diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/refs/createwithlog.c | 51 | ||||
| -rw-r--r-- | tests/refs/reflog/reflog.c | 73 | ||||
| -rw-r--r-- | tests/refs/settargetwithlog.c | 55 |
3 files changed, 146 insertions, 33 deletions
diff --git a/tests/refs/createwithlog.c b/tests/refs/createwithlog.c new file mode 100644 index 000000000..0fe81df91 --- /dev/null +++ b/tests/refs/createwithlog.c @@ -0,0 +1,51 @@ +#include "clar_libgit2.h" + +#include "repository.h" +#include "git2/reflog.h" +#include "reflog.h" +#include "ref_helpers.h" + +static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"; + +static git_repository *g_repo; + +void test_refs_createwithlog__initialize(void) +{ + g_repo = cl_git_sandbox_init("testrepo.git"); +} + +void test_refs_createwithlog__cleanup(void) +{ + cl_git_sandbox_cleanup(); +} + +void test_refs_createwithlog__creating_a_direct_reference_adds_a_reflog_entry(void) +{ + git_reference *reference; + git_oid id; + git_signature *signature; + git_reflog *reflog; + const git_reflog_entry *entry; + + const char *name = "refs/heads/new-head"; + const char *message = "You've been logged, mate!"; + + git_oid_fromstr(&id, current_master_tip); + + cl_git_pass(git_signature_now(&signature, "foo", "foo@bar")); + + cl_git_pass( + git_reference_create_with_log(&reference, g_repo, name, &id, 0, signature, message)); + + cl_git_pass(git_reflog_read(&reflog, g_repo, name)); + cl_assert_equal_sz(1, git_reflog_entrycount(reflog)); + + entry = git_reflog_entry_byindex(reflog, 0); + cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0); + cl_assert(git_oid_cmp(&id, &entry->oid_cur) == 0); + cl_assert_equal_s(message, entry->msg); + + git_reflog_free(reflog); + git_reference_free(reference); + git_signature_free(signature); +} diff --git a/tests/refs/reflog/reflog.c b/tests/refs/reflog/reflog.c index bcd224270..a1c5adaf4 100644 --- a/tests/refs/reflog/reflog.c +++ b/tests/refs/reflog/reflog.c @@ -49,17 +49,20 @@ static void assert_appends(const git_signature *committer, const git_oid *oid) /* Read and parse the reflog for this branch */ cl_git_pass(git_reflog_read(&reflog, repo2, new_ref)); - cl_assert_equal_i(2, (int)git_reflog_entrycount(reflog)); + cl_assert_equal_i(3, (int)git_reflog_entrycount(reflog)); + + /* The first one was the creation of the branch */ + entry = git_reflog_entry_byindex(reflog, 2); + cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0); entry = git_reflog_entry_byindex(reflog, 1); assert_signature(committer, entry->committer); - cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0); + cl_assert(git_oid_cmp(oid, &entry->oid_old) == 0); cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0); cl_assert(entry->msg == NULL); entry = git_reflog_entry_byindex(reflog, 0); assert_signature(committer, entry->committer); - cl_assert(git_oid_cmp(oid, &entry->oid_old) == 0); cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0); cl_assert_equal_s(commit_msg, entry->msg); @@ -97,29 +100,6 @@ void test_refs_reflog_reflog__append_then_read(void) git_signature_free(committer); } -void test_refs_reflog_reflog__append_to_then_read(void) -{ - /* write a reflog for a given reference and ensure it can be read back */ - git_reference *ref; - git_oid oid; - git_signature *committer; - - /* Create a new branch pointing at the HEAD */ - git_oid_fromstr(&oid, current_master_tip); - cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &oid, 0)); - git_reference_free(ref); - - cl_git_pass(git_signature_now(&committer, "foo", "foo@bar")); - - cl_git_fail(git_reflog_append_to(g_repo, new_ref, &oid, committer, "no inner\nnewline")); - cl_git_pass(git_reflog_append_to(g_repo, new_ref, &oid, committer, NULL)); - cl_git_pass(git_reflog_append_to(g_repo, new_ref, &oid, committer, commit_msg "\n")); - - assert_appends(committer, &oid); - - git_signature_free(committer); -} - void test_refs_reflog_reflog__renaming_the_reference_moves_the_reflog(void) { git_reference *master, *new_master; @@ -147,13 +127,7 @@ void test_refs_reflog_reflog__renaming_the_reference_moves_the_reflog(void) static void assert_has_reflog(bool expected_result, const char *name) { - git_reference *ref; - - cl_git_pass(git_reference_lookup(&ref, g_repo, name)); - - cl_assert_equal_i(expected_result, git_reference_has_log(ref)); - - git_reference_free(ref); + cl_assert_equal_i(expected_result, git_reference_has_log(g_repo, name)); } void test_refs_reflog_reflog__reference_has_reflog(void) @@ -207,3 +181,36 @@ void test_refs_reflog_reflog__renaming_with_an_invalid_name_returns_EINVALIDSPEC cl_assert_equal_i(GIT_EINVALIDSPEC, git_reflog_rename(g_repo, "refs/heads/master", "refs/heads/Inv@{id")); } + +void test_refs_reflog_reflog__write_only_std_locations(void) +{ + git_reference *ref; + git_oid id; + + git_oid_fromstr(&id, current_master_tip); + + cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/foo", &id, 1)); + git_reference_free(ref); + cl_git_pass(git_reference_create(&ref, g_repo, "refs/tags/foo", &id, 1)); + git_reference_free(ref); + cl_git_pass(git_reference_create(&ref, g_repo, "refs/notes/foo", &id, 1)); + git_reference_free(ref); + + assert_has_reflog(true, "refs/heads/foo"); + assert_has_reflog(false, "refs/tags/foo"); + assert_has_reflog(true, "refs/notes/foo"); + +} + +void test_refs_reflog_reflog__write_when_explicitly_active(void) +{ + git_reference *ref; + git_oid id; + + git_oid_fromstr(&id, current_master_tip); + git_reference_ensure_log(g_repo, "refs/tags/foo"); + + cl_git_pass(git_reference_create(&ref, g_repo, "refs/tags/foo", &id, 1)); + git_reference_free(ref); + assert_has_reflog(true, "refs/tags/foo"); +} diff --git a/tests/refs/settargetwithlog.c b/tests/refs/settargetwithlog.c new file mode 100644 index 000000000..cfa1c99d5 --- /dev/null +++ b/tests/refs/settargetwithlog.c @@ -0,0 +1,55 @@ +#include "clar_libgit2.h" + +#include "repository.h" +#include "git2/reflog.h" +#include "reflog.h" +#include "ref_helpers.h" + +static const char *br2_tip = "a4a7dce85cf63874e984719f4fdd239f5145052f"; +static const char *master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"; +static const char *br2_name = "refs/heads/br2"; + +static git_repository *g_repo; + +void test_refs_settargetwithlog__initialize(void) +{ + g_repo = cl_git_sandbox_init("testrepo.git"); +} + +void test_refs_settargetwithlog__cleanup(void) +{ + cl_git_sandbox_cleanup(); +} + +void test_refs_settargetwithlog__updating_a_direct_reference_adds_a_reflog_entry(void) +{ + git_reference *reference, *reference_out; + git_oid current_id, target_id; + git_signature *signature; + git_reflog *reflog; + const git_reflog_entry *entry; + + const char *message = "You've been logged, mate!"; + + git_oid_fromstr(¤t_id, br2_tip); + git_oid_fromstr(&target_id, master_tip); + + cl_git_pass(git_reference_lookup(&reference, g_repo, br2_name)); + + cl_git_pass(git_signature_now(&signature, "foo", "foo@bar")); + + cl_git_pass(git_reference_set_target_with_log( + &reference_out, reference, &target_id, signature, message)); + + cl_git_pass(git_reflog_read(&reflog, g_repo, br2_name)); + + entry = git_reflog_entry_byindex(reflog, 0); + cl_assert(git_oid_cmp(¤t_id, &entry->oid_old) == 0); + cl_assert(git_oid_cmp(&target_id, &entry->oid_cur) == 0); + cl_assert_equal_s(message, entry->msg); + + git_reflog_free(reflog); + git_reference_free(reference_out); + git_reference_free(reference); + git_signature_free(signature); +} |
