Skip to content

Commit

Permalink
refs: on symref reflog expire, lock symref not referrent
Browse files Browse the repository at this point in the history
When locking a symbolic ref to expire a reflog, lock the symbolic
ref (using REF_NODEREF) instead of its referent.

Add a test for this.

Signed-off-by: David Turner <[email protected]>
Reviewed-by: Michael Haggerty <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
dturner-tw authored and gitster committed Apr 10, 2016
1 parent 2d0663b commit 41d796e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion refs/files-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -3314,7 +3314,8 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
* reference itself, plus we might need to update the
* reference if --updateref was specified:
*/
lock = lock_ref_sha1_basic(refname, sha1, NULL, NULL, 0, &type, &err);
lock = lock_ref_sha1_basic(refname, sha1, NULL, NULL, REF_NODEREF,
&type, &err);
if (!lock) {
error("cannot lock ref '%s': %s", refname, err.buf);
strbuf_release(&err);
Expand Down
10 changes: 10 additions & 0 deletions t/t1410-reflog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,14 @@ test_expect_failure 'reflog with non-commit entries displays all entries' '
test_line_count = 3 actual
'

test_expect_success 'reflog expire operates on symref not referrent' '
git branch -l the_symref &&
git branch -l referrent &&
git update-ref referrent HEAD &&
git symbolic-ref refs/heads/the_symref refs/heads/referrent &&
test_when_finished "rm -f .git/refs/heads/referrent.lock" &&
touch .git/refs/heads/referrent.lock &&
git reflog expire --expire=all the_symref
'

test_done

0 comments on commit 41d796e

Please sign in to comment.