Skip to content

Commit c13c783

Browse files
committed
Merge branch 'km/delete-ref-reflog-message'
"git update-ref -d" and other operations to delete references did not leave any entry in HEAD's reflog when the reference being deleted was the current branch. This is not a problem in practice because you do not want to delete the branch you are currently on, but caused renaming of the current branch to something else not to be logged in a useful way. * km/delete-ref-reflog-message: branch: record creation of renamed branch in HEAD's log rename_ref: replace empty message in HEAD's log update-ref: pass reflog message to delete_ref() delete_ref: accept a reflog message argument
2 parents 3f7ebc6 + 39ee4c6 commit c13c783

18 files changed

+58
-30
lines changed

branch.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ void die_if_checked_out(const char *branch, int ignore_current_worktree)
345345
branch, wt->path);
346346
}
347347

348-
int replace_each_worktree_head_symref(const char *oldref, const char *newref)
348+
int replace_each_worktree_head_symref(const char *oldref, const char *newref,
349+
const char *logmsg)
349350
{
350351
int ret = 0;
351352
struct worktree **worktrees = get_worktrees(0);
@@ -358,7 +359,7 @@ int replace_each_worktree_head_symref(const char *oldref, const char *newref)
358359
continue;
359360

360361
if (set_worktree_head_symref(get_worktree_git_dir(worktrees[i]),
361-
newref)) {
362+
newref, logmsg)) {
362363
ret = -1;
363364
error(_("HEAD of working tree %s is not updated"),
364365
worktrees[i]->path);

branch.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ extern void die_if_checked_out(const char *branch, int ignore_current_worktree);
7171
* This will be used when renaming a branch. Returns 0 if successful, non-zero
7272
* otherwise.
7373
*/
74-
extern int replace_each_worktree_head_symref(const char *oldref, const char *newref);
74+
extern int replace_each_worktree_head_symref(const char *oldref, const char *newref,
75+
const char *logmsg);
7576

7677
#endif

builtin/am.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
10491049
} else {
10501050
write_state_text(state, "abort-safety", "");
10511051
if (!state->rebasing)
1052-
delete_ref("ORIG_HEAD", NULL, 0);
1052+
delete_ref(NULL, "ORIG_HEAD", NULL, 0);
10531053
}
10541054

10551055
/*
@@ -2172,7 +2172,7 @@ static void am_abort(struct am_state *state)
21722172
has_curr_head ? &curr_head : NULL, 0,
21732173
UPDATE_REFS_DIE_ON_ERR);
21742174
else if (curr_branch)
2175-
delete_ref(curr_branch, NULL, REF_NODEREF);
2175+
delete_ref(NULL, curr_branch, NULL, REF_NODEREF);
21762176

21772177
free(curr_branch);
21782178
am_destroy(state);

builtin/branch.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
252252
goto next;
253253
}
254254

255-
if (delete_ref(name, is_null_sha1(sha1) ? NULL : sha1,
255+
if (delete_ref(NULL, name, is_null_sha1(sha1) ? NULL : sha1,
256256
REF_NODEREF)) {
257257
error(remote_branch
258258
? _("Error deleting remote-tracking branch '%s'")
@@ -471,14 +471,15 @@ static void rename_branch(const char *oldname, const char *newname, int force)
471471

472472
if (rename_ref(oldref.buf, newref.buf, logmsg.buf))
473473
die(_("Branch rename failed"));
474-
strbuf_release(&logmsg);
475474

476475
if (recovery)
477476
warning(_("Renamed a misnamed branch '%s' away"), oldref.buf + 11);
478477

479-
if (replace_each_worktree_head_symref(oldref.buf, newref.buf))
478+
if (replace_each_worktree_head_symref(oldref.buf, newref.buf, logmsg.buf))
480479
die(_("Branch renamed to %s, but HEAD is not updated!"), newname);
481480

481+
strbuf_release(&logmsg);
482+
482483
strbuf_addf(&oldsection, "branch.%s", oldref.buf + 11);
483484
strbuf_release(&oldref);
484485
strbuf_addf(&newsection, "branch.%s", newref.buf + 11);

builtin/notes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,9 @@ static int merge_abort(struct notes_merge_options *o)
681681
* notes_merge_abort() to remove .git/NOTES_MERGE_WORKTREE.
682682
*/
683683

684-
if (delete_ref("NOTES_MERGE_PARTIAL", NULL, 0))
684+
if (delete_ref(NULL, "NOTES_MERGE_PARTIAL", NULL, 0))
685685
ret += error(_("failed to delete ref NOTES_MERGE_PARTIAL"));
686-
if (delete_ref("NOTES_MERGE_REF", NULL, REF_NODEREF))
686+
if (delete_ref(NULL, "NOTES_MERGE_REF", NULL, REF_NODEREF))
687687
ret += error(_("failed to delete ref NOTES_MERGE_REF"));
688688
if (notes_merge_abort(o))
689689
ret += error(_("failed to remove 'git notes merge' worktree"));

builtin/remote.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static int mv(int argc, const char **argv)
691691
read_ref_full(item->string, RESOLVE_REF_READING, oid.hash, &flag);
692692
if (!(flag & REF_ISSYMREF))
693693
continue;
694-
if (delete_ref(item->string, NULL, REF_NODEREF))
694+
if (delete_ref(NULL, item->string, NULL, REF_NODEREF))
695695
die(_("deleting '%s' failed"), item->string);
696696
}
697697
for (i = 0; i < remote_branches.nr; i++) {
@@ -1248,7 +1248,7 @@ static int set_head(int argc, const char **argv)
12481248
head_name = xstrdup(states.heads.items[0].string);
12491249
free_remote_ref_states(&states);
12501250
} else if (opt_d && !opt_a && argc == 1) {
1251-
if (delete_ref(buf.buf, NULL, REF_NODEREF))
1251+
if (delete_ref(NULL, buf.buf, NULL, REF_NODEREF))
12521252
result |= error(_("Could not delete %s"), buf.buf);
12531253
} else
12541254
usage_with_options(builtin_remote_sethead_usage, options);

builtin/replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
121121
static int delete_replace_ref(const char *name, const char *ref,
122122
const unsigned char *sha1)
123123
{
124-
if (delete_ref(ref, sha1, 0))
124+
if (delete_ref(NULL, ref, sha1, 0))
125125
return 1;
126126
printf("Deleted replace ref '%s'\n", name);
127127
return 0;

builtin/reset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static int reset_refs(const char *rev, const struct object_id *oid)
256256
update_ref_oid(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
257257
UPDATE_REFS_MSG_ON_ERR);
258258
} else if (old_orig)
259-
delete_ref("ORIG_HEAD", old_orig->hash, 0);
259+
delete_ref(NULL, "ORIG_HEAD", old_orig->hash, 0);
260260
set_reflog_message(&msg, "updating HEAD", rev);
261261
update_ref_status = update_ref_oid(msg.buf, "HEAD", oid, orig, 0,
262262
UPDATE_REFS_MSG_ON_ERR);

builtin/symbolic-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
5858
die("Cannot delete %s, not a symbolic ref", argv[0]);
5959
if (!strcmp(argv[0], "HEAD"))
6060
die("deleting '%s' is not allowed", argv[0]);
61-
return delete_ref(argv[0], NULL, REF_NODEREF);
61+
return delete_ref(NULL, argv[0], NULL, REF_NODEREF);
6262
}
6363

6464
switch (argc) {

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
9797
static int delete_tag(const char *name, const char *ref,
9898
const unsigned char *sha1, const void *cb_data)
9999
{
100-
if (delete_ref(ref, sha1, 0))
100+
if (delete_ref(NULL, ref, sha1, 0))
101101
return 1;
102102
printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(sha1, DEFAULT_ABBREV));
103103
return 0;

0 commit comments

Comments
 (0)