]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t7201-co.sh
Enhance hold_lock_file_for_{update,append}() API
[thirdparty/git.git] / t / t7201-co.sh
index 63915cd87b74aaddb943f45057bda10d283b4351..f93478f97ff8d139d4c67690e1c85f098ca90a10 100755 (executable)
@@ -3,7 +3,7 @@
 # Copyright (c) 2006 Junio C Hamano
 #
 
-test_description='git-checkout tests.
+test_description='git checkout tests.
 
 Creates master, forks renamer and side branches from it.
 Test switching across them.
@@ -83,13 +83,13 @@ test_expect_success "checkout with unrelated dirty tree without -m" '
        fill 0 1 2 3 4 5 6 7 8 >same &&
        cp same kept
        git checkout side >messages &&
-       diff -u same kept
+       test_cmp same kept
        (cat > messages.expect <<EOF
 M      same
 EOF
 ) &&
        touch messages.expect &&
-       diff -u messages.expect messages
+       test_cmp messages.expect messages
 '
 
 test_expect_success "checkout -m with dirty tree" '
@@ -106,19 +106,19 @@ test_expect_success "checkout -m with dirty tree" '
 M      one
 EOF
 ) &&
-       diff -u expect.messages messages &&
+       test_cmp expect.messages messages &&
 
        fill "M one" "A three" "D       two" >expect.master &&
        git diff --name-status master >current.master &&
-       diff -u expect.master current.master &&
+       test_cmp expect.master current.master &&
 
        fill "M one" >expect.side &&
        git diff --name-status side >current.side &&
-       diff -u expect.side current.side &&
+       test_cmp expect.side current.side &&
 
        : >expect.index &&
        git diff --cached >current.index &&
-       diff -u expect.index current.index
+       test_cmp expect.index current.index
 '
 
 test_expect_success "checkout -m with dirty tree, renamed" '
@@ -136,7 +136,7 @@ test_expect_success "checkout -m with dirty tree, renamed" '
 
        git checkout -m renamer &&
        fill 1 3 4 5 7 8 >expect &&
-       diff -u expect uno &&
+       test_cmp expect uno &&
        ! test -f one &&
        git diff --cached >current &&
        ! test -s current
@@ -161,7 +161,7 @@ test_expect_success 'checkout -m with merge conflict' '
        git diff master:one :3:uno |
        sed -e "1,/^@@/d" -e "/^ /d" -e "s/^-/d/" -e "s/^+/a/" >current &&
        fill d2 aT d7 aS >expect &&
-       diff -u current expect &&
+       test_cmp current expect &&
        git diff --cached two >current &&
        ! test -s current
 '
@@ -178,7 +178,7 @@ If you want to create a new branch from this checkout, you may do so
 HEAD is now at 7329388... Initial A one, A two
 EOF
 ) &&
-       diff -u messages.expect messages &&
+       test_cmp messages.expect messages &&
        H=$(git rev-parse --verify HEAD) &&
        M=$(git show-ref -s --verify refs/heads/master) &&
        test "z$H" = "z$M" &&
@@ -330,11 +330,47 @@ test_expect_success \
     test "$(git config branch.track2.merge)"
     git config branch.autosetupmerge false'
 
-test_expect_success \
-    'checkout w/--track from non-branch HEAD fails' '
-    git checkout -b delete-me master &&
-    rm .git/refs/heads/delete-me &&
-    test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
-    !(git checkout --track -b track)'
+test_expect_success 'checkout w/--track from non-branch HEAD fails' '
+    git checkout master^0 &&
+    test_must_fail git symbolic-ref HEAD &&
+    test_must_fail git checkout --track -b track &&
+    test_must_fail git rev-parse --verify track &&
+    test_must_fail git symbolic-ref HEAD &&
+    test "z$(git rev-parse master^0)" = "z$(git rev-parse HEAD)"
+'
+
+test_expect_success 'detach a symbolic link HEAD' '
+    git checkout master &&
+    git config --bool core.prefersymlinkrefs yes &&
+    git checkout side &&
+    git checkout master &&
+    it=$(git symbolic-ref HEAD) &&
+    test "z$it" = zrefs/heads/master &&
+    here=$(git rev-parse --verify refs/heads/master) &&
+    git checkout side^ &&
+    test "z$(git rev-parse --verify refs/heads/master)" = "z$here"
+'
+
+test_expect_success 'checkout an unmerged path should fail' '
+       rm -f .git/index &&
+       O=$(echo original | git hash-object -w --stdin) &&
+       A=$(echo ourside | git hash-object -w --stdin) &&
+       B=$(echo theirside | git hash-object -w --stdin) &&
+       (
+               echo "100644 $A 0       fild" &&
+               echo "100644 $O 1       file" &&
+               echo "100644 $A 2       file" &&
+               echo "100644 $B 3       file" &&
+               echo "100644 $A 0       filf"
+       ) | git update-index --index-info &&
+       echo "none of the above" >sample &&
+       cat sample >fild &&
+       cat sample >file &&
+       cat sample >filf &&
+       test_must_fail git checkout fild file filf &&
+       test_cmp sample fild &&
+       test_cmp sample filf &&
+       test_cmp sample file
+'
 
 test_done