diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-03-19 01:16:58 +0400 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-03-19 18:54:33 +0400 |
commit | 1afe1400433f010734ae4c43bf35dcc94edcc9de (patch) | |
tree | d2a7143551040175da2a5f13948ccc68f260d7ff /tests | |
parent | bac95e6e1e99b1e364c5ebd39887a8e24bc1ad9d (diff) |
refdb: don't update when there's no need
If the caller wants to update a ref to point to the same target as it
currently has, we should return early and avoid writing to the reflog.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/refs/reflog/reflog.c | 24 | ||||
-rw-r--r-- | tests/repo/head.c | 27 |
2 files changed, 51 insertions, 0 deletions
diff --git a/tests/refs/reflog/reflog.c b/tests/refs/reflog/reflog.c index 149e98273..a50d40aac 100644 --- a/tests/refs/reflog/reflog.c +++ b/tests/refs/reflog/reflog.c @@ -237,3 +237,27 @@ void test_refs_reflog_reflog__append_to_HEAD_when_changing_current_branch(void) cl_assert_equal_i(nlogs_after, nlogs + 1); } + +void test_refs_reflog_reflog__do_not_append_when_no_update(void) +{ + size_t nlogs, nlogs_after; + git_reference *ref, *ref2; + git_reflog *log; + + cl_git_pass(git_reflog_read(&log, g_repo, "HEAD")); + nlogs = git_reflog_entrycount(log); + git_reflog_free(log); + + cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/master")); + cl_git_pass(git_reference_create(&ref2, g_repo, "refs/heads/master", + git_reference_target(ref), 1, NULL, NULL)); + + git_reference_free(ref); + git_reference_free(ref2); + + cl_git_pass(git_reflog_read(&log, g_repo, "HEAD")); + nlogs_after = git_reflog_entrycount(log); + git_reflog_free(log); + + cl_assert_equal_i(nlogs_after, nlogs); +} diff --git a/tests/repo/head.c b/tests/repo/head.c index a246e6086..130ed8588 100644 --- a/tests/repo/head.c +++ b/tests/repo/head.c @@ -341,3 +341,30 @@ void test_repo_head__orphan_branch_does_not_count(void) git_signature_free(sig); } + +void test_repo_head__set_to_current_target(void) +{ + git_signature *sig; + const char *msg; + git_reflog *log; + size_t nentries, nentries_after; + + cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE)); + nentries = git_reflog_entrycount(log); + git_reflog_free(log); + + cl_git_pass(git_signature_now(&sig, "me", "foo@example.com")); + + msg = "message 1"; + cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, msg)); + cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, msg)); + + cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE)); + nentries_after = git_reflog_entrycount(log); + git_reflog_free(log); + + cl_assert_equal_i(nentries + 1, nentries_after); + + git_signature_free(sig); + +} |