Skip to content

Commit a1ee40f

Browse files
committed
Merge branch 'jc/checkout-reflog-fix' into maint
* jc/checkout-reflog-fix: checkout: do not write bogus reflog entry out
2 parents 7aa5089 + 25d3354 commit a1ee40f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

builtin/checkout.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,10 +715,12 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
715715
unsigned char rev[20];
716716
int flag;
717717
memset(&old, 0, sizeof(old));
718-
old.path = resolve_ref("HEAD", rev, 0, &flag);
718+
old.path = xstrdup(resolve_ref("HEAD", rev, 0, &flag));
719719
old.commit = lookup_commit_reference_gently(rev, 1);
720-
if (!(flag & REF_ISSYMREF))
720+
if (!(flag & REF_ISSYMREF)) {
721+
free((char *)old.path);
721722
old.path = NULL;
723+
}
722724

723725
if (old.path && !prefixcmp(old.path, "refs/heads/"))
724726
old.name = old.path + strlen("refs/heads/");
@@ -741,6 +743,7 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
741743
update_refs_for_switch(opts, &old, new);
742744

743745
ret = post_checkout_hook(old.commit, new->commit, 1);
746+
free((char *)old.path);
744747
return ret || opts->writeout_error;
745748
}
746749

0 commit comments

Comments
 (0)