Deleting a branch deletes its reflog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
diff --git a/src/branch.c b/src/branch.c
index a989cb6..531101f 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 43f2aff..0c0fdb0 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 a642f87..7d1d400 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);
+}
+