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>
David Turner committed
Apr 7, 2016 at 15:03 UTC
41d796ed5cd78d159f8a8bfa3b54bdbe5d9383a3
2 files changed
+12
-1
refs/files-backend.c
+2
-1
@@ -3314,7 +3314,8 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
3314
* reference itself, plus we might need to update the
3315
* reference if --updateref was specified:
3316
*/
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);
3319
if (!lock) {
3320
error("cannot lock ref '%s': %s", refname, err.buf);
3321
strbuf_release(&err);
t/t1410-reflog.sh
+10
@@ -338,4 +338,14 @@ test_expect_failure 'reflog with non-commit entries displays all entries' '
338
test_line_count = 3 actual
339
'
340
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
+
351
test_done