Skip to content

Commit 41d796e

Browse files
dturner-twgitster
authored andcommitted
refs: on symref reflog expire, lock symref not referrent
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 <dturner@twopensource.com> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2d0663b commit 41d796e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

refs/files-backend.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3314,7 +3314,8 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
33143314
* reference itself, plus we might need to update the
33153315
* reference if --updateref was specified:
33163316
*/
3317-
lock = lock_ref_sha1_basic(refname, sha1, NULL, NULL, 0, &type, &err);
3317+
lock = lock_ref_sha1_basic(refname, sha1, NULL, NULL, REF_NODEREF,
3318+
&type, &err);
33183319
if (!lock) {
33193320
error("cannot lock ref '%s': %s", refname, err.buf);
33203321
strbuf_release(&err);

t/t1410-reflog.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,14 @@ test_expect_failure 'reflog with non-commit entries displays all entries' '
338338
test_line_count = 3 actual
339339
'
340340

341+
test_expect_success 'reflog expire operates on symref not referrent' '
342+
git branch -l the_symref &&
343+
git branch -l referrent &&
344+
git update-ref referrent HEAD &&
345+
git symbolic-ref refs/heads/the_symref refs/heads/referrent &&
346+
test_when_finished "rm -f .git/refs/heads/referrent.lock" &&
347+
touch .git/refs/heads/referrent.lock &&
348+
git reflog expire --expire=all the_symref
349+
'
350+
341351
test_done

0 commit comments

Comments
 (0)