summaryrefslogtreecommitdiff
path: root/tests/reset
diff options
context:
space:
mode:
Diffstat (limited to 'tests/reset')
-rw-r--r--tests/reset/hard.c27
-rw-r--r--tests/reset/mixed.c26
-rw-r--r--tests/reset/reset_helpers.c17
-rw-r--r--tests/reset/reset_helpers.h2
-rw-r--r--tests/reset/soft.c26
5 files changed, 98 insertions, 0 deletions
diff --git a/tests/reset/hard.c b/tests/reset/hard.c
index 97243605d..d4c7db45f 100644
--- a/tests/reset/hard.c
+++ b/tests/reset/hard.c
@@ -197,3 +197,30 @@ void test_reset_hard__cleans_up_merge(void)
git_buf_free(&merge_mode_path);
git_buf_free(&orig_head_path);
}
+
+void test_reset_hard__reflog_is_correct(void)
+{
+ const char *exp_msg = "commit: Add a file which name should appear before the "
+ "\"subdir/\" folder while being dealt with by the treewalker";
+
+ reflog_check(repo, "HEAD", 3, "emeric.fermas@gmail.com", exp_msg);
+ reflog_check(repo, "refs/heads/master", 3, "emeric.fermas@gmail.com", exp_msg);
+
+ /* Branch not moving, no reflog entry */
+ cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL, NULL));
+ reflog_check(repo, "HEAD", 3, "emeric.fermas@gmail.com", exp_msg);
+ reflog_check(repo, "refs/heads/master", 3, "emeric.fermas@gmail.com", exp_msg);
+
+ /* Moved branch, expect default message */
+ cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL, NULL));
+ reflog_check(repo, "HEAD", 3, "emeric.fermas@gmail.com", exp_msg);
+ reflog_check(repo, "refs/heads/master", 4, NULL, "reset: moving");
+
+ /* Moved branch, expect custom message */
+ cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL, "message1"));
+ reflog_check(repo, "HEAD", 3, "emeric.fermas@gmail.com", exp_msg);
+ reflog_check(repo, "refs/heads/master", 5, NULL, "message1");
+}
diff --git a/tests/reset/mixed.c b/tests/reset/mixed.c
index 7a2605a82..25272a75c 100644
--- a/tests/reset/mixed.c
+++ b/tests/reset/mixed.c
@@ -47,3 +47,29 @@ void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
cl_git_pass(git_status_file(&status, repo, "macro_bad"));
cl_assert(status == GIT_STATUS_WT_NEW);
}
+
+void test_reset_mixed__reflog_is_correct(void)
+{
+ const char *exp_msg = "commit: Updating test data so we can test inter-hunk-context";
+
+ reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
+ reflog_check(repo, "refs/heads/master", 9, "yoram.harmelin@gmail.com", exp_msg);
+
+ /* Branch not moving, no reflog entry */
+ cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL, NULL));
+ reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
+ reflog_check(repo, "refs/heads/master", 9, "yoram.harmelin@gmail.com", exp_msg);
+
+ /* Moved branch, expect default message */
+ cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL, NULL));
+ reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
+ reflog_check(repo, "refs/heads/master", 10, NULL, "reset: moving");
+
+ /* Moved branch, expect custom message */
+ cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL, "message1"));
+ reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
+ reflog_check(repo, "refs/heads/master", 11, NULL, "message1");
+}
diff --git a/tests/reset/reset_helpers.c b/tests/reset/reset_helpers.c
index a792c03b9..7a335a600 100644
--- a/tests/reset/reset_helpers.c
+++ b/tests/reset/reset_helpers.c
@@ -1,3 +1,20 @@
#include "clar_libgit2.h"
#include "reset_helpers.h"
+void reflog_check(git_repository *repo, const char *refname,
+ size_t exp_count, const char *exp_email, const char *exp_msg)
+{
+ git_reflog *log;
+ const git_reflog_entry *entry;
+
+ cl_git_pass(git_reflog_read(&log, repo, refname));
+ cl_assert_equal_i(exp_count, git_reflog_entrycount(log));
+ entry = git_reflog_entry_byindex(log, 0);
+
+ if (exp_email)
+ cl_assert_equal_s(exp_email, git_reflog_entry_committer(entry)->email);
+ if (exp_msg)
+ cl_assert_equal_s(exp_msg, git_reflog_entry_message(entry));
+
+ git_reflog_free(log);
+}
diff --git a/tests/reset/reset_helpers.h b/tests/reset/reset_helpers.h
index 82249fffa..e7e048514 100644
--- a/tests/reset/reset_helpers.h
+++ b/tests/reset/reset_helpers.h
@@ -3,3 +3,5 @@
#define KNOWN_COMMIT_IN_BARE_REPO "e90810b8df3e80c413d903f631643c716887138d"
#define KNOWN_COMMIT_IN_ATTR_REPO "217878ab49e1314388ea2e32dc6fdb58a1b969e0"
+void reflog_check(git_repository *repo, const char *refname,
+ size_t exp_count, const char *exp_email, const char *exp_msg);
diff --git a/tests/reset/soft.c b/tests/reset/soft.c
index 7c02b8073..6469fce6d 100644
--- a/tests/reset/soft.c
+++ b/tests/reset/soft.c
@@ -154,3 +154,29 @@ void test_reset_soft__fails_when_index_contains_conflicts_independently_of_MERGE
cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL));
}
+
+void test_reset_soft_reflog_is_correct(void)
+{
+ const char *exp_msg = "commit: Updating test data so we can test inter-hunk-context";
+
+ reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
+ reflog_check(repo, "refs/heads/master", 9, "yoram.harmelin@gmail.com", exp_msg);
+
+ /* Branch not moving, no reflog entry */
+ cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL));
+ reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
+ reflog_check(repo, "refs/heads/master", 9, "yoram.harmelin@gmail.com", exp_msg);
+
+ /* Moved branch, expect default message */
+ cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL, NULL));
+ reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
+ reflog_check(repo, "refs/heads/master", 10, NULL, "reset: moving");
+
+ /* Moved branch, expect custom message */
+ cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL, "message1"));
+ reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
+ reflog_check(repo, "refs/heads/master", 11, NULL, "message1");
+}