Commit 86746b4b by Ben Straub

Add reset tests for reflog

parent eec2761f
......@@ -1032,8 +1032,10 @@ static int reference__update_terminal(
nesting+1, signature, log_message);
git_reference_free(ref);
} else {
/* If we're not moving the target, don't recreate the ref */
if (0 != git_oid_cmp(git_reference_target(ref), oid))
error = git_reference_create(NULL, repo, ref_name, oid, 1, signature, log_message);
git_reference_free(ref);
error = git_reference_create(NULL, repo, ref_name, oid, 1, signature, log_message);
}
return error;
......
......@@ -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");
}
......@@ -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");
}
#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);
}
......@@ -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);
......@@ -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");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment