Skip to content

Commit b3370dd

Browse files
committed
Merge branch 'pw/show-ref-pseudorefs'
"git show-ref --verify" did not show things like "CHERRY_PICK_HEAD", which has been corrected. * pw/show-ref-pseudorefs: t1400: use show-ref to check pseudorefs show-ref --verify: accept pseudorefs
2 parents 70550a2 + 1af410d commit b3370dd

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

builtin/show-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static int cmd_show_ref__verify(const struct show_one_options *show_one_opts,
172172
while (*refs) {
173173
struct object_id oid;
174174

175-
if ((starts_with(*refs, "refs/") || !strcmp(*refs, "HEAD")) &&
175+
if ((starts_with(*refs, "refs/") || refname_is_safe(*refs)) &&
176176
!read_ref(*refs, &oid)) {
177177
show_one(show_one_opts, *refs, &oid);
178178
}

t/t1400-update-ref.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -524,51 +524,51 @@ test_expect_success 'given old value for missing pseudoref, do not create' '
524524

525525
test_expect_success 'create pseudoref' '
526526
git update-ref PSEUDOREF $A &&
527-
test $A = $(git rev-parse PSEUDOREF)
527+
test $A = $(git show-ref -s --verify PSEUDOREF)
528528
'
529529

530530
test_expect_success 'overwrite pseudoref with no old value given' '
531531
git update-ref PSEUDOREF $B &&
532-
test $B = $(git rev-parse PSEUDOREF)
532+
test $B = $(git show-ref -s --verify PSEUDOREF)
533533
'
534534

535535
test_expect_success 'overwrite pseudoref with correct old value' '
536536
git update-ref PSEUDOREF $C $B &&
537-
test $C = $(git rev-parse PSEUDOREF)
537+
test $C = $(git show-ref -s --verify PSEUDOREF)
538538
'
539539

540540
test_expect_success 'do not overwrite pseudoref with wrong old value' '
541541
test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
542-
test $C = $(git rev-parse PSEUDOREF) &&
542+
test $C = $(git show-ref -s --verify PSEUDOREF) &&
543543
test_grep "cannot lock ref.*expected" err
544544
'
545545

546546
test_expect_success 'delete pseudoref' '
547547
git update-ref -d PSEUDOREF &&
548-
test_must_fail git rev-parse PSEUDOREF
548+
test_must_fail git show-ref -s --verify PSEUDOREF
549549
'
550550

551551
test_expect_success 'do not delete pseudoref with wrong old value' '
552552
git update-ref PSEUDOREF $A &&
553553
test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
554-
test $A = $(git rev-parse PSEUDOREF) &&
554+
test $A = $(git show-ref -s --verify PSEUDOREF) &&
555555
test_grep "cannot lock ref.*expected" err
556556
'
557557

558558
test_expect_success 'delete pseudoref with correct old value' '
559559
git update-ref -d PSEUDOREF $A &&
560-
test_must_fail git rev-parse PSEUDOREF
560+
test_must_fail git show-ref -s --verify PSEUDOREF
561561
'
562562

563563
test_expect_success 'create pseudoref with old OID zero' '
564564
git update-ref PSEUDOREF $A $Z &&
565-
test $A = $(git rev-parse PSEUDOREF)
565+
test $A = $(git show-ref -s --verify PSEUDOREF)
566566
'
567567

568568
test_expect_success 'do not overwrite pseudoref with old OID zero' '
569569
test_when_finished git update-ref -d PSEUDOREF &&
570570
test_must_fail git update-ref PSEUDOREF $B $Z 2>err &&
571-
test $A = $(git rev-parse PSEUDOREF) &&
571+
test $A = $(git show-ref -s --verify PSEUDOREF) &&
572572
test_grep "already exists" err
573573
'
574574

t/t1403-show-ref.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ test_expect_success 'show-ref --verify HEAD' '
174174
test_must_be_empty actual
175175
'
176176

177+
test_expect_success 'show-ref --verify pseudorefs' '
178+
git update-ref CHERRY_PICK_HEAD HEAD $ZERO_OID &&
179+
test_when_finished "git update-ref -d CHERRY_PICK_HEAD" &&
180+
git show-ref -s --verify HEAD >actual &&
181+
git show-ref -s --verify CHERRY_PICK_HEAD >expect &&
182+
test_cmp actual expect
183+
'
184+
177185
test_expect_success 'show-ref --verify with dangling ref' '
178186
sha1_file() {
179187
echo "$*" | sed "s#..#.git/objects/&/#"

0 commit comments

Comments
 (0)