Skip to content

Commit 65eb8fc

Browse files
Martin Ågrengitster
authored andcommitted
t1400: add tests around adding/deleting pseudorefs
I have not been able to find any tests around adding pseudorefs using `git update-ref`. Add some as outlined in this table (original design by Michael Haggerty; modified and extended by me): Pre-update value | ref-update old OID | Expected result -------------------|----------------------|---------------- missing | value | reject missing | none given | accept set | none given | accept set | correct value | accept set | wrong value | reject missing | zero | accept * set | zero | reject * The tests marked with a * currently fail, despite git-update-ref(1) claiming that it is possible to "specify 40 '0' or an empty string as <oldvalue> to make sure that the ref you are creating does not exist." These failing tests will be fixed in the next commit. It is only natural to test deletion as well. Test deletion without an old OID, with a correct one and with an incorrect one. Suggested-by: Michael Haggerty <[email protected]> Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0bdd65 commit 65eb8fc

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

t/t1400-update-ref.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,66 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER
457457
test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")
458458
'
459459

460+
# Test adding and deleting pseudorefs
461+
462+
test_expect_success 'given old value for missing pseudoref, do not create' '
463+
test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
464+
test_path_is_missing .git/PSEUDOREF &&
465+
grep "could not read ref" err
466+
'
467+
468+
test_expect_success 'create pseudoref' '
469+
git update-ref PSEUDOREF $A &&
470+
test $A = $(cat .git/PSEUDOREF)
471+
'
472+
473+
test_expect_success 'overwrite pseudoref with no old value given' '
474+
git update-ref PSEUDOREF $B &&
475+
test $B = $(cat .git/PSEUDOREF)
476+
'
477+
478+
test_expect_success 'overwrite pseudoref with correct old value' '
479+
git update-ref PSEUDOREF $C $B &&
480+
test $C = $(cat .git/PSEUDOREF)
481+
'
482+
483+
test_expect_success 'do not overwrite pseudoref with wrong old value' '
484+
test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
485+
test $C = $(cat .git/PSEUDOREF) &&
486+
grep "unexpected object ID" err
487+
'
488+
489+
test_expect_success 'delete pseudoref' '
490+
git update-ref -d PSEUDOREF &&
491+
test_path_is_missing .git/PSEUDOREF
492+
'
493+
494+
test_expect_success 'do not delete pseudoref with wrong old value' '
495+
git update-ref PSEUDOREF $A &&
496+
test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
497+
test $A = $(cat .git/PSEUDOREF) &&
498+
grep "unexpected object ID" err
499+
'
500+
501+
test_expect_success 'delete pseudoref with correct old value' '
502+
git update-ref -d PSEUDOREF $A &&
503+
test_path_is_missing .git/PSEUDOREF
504+
'
505+
506+
test_expect_failure 'create pseudoref with old OID zero' '
507+
git update-ref PSEUDOREF $A $Z &&
508+
test $A = $(cat .git/PSEUDOREF)
509+
'
510+
511+
test_expect_failure 'do not overwrite pseudoref with old OID zero' '
512+
test_when_finished git update-ref -d PSEUDOREF &&
513+
test_must_fail git update-ref PSEUDOREF $B $Z 2>err &&
514+
test $A = $(cat .git/PSEUDOREF) &&
515+
grep "already exists" err
516+
'
517+
518+
# Test --stdin
519+
460520
a=refs/heads/a
461521
b=refs/heads/b
462522
c=refs/heads/c

0 commit comments

Comments
 (0)