summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-05-30 05:04:08 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-05-30 05:04:08 (GMT)
commit26597cb0cceb82b315c543f1cc02bbb72c537eaa (patch)
tree99051d4931818a123a6123bbcb6cfe6f512d6586 /t
parentcf315793c1ef90788470438a7ef8dc281ea97806 (diff)
parentdb0210d445963e5d85f98e48d6a93b971779d449 (diff)
downloadgit-26597cb0cceb82b315c543f1cc02bbb72c537eaa.zip
git-26597cb0cceb82b315c543f1cc02bbb72c537eaa.tar.gz
git-26597cb0cceb82b315c543f1cc02bbb72c537eaa.tar.bz2
Merge branch 'ma/create-pseudoref-with-null-old-oid'
"git update-ref A B" is supposed to ensure that ref A does not yet exist when B is a NULL OID, but this check was not done correctly for pseudo-refs outside refs/ hierarchy, e.g. MERGE_HEAD. * ma/create-pseudoref-with-null-old-oid: refs: handle zero oid for pseudorefs t1400: add tests around adding/deleting pseudorefs refs.c: refer to "object ID", not "sha1", in error messages
Diffstat (limited to 't')
-rwxr-xr-xt/t1400-update-ref.sh60
1 files changed, 60 insertions, 0 deletions
diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh
index 664a3a4..faf0dfe 100755
--- a/t/t1400-update-ref.sh
+++ b/t/t1400-update-ref.sh
@@ -457,6 +457,66 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER
test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")
'
+# Test adding and deleting pseudorefs
+
+test_expect_success 'given old value for missing pseudoref, do not create' '
+ test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
+ test_path_is_missing .git/PSEUDOREF &&
+ grep "could not read ref" err
+'
+
+test_expect_success 'create pseudoref' '
+ git update-ref PSEUDOREF $A &&
+ test $A = $(cat .git/PSEUDOREF)
+'
+
+test_expect_success 'overwrite pseudoref with no old value given' '
+ git update-ref PSEUDOREF $B &&
+ test $B = $(cat .git/PSEUDOREF)
+'
+
+test_expect_success 'overwrite pseudoref with correct old value' '
+ git update-ref PSEUDOREF $C $B &&
+ test $C = $(cat .git/PSEUDOREF)
+'
+
+test_expect_success 'do not overwrite pseudoref with wrong old value' '
+ test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
+ test $C = $(cat .git/PSEUDOREF) &&
+ grep "unexpected object ID" err
+'
+
+test_expect_success 'delete pseudoref' '
+ git update-ref -d PSEUDOREF &&
+ test_path_is_missing .git/PSEUDOREF
+'
+
+test_expect_success 'do not delete pseudoref with wrong old value' '
+ git update-ref PSEUDOREF $A &&
+ test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
+ test $A = $(cat .git/PSEUDOREF) &&
+ grep "unexpected object ID" err
+'
+
+test_expect_success 'delete pseudoref with correct old value' '
+ git update-ref -d PSEUDOREF $A &&
+ test_path_is_missing .git/PSEUDOREF
+'
+
+test_expect_success 'create pseudoref with old OID zero' '
+ git update-ref PSEUDOREF $A $Z &&
+ test $A = $(cat .git/PSEUDOREF)
+'
+
+test_expect_success 'do not overwrite pseudoref with old OID zero' '
+ test_when_finished git update-ref -d PSEUDOREF &&
+ test_must_fail git update-ref PSEUDOREF $B $Z 2>err &&
+ test $A = $(cat .git/PSEUDOREF) &&
+ grep "already exists" err
+'
+
+# Test --stdin
+
a=refs/heads/a
b=refs/heads/b
c=refs/heads/c