diff options
author | Ben Straub <bs@github.com> | 2014-01-28 10:31:54 -0800 |
---|---|---|
committer | Ben Straub <bs@github.com> | 2014-01-30 15:52:13 -0800 |
commit | 48110f67e4a21caac1b8157d8239d16cd9781e51 (patch) | |
tree | c4f5622e70fe4fc88a6400468e56eee7afa0d033 | |
parent | 1cc974ab625c2fa0794130eb97ca88c449fc1a06 (diff) | |
download | libgit2-48110f67e4a21caac1b8157d8239d16cd9781e51.tar.gz |
Deleting a branch deletes its reflog
-rw-r--r-- | src/branch.c | 3 | ||||
-rw-r--r-- | tests/refs/branches/create.c | 20 | ||||
-rw-r--r-- | tests/refs/branches/delete.c | 26 |
3 files changed, 29 insertions, 20 deletions
diff --git a/src/branch.c b/src/branch.c index a989cb61d..531101f8a 100644 --- a/src/branch.c +++ b/src/branch.c @@ -111,6 +111,9 @@ int git_branch_delete(git_reference *branch) if (git_reference_delete(branch) < 0) goto on_error; + if (git_reflog_delete(git_reference_owner(branch), git_reference_name(branch)) < 0) + goto on_error; + error = 0; on_error: diff --git a/tests/refs/branches/create.c b/tests/refs/branches/create.c index 43f2affb9..0c0fdb013 100644 --- a/tests/refs/branches/create.c +++ b/tests/refs/branches/create.c @@ -87,23 +87,3 @@ void test_refs_branches_create__creation_creates_new_reflog(void) entry = git_reflog_entry_byindex(log, 0); cl_assert_equal_s("create!", git_reflog_entry_message(entry)); } - -void test_refs_branches_create__recreation_updates_existing_reflog(void) -{ - git_reflog *log; - const git_reflog_entry *entry1, *entry2; - - retrieve_known_commit(&target, repo); - - cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false, NULL, "Create 1")); - cl_git_pass(git_branch_delete(branch)); - cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false, NULL, "Create 2")); - cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME)); - - cl_assert_equal_i(2, git_reflog_entrycount(log)); - entry1 = git_reflog_entry_byindex(log, 1); - entry2 = git_reflog_entry_byindex(log, 0); - cl_assert_equal_s("Create 1", git_reflog_entry_message(entry1)); - cl_assert_equal_s("Create 2", git_reflog_entry_message(entry2)); -} - diff --git a/tests/refs/branches/delete.c b/tests/refs/branches/delete.c index a642f8704..7d1d400c8 100644 --- a/tests/refs/branches/delete.c +++ b/tests/refs/branches/delete.c @@ -115,3 +115,29 @@ void test_refs_branches_delete__deleting_a_branch_removes_related_configuration_ assert_config_entry_existence(repo, "branch.track-local.remote", false); assert_config_entry_existence(repo, "branch.track-local.merge", false); } + +void test_refs_branches_delete__removes_reflog(void) +{ + git_reference *branch; + git_reflog *log; + git_oid oidzero = {{0}}; + git_signature *sig; + + /* Ensure the reflog has at least one entry */ + cl_git_pass(git_signature_now(&sig, "Me", "user@example.com")); + cl_git_pass(git_reflog_read(&log, repo, "refs/heads/track-local")); + cl_git_pass(git_reflog_append(log, &oidzero, sig, "message")); + cl_assert(git_reflog_entrycount(log) > 0); + git_signature_free(sig); + git_reflog_free(log); + + cl_git_pass(git_branch_lookup(&branch, repo, "track-local", GIT_BRANCH_LOCAL)); + cl_git_pass(git_branch_delete(branch)); + git_reference_free(branch); + + /* Reading a nonexistant reflog creates it, but it should be empty */ + cl_git_pass(git_reflog_read(&log, repo, "refs/heads/track-local")); + cl_assert_equal_i(0, git_reflog_entrycount(log)); + git_reflog_free(log); +} + |