Merge branch 'cm/t7xxx-cleanup'

Micro clean-up.

* cm/t7xxx-cleanup:
  t7102: prepare expected output inside test_expect_* block
  t7201: put each command on a separate line
  t7201: use 'git -C' to avoid subshell
  t7102,t7201: remove whitespace after redirect operator
  t7102,t7201: remove unnecessary blank spaces in test body
  t7101,t7102,t7201: modernize test formatting
maint
Junio C Hamano 2020-10-30 13:04:24 -07:00
commit c8b7c0272a
3 changed files with 217 additions and 258 deletions

View File

@ -6,16 +6,15 @@
test_description='git reset should cull empty subdirs' test_description='git reset should cull empty subdirs'
. ./test-lib.sh . ./test-lib.sh


test_expect_success \ test_expect_success 'creating initial files' '
'creating initial files' \ mkdir path0 &&
'mkdir path0 &&
cp "$TEST_DIRECTORY"/../COPYING path0/COPYING && cp "$TEST_DIRECTORY"/../COPYING path0/COPYING &&
git add path0/COPYING && git add path0/COPYING &&
git commit -m add -a' git commit -m add -a
'


test_expect_success \ test_expect_success 'creating second files' '
'creating second files' \ mkdir path1 &&
'mkdir path1 &&
mkdir path1/path2 && mkdir path1/path2 &&
cp "$TEST_DIRECTORY"/../COPYING path1/path2/COPYING && cp "$TEST_DIRECTORY"/../COPYING path1/path2/COPYING &&
cp "$TEST_DIRECTORY"/../COPYING path1/COPYING && cp "$TEST_DIRECTORY"/../COPYING path1/COPYING &&
@ -25,39 +24,40 @@ test_expect_success \
git add path1/COPYING && git add path1/COPYING &&
git add COPYING && git add COPYING &&
git add path0/COPYING-TOO && git add path0/COPYING-TOO &&
git commit -m change -a' git commit -m change -a
'


test_expect_success \ test_expect_success 'resetting tree HEAD^' '
'resetting tree HEAD^' \ git reset --hard HEAD^
'git reset --hard HEAD^' '


test_expect_success \ test_expect_success 'checking initial files exist after rewind' '
'checking initial files exist after rewind' \ test -d path0 &&
'test -d path0 && test -f path0/COPYING
test -f path0/COPYING' '


test_expect_success \ test_expect_success 'checking lack of path1/path2/COPYING' '
'checking lack of path1/path2/COPYING' \ ! test -f path1/path2/COPYING
'! test -f path1/path2/COPYING' '


test_expect_success \ test_expect_success 'checking lack of path1/COPYING' '
'checking lack of path1/COPYING' \ ! test -f path1/COPYING
'! test -f path1/COPYING' '


test_expect_success \ test_expect_success 'checking lack of COPYING' '
'checking lack of COPYING' \ ! test -f COPYING
'! test -f COPYING' '


test_expect_success \ test_expect_success 'checking checking lack of path1/COPYING-TOO' '
'checking checking lack of path1/COPYING-TOO' \ ! test -f path0/COPYING-TOO
'! test -f path0/COPYING-TOO' '


test_expect_success \ test_expect_success 'checking lack of path1/path2' '
'checking lack of path1/path2' \ ! test -d path1/path2
'! test -d path1/path2' '


test_expect_success \ test_expect_success 'checking lack of path1' '
'checking lack of path1' \ ! test -d path1
'! test -d path1' '


test_done test_done

View File

@ -70,27 +70,27 @@ check_changes () {


test_expect_success 'reset --hard message' ' test_expect_success 'reset --hard message' '
hex=$(git log -1 --format="%h") && hex=$(git log -1 --format="%h") &&
git reset --hard > .actual && git reset --hard >.actual &&
echo HEAD is now at $hex $(commit_msg) > .expected && echo HEAD is now at $hex $(commit_msg) >.expected &&
test_i18ncmp .expected .actual test_i18ncmp .expected .actual
' '


test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' ' test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' '
hex=$(git log -1 --format="%h") && hex=$(git log -1 --format="%h") &&
git -c "i18n.logOutputEncoding=$test_encoding" reset --hard > .actual && git -c "i18n.logOutputEncoding=$test_encoding" reset --hard >.actual &&
echo HEAD is now at $hex $(commit_msg $test_encoding) > .expected && echo HEAD is now at $hex $(commit_msg $test_encoding) >.expected &&
test_i18ncmp .expected .actual test_i18ncmp .expected .actual
' '


>.diff_expect
>.cached_expect
cat >.cat_expect <<EOF
secondfile:
1st line 2nd file
2nd line 2nd file
EOF

test_expect_success 'giving a non existing revision should fail' ' test_expect_success 'giving a non existing revision should fail' '
>.diff_expect &&
>.cached_expect &&
cat >.cat_expect <<-\EOF &&
secondfile:
1st line 2nd file
2nd line 2nd file
EOF

test_must_fail git reset aaaaaa && test_must_fail git reset aaaaaa &&
test_must_fail git reset --mixed aaaaaa && test_must_fail git reset --mixed aaaaaa &&
test_must_fail git reset --soft aaaaaa && test_must_fail git reset --soft aaaaaa &&
@ -107,8 +107,7 @@ test_expect_success 'reset --soft with unmerged index should fail' '
git rm --cached -- un git rm --cached -- un
' '


test_expect_success \ test_expect_success 'giving paths with options different than --mixed should fail' '
'giving paths with options different than --mixed should fail' '
test_must_fail git reset --soft -- first && test_must_fail git reset --soft -- first &&
test_must_fail git reset --hard -- first && test_must_fail git reset --hard -- first &&
test_must_fail git reset --soft HEAD^ -- first && test_must_fail git reset --soft HEAD^ -- first &&
@ -128,8 +127,7 @@ test_expect_success 'giving unrecognized options should fail' '
check_changes $head5 check_changes $head5
' '


test_expect_success \ test_expect_success 'trying to do reset --soft with pending merge should fail' '
'trying to do reset --soft with pending merge should fail' '
git branch branch1 && git branch branch1 &&
git branch branch2 && git branch branch2 &&


@ -152,8 +150,7 @@ test_expect_success \
check_changes $head5 check_changes $head5
' '


test_expect_success \ test_expect_success 'trying to do reset --soft with pending checkout merge should fail' '
'trying to do reset --soft with pending checkout merge should fail' '
git branch branch3 && git branch branch3 &&
git branch branch4 && git branch branch4 &&


@ -175,8 +172,7 @@ test_expect_success \
check_changes $head5 check_changes $head5
' '


test_expect_success \ test_expect_success 'resetting to HEAD with no changes should succeed and do nothing' '
'resetting to HEAD with no changes should succeed and do nothing' '
git reset --hard && git reset --hard &&
check_changes $head5 && check_changes $head5 &&
git reset --hard HEAD && git reset --hard HEAD &&
@ -195,39 +191,38 @@ test_expect_success \
check_changes $head5 check_changes $head5
' '


>.diff_expect
cat >.cached_expect <<EOF
diff --git a/secondfile b/secondfile
index $head5p1s..$head5s 100644
--- a/secondfile
+++ b/secondfile
@@ -1 +1,2 @@
-2nd file
+1st line 2nd file
+2nd line 2nd file
EOF
cat >.cat_expect <<EOF
secondfile:
1st line 2nd file
2nd line 2nd file
EOF
test_expect_success '--soft reset only should show changes in diff --cached' ' test_expect_success '--soft reset only should show changes in diff --cached' '
>.diff_expect &&
cat >.cached_expect <<-EOF &&
diff --git a/secondfile b/secondfile
index $head5p1s..$head5s 100644
--- a/secondfile
+++ b/secondfile
@@ -1 +1,2 @@
-2nd file
+1st line 2nd file
+2nd line 2nd file
EOF
cat >.cat_expect <<-\EOF &&
secondfile:
1st line 2nd file
2nd line 2nd file
EOF
git reset --soft HEAD^ && git reset --soft HEAD^ &&
check_changes $head5p1 && check_changes $head5p1 &&
test "$(git rev-parse ORIG_HEAD)" = \ test "$(git rev-parse ORIG_HEAD)" = \
$head5 $head5
' '


>.diff_expect test_expect_success 'changing files and redo the last commit should succeed' '
>.cached_expect >.diff_expect &&
cat >.cat_expect <<EOF >.cached_expect &&
secondfile: cat >.cat_expect <<-\EOF &&
1st line 2nd file secondfile:
2nd line 2nd file 1st line 2nd file
3rd line 2nd file 2nd line 2nd file
EOF 3rd line 2nd file
test_expect_success \ EOF
'changing files and redo the last commit should succeed' '
echo "3rd line 2nd file" >>secondfile && echo "3rd line 2nd file" >>secondfile &&
git commit -a -C ORIG_HEAD && git commit -a -C ORIG_HEAD &&
head4=$(git rev-parse --verify HEAD) && head4=$(git rev-parse --verify HEAD) &&
@ -236,56 +231,54 @@ test_expect_success \
$head5 $head5
' '


>.diff_expect test_expect_success '--hard reset should change the files and undo commits permanently' '
>.cached_expect >.diff_expect &&
cat >.cat_expect <<EOF >.cached_expect &&
first: cat >.cat_expect <<-\EOF &&
1st file first:
2nd line 1st file 1st file
second: 2nd line 1st file
2nd file second:
EOF 2nd file
test_expect_success \ EOF
'--hard reset should change the files and undo commits permanently' '
git reset --hard HEAD~2 && git reset --hard HEAD~2 &&
check_changes $head5p2 && check_changes $head5p2 &&
test "$(git rev-parse ORIG_HEAD)" = \ test "$(git rev-parse ORIG_HEAD)" = \
$head4 $head4
' '


>.diff_expect test_expect_success 'redoing changes adding them without commit them should succeed' '
cat >.cached_expect <<EOF >.diff_expect &&
diff --git a/first b/first cat >.cached_expect <<-EOF &&
deleted file mode 100644 diff --git a/first b/first
index $head5p2f..0000000 deleted file mode 100644
--- a/first index $head5p2f..0000000
+++ /dev/null --- a/first
@@ -1,2 +0,0 @@ +++ /dev/null
-1st file @@ -1,2 +0,0 @@
-2nd line 1st file -1st file
diff --git a/second b/second -2nd line 1st file
deleted file mode 100644 diff --git a/second b/second
index $head5p1s..0000000 deleted file mode 100644
--- a/second index $head5p1s..0000000
+++ /dev/null --- a/second
@@ -1 +0,0 @@ +++ /dev/null
-2nd file @@ -1 +0,0 @@
diff --git a/secondfile b/secondfile -2nd file
new file mode 100644 diff --git a/secondfile b/secondfile
index 0000000..$head5s new file mode 100644
--- /dev/null index 0000000..$head5s
+++ b/secondfile --- /dev/null
@@ -0,0 +1,2 @@ +++ b/secondfile
+1st line 2nd file @@ -0,0 +1,2 @@
+2nd line 2nd file +1st line 2nd file
EOF +2nd line 2nd file
cat >.cat_expect <<EOF EOF
secondfile: cat >.cat_expect <<-\EOF &&
1st line 2nd file secondfile:
2nd line 2nd file 1st line 2nd file
EOF 2nd line 2nd file
test_expect_success \ EOF
'redoing changes adding them without commit them should succeed' '
git rm first && git rm first &&
git mv second secondfile && git mv second secondfile &&


@ -295,46 +288,45 @@ test_expect_success \
check_changes $head5p2 check_changes $head5p2
' '


cat >.diff_expect <<EOF
diff --git a/first b/first
deleted file mode 100644
index $head5p2f..0000000
--- a/first
+++ /dev/null
@@ -1,2 +0,0 @@
-1st file
-2nd line 1st file
diff --git a/second b/second
deleted file mode 100644
index $head5p1s..0000000
--- a/second
+++ /dev/null
@@ -1 +0,0 @@
-2nd file
EOF
>.cached_expect
cat >.cat_expect <<EOF
secondfile:
1st line 2nd file
2nd line 2nd file
EOF
test_expect_success '--mixed reset to HEAD should unadd the files' ' test_expect_success '--mixed reset to HEAD should unadd the files' '
cat >.diff_expect <<-EOF &&
diff --git a/first b/first
deleted file mode 100644
index $head5p2f..0000000
--- a/first
+++ /dev/null
@@ -1,2 +0,0 @@
-1st file
-2nd line 1st file
diff --git a/second b/second
deleted file mode 100644
index $head5p1s..0000000
--- a/second
+++ /dev/null
@@ -1 +0,0 @@
-2nd file
EOF
>.cached_expect &&
cat >.cat_expect <<-\EOF &&
secondfile:
1st line 2nd file
2nd line 2nd file
EOF
git reset && git reset &&
check_changes $head5p2 && check_changes $head5p2 &&
test "$(git rev-parse ORIG_HEAD)" = $head5p2 test "$(git rev-parse ORIG_HEAD)" = $head5p2
' '


>.diff_expect
>.cached_expect
cat >.cat_expect <<EOF
secondfile:
1st line 2nd file
2nd line 2nd file
EOF
test_expect_success 'redoing the last two commits should succeed' ' test_expect_success 'redoing the last two commits should succeed' '
>.diff_expect &&
>.cached_expect &&
cat >.cat_expect <<-\EOF &&
secondfile:
1st line 2nd file
2nd line 2nd file
EOF
git add secondfile && git add secondfile &&
git reset --hard $head5p2 && git reset --hard $head5p2 &&

git rm first && git rm first &&
git mv second secondfile && git mv second secondfile &&
git commit -a -m "remove 1st and rename 2nd" && git commit -a -m "remove 1st and rename 2nd" &&
@ -347,15 +339,15 @@ test_expect_success 'redoing the last two commits should succeed' '
check_changes $head5 check_changes $head5
' '


>.diff_expect
>.cached_expect
cat >.cat_expect <<EOF
secondfile:
1st line 2nd file
2nd line 2nd file
3rd line in branch2
EOF
test_expect_success '--hard reset to HEAD should clear a failed merge' ' test_expect_success '--hard reset to HEAD should clear a failed merge' '
>.diff_expect &&
>.cached_expect &&
cat >.cat_expect <<-\EOF &&
secondfile:
1st line 2nd file
2nd line 2nd file
3rd line in branch2
EOF
git branch branch1 && git branch branch1 &&
git branch branch2 && git branch branch2 &&


@ -373,15 +365,14 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' '
check_changes $head3 check_changes $head3
' '


>.diff_expect test_expect_success '--hard reset to ORIG_HEAD should clear a fast-forward merge' '
>.cached_expect >.diff_expect &&
cat >.cat_expect <<EOF >.cached_expect &&
secondfile: cat >.cat_expect <<-\EOF &&
1st line 2nd file secondfile:
2nd line 2nd file 1st line 2nd file
EOF 2nd line 2nd file
test_expect_success \ EOF
'--hard reset to ORIG_HEAD should clear a fast-forward merge' '
git reset --hard HEAD^ && git reset --hard HEAD^ &&
check_changes $head5 && check_changes $head5 &&


@ -395,25 +386,25 @@ test_expect_success \
' '


test_expect_success 'test --mixed <paths>' ' test_expect_success 'test --mixed <paths>' '
echo 1 > file1 && echo 1 >file1 &&
echo 2 > file2 && echo 2 >file2 &&
git add file1 file2 && git add file1 file2 &&
test_tick && test_tick &&
git commit -m files && git commit -m files &&
before1=$(git rev-parse --short HEAD:file1) && before1=$(git rev-parse --short HEAD:file1) &&
before2=$(git rev-parse --short HEAD:file2) && before2=$(git rev-parse --short HEAD:file2) &&
git rm file2 && git rm file2 &&
echo 3 > file3 && echo 3 >file3 &&
echo 4 > file4 && echo 4 >file4 &&
echo 5 > file1 && echo 5 >file1 &&
after1=$(git rev-parse --short $(git hash-object file1)) && after1=$(git rev-parse --short $(git hash-object file1)) &&
after4=$(git rev-parse --short $(git hash-object file4)) && after4=$(git rev-parse --short $(git hash-object file4)) &&
git add file1 file3 file4 && git add file1 file3 file4 &&
git reset HEAD -- file1 file2 file3 && git reset HEAD -- file1 file2 file3 &&
test_must_fail git diff --quiet && test_must_fail git diff --quiet &&
git diff > output && git diff >output &&


cat > expect <<-EOF && cat >expect <<-EOF &&
diff --git a/file1 b/file1 diff --git a/file1 b/file1
index $before1..$after1 100644 index $before1..$after1 100644
--- a/file1 --- a/file1
@ -431,9 +422,9 @@ test_expect_success 'test --mixed <paths>' '
EOF EOF


test_cmp expect output && test_cmp expect output &&
git diff --cached > output && git diff --cached >output &&


cat > cached_expect <<-EOF && cat >cached_expect <<-EOF &&
diff --git a/file4 b/file4 diff --git a/file4 b/file4
new file mode 100644 new file mode 100644
index 0000000..$after4 index 0000000..$after4
@ -447,7 +438,6 @@ test_expect_success 'test --mixed <paths>' '
' '


test_expect_success 'test resetting the index at give paths' ' test_expect_success 'test resetting the index at give paths' '

mkdir sub && mkdir sub &&
>sub/file1 && >sub/file1 &&
>sub/file2 && >sub/file2 &&
@ -460,7 +450,6 @@ test_expect_success 'test resetting the index at give paths' '
echo "$U" && echo "$U" &&
test_must_fail git diff-index --cached --exit-code "$T" && test_must_fail git diff-index --cached --exit-code "$T" &&
test "$T" != "$U" test "$T" != "$U"

' '


test_expect_success 'resetting an unmodified path is a no-op' ' test_expect_success 'resetting an unmodified path is a no-op' '
@ -470,14 +459,13 @@ test_expect_success 'resetting an unmodified path is a no-op' '
git diff-index --cached --exit-code HEAD git diff-index --cached --exit-code HEAD
' '


cat > expect << EOF
Unstaged changes after reset:
M file2
EOF

test_expect_success '--mixed refreshes the index' ' test_expect_success '--mixed refreshes the index' '
echo 123 >> file2 && cat >expect <<-\EOF &&
git reset --mixed HEAD > output && Unstaged changes after reset:
M file2
EOF
echo 123 >>file2 &&
git reset --mixed HEAD >output &&
test_i18ncmp expect output test_i18ncmp expect output
' '


@ -498,7 +486,6 @@ test_expect_success 'resetting specific path that is unmerged' '
' '


test_expect_success 'disambiguation (1)' ' test_expect_success 'disambiguation (1)' '

git reset --hard && git reset --hard &&
>secondfile && >secondfile &&
git add secondfile && git add secondfile &&
@ -507,11 +494,9 @@ test_expect_success 'disambiguation (1)' '
test -z "$(git diff --cached --name-only)" && test -z "$(git diff --cached --name-only)" &&
test -f secondfile && test -f secondfile &&
test_must_be_empty secondfile test_must_be_empty secondfile

' '


test_expect_success 'disambiguation (2)' ' test_expect_success 'disambiguation (2)' '

git reset --hard && git reset --hard &&
>secondfile && >secondfile &&
git add secondfile && git add secondfile &&
@ -519,11 +504,9 @@ test_expect_success 'disambiguation (2)' '
test_must_fail git reset secondfile && test_must_fail git reset secondfile &&
test -n "$(git diff --cached --name-only -- secondfile)" && test -n "$(git diff --cached --name-only -- secondfile)" &&
test ! -f secondfile test ! -f secondfile

' '


test_expect_success 'disambiguation (3)' ' test_expect_success 'disambiguation (3)' '

git reset --hard && git reset --hard &&
>secondfile && >secondfile &&
git add secondfile && git add secondfile &&
@ -532,11 +515,9 @@ test_expect_success 'disambiguation (3)' '
test_must_fail git diff --quiet && test_must_fail git diff --quiet &&
test -z "$(git diff --cached --name-only)" && test -z "$(git diff --cached --name-only)" &&
test ! -f secondfile test ! -f secondfile

' '


test_expect_success 'disambiguation (4)' ' test_expect_success 'disambiguation (4)' '

git reset --hard && git reset --hard &&
>secondfile && >secondfile &&
git add secondfile && git add secondfile &&

View File

@ -33,8 +33,7 @@ fill () {




test_expect_success setup ' test_expect_success setup '

fill x y z >same &&
fill x y z > same &&
fill 1 2 3 4 5 6 7 8 >one && fill 1 2 3 4 5 6 7 8 >one &&
fill a b c d e >two && fill a b c d e >two &&
git add same one two && git add same one two &&
@ -56,14 +55,13 @@ test_expect_success setup '


git checkout -b simple master && git checkout -b simple master &&
rm -f one && rm -f one &&
fill a c e > two && fill a c e >two &&
git commit -a -m "Simple D one, M two" && git commit -a -m "Simple D one, M two" &&


git checkout master git checkout master
' '


test_expect_success "checkout from non-existing branch" ' test_expect_success 'checkout from non-existing branch' '

git checkout -b delete-me master && git checkout -b delete-me master &&
git update-ref -d --no-deref refs/heads/delete-me && git update-ref -d --no-deref refs/heads/delete-me &&
test refs/heads/delete-me = "$(git symbolic-ref HEAD)" && test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
@ -71,8 +69,7 @@ test_expect_success "checkout from non-existing branch" '
test refs/heads/master = "$(git symbolic-ref HEAD)" test refs/heads/master = "$(git symbolic-ref HEAD)"
' '


test_expect_success "checkout with dirty tree without -m" ' test_expect_success 'checkout with dirty tree without -m' '

fill 0 1 2 3 4 5 6 7 8 >one && fill 0 1 2 3 4 5 6 7 8 >one &&
if git checkout side if git checkout side
then then
@ -81,11 +78,9 @@ test_expect_success "checkout with dirty tree without -m" '
else else
echo "happy - failed correctly" echo "happy - failed correctly"
fi fi

' '


test_expect_success "checkout with unrelated dirty tree without -m" ' test_expect_success 'checkout with unrelated dirty tree without -m' '

git checkout -f master && git checkout -f master &&
fill 0 1 2 3 4 5 6 7 8 >same && fill 0 1 2 3 4 5 6 7 8 >same &&
cp same kept && cp same kept &&
@ -95,13 +90,12 @@ test_expect_success "checkout with unrelated dirty tree without -m" '
test_cmp messages.expect messages test_cmp messages.expect messages
' '


test_expect_success "checkout -m with dirty tree" ' test_expect_success 'checkout -m with dirty tree' '

git checkout -f master && git checkout -f master &&
git clean -f && git clean -f &&


fill 0 1 2 3 4 5 6 7 8 >one && fill 0 1 2 3 4 5 6 7 8 >one &&
git checkout -m side > messages && git checkout -m side >messages &&


test "$(git symbolic-ref HEAD)" = "refs/heads/side" && test "$(git symbolic-ref HEAD)" = "refs/heads/side" &&


@ -120,8 +114,7 @@ test_expect_success "checkout -m with dirty tree" '
test_must_be_empty current.index test_must_be_empty current.index
' '


test_expect_success "checkout -m with dirty tree, renamed" ' test_expect_success 'checkout -m with dirty tree, renamed' '

git checkout -f master && git clean -f && git checkout -f master && git clean -f &&


fill 1 2 3 4 5 7 8 >one && fill 1 2 3 4 5 7 8 >one &&
@ -139,11 +132,9 @@ test_expect_success "checkout -m with dirty tree, renamed" '
! test -f one && ! test -f one &&
git diff --cached >current && git diff --cached >current &&
test_must_be_empty current test_must_be_empty current

' '


test_expect_success 'checkout -m with merge conflict' ' test_expect_success 'checkout -m with merge conflict' '

git checkout -f master && git clean -f && git checkout -f master && git clean -f &&


fill 1 T 3 4 5 6 S 8 >one && fill 1 T 3 4 5 6 S 8 >one &&
@ -166,10 +157,10 @@ test_expect_success 'checkout -m with merge conflict' '
' '


test_expect_success 'format of merge conflict from checkout -m' ' test_expect_success 'format of merge conflict from checkout -m' '
git checkout -f master &&
git clean -f &&


git checkout -f master && git clean -f && fill b d >two &&

fill b d > two &&
git checkout -m simple && git checkout -m simple &&


git ls-files >current && git ls-files >current &&
@ -190,10 +181,11 @@ test_expect_success 'format of merge conflict from checkout -m' '
' '


test_expect_success 'checkout --merge --conflict=diff3 <branch>' ' test_expect_success 'checkout --merge --conflict=diff3 <branch>' '
git checkout -f master &&
git reset --hard &&
git clean -f &&


git checkout -f master && git reset --hard && git clean -f && fill b d >two &&

fill b d > two &&
git checkout --merge --conflict=diff3 simple && git checkout --merge --conflict=diff3 simple &&


cat <<-EOF >expect && cat <<-EOF >expect &&
@ -216,8 +208,9 @@ test_expect_success 'checkout --merge --conflict=diff3 <branch>' '
' '


test_expect_success 'switch to another branch while carrying a deletion' ' test_expect_success 'switch to another branch while carrying a deletion' '

git checkout -f master &&
git checkout -f master && git reset --hard && git clean -f && git reset --hard &&
git clean -f &&
git rm two && git rm two &&


test_must_fail git checkout simple 2>errs && test_must_fail git checkout simple 2>errs &&
@ -228,10 +221,10 @@ test_expect_success 'switch to another branch while carrying a deletion' '
' '


test_expect_success 'checkout to detach HEAD (with advice declined)' ' test_expect_success 'checkout to detach HEAD (with advice declined)' '

git config advice.detachedHead false && git config advice.detachedHead false &&
rev=$(git rev-parse --short renamer^) && rev=$(git rev-parse --short renamer^) &&
git checkout -f renamer && git clean -f && git checkout -f renamer &&
git clean -f &&
git checkout renamer^ 2>messages && git checkout renamer^ 2>messages &&
test_i18ngrep "HEAD is now at $rev" messages && test_i18ngrep "HEAD is now at $rev" messages &&
test_line_count = 1 messages && test_line_count = 1 messages &&
@ -250,7 +243,8 @@ test_expect_success 'checkout to detach HEAD (with advice declined)' '
test_expect_success 'checkout to detach HEAD' ' test_expect_success 'checkout to detach HEAD' '
git config advice.detachedHead true && git config advice.detachedHead true &&
rev=$(git rev-parse --short renamer^) && rev=$(git rev-parse --short renamer^) &&
git checkout -f renamer && git clean -f && git checkout -f renamer &&
git clean -f &&
GIT_TEST_GETTEXT_POISON=false git checkout renamer^ 2>messages && GIT_TEST_GETTEXT_POISON=false git checkout renamer^ 2>messages &&
grep "HEAD is now at $rev" messages && grep "HEAD is now at $rev" messages &&
test_line_count -gt 1 messages && test_line_count -gt 1 messages &&
@ -267,8 +261,8 @@ test_expect_success 'checkout to detach HEAD' '
' '


test_expect_success 'checkout to detach HEAD with branchname^' ' test_expect_success 'checkout to detach HEAD with branchname^' '

git checkout -f master &&
git checkout -f master && git clean -f && git clean -f &&
git checkout renamer^ && git checkout renamer^ &&
H=$(git rev-parse --verify HEAD) && H=$(git rev-parse --verify HEAD) &&
M=$(git show-ref -s --verify refs/heads/master) && M=$(git show-ref -s --verify refs/heads/master) &&
@ -283,8 +277,8 @@ test_expect_success 'checkout to detach HEAD with branchname^' '
' '


test_expect_success 'checkout to detach HEAD with :/message' ' test_expect_success 'checkout to detach HEAD with :/message' '

git checkout -f master &&
git checkout -f master && git clean -f && git clean -f &&
git checkout ":/Initial" && git checkout ":/Initial" &&
H=$(git rev-parse --verify HEAD) && H=$(git rev-parse --verify HEAD) &&
M=$(git show-ref -s --verify refs/heads/master) && M=$(git show-ref -s --verify refs/heads/master) &&
@ -299,8 +293,8 @@ test_expect_success 'checkout to detach HEAD with :/message' '
' '


test_expect_success 'checkout to detach HEAD with HEAD^0' ' test_expect_success 'checkout to detach HEAD with HEAD^0' '

git checkout -f master &&
git checkout -f master && git clean -f && git clean -f &&
git checkout HEAD^0 && git checkout HEAD^0 &&
H=$(git rev-parse --verify HEAD) && H=$(git rev-parse --verify HEAD) &&
M=$(git show-ref -s --verify refs/heads/master) && M=$(git show-ref -s --verify refs/heads/master) &&
@ -315,7 +309,6 @@ test_expect_success 'checkout to detach HEAD with HEAD^0' '
' '


test_expect_success 'checkout with ambiguous tag/branch names' ' test_expect_success 'checkout with ambiguous tag/branch names' '

git tag both side && git tag both side &&
git branch both master && git branch both master &&
git reset --hard && git reset --hard &&
@ -327,11 +320,9 @@ test_expect_success 'checkout with ambiguous tag/branch names' '
test "z$H" = "z$M" && test "z$H" = "z$M" &&
name=$(git symbolic-ref HEAD 2>/dev/null) && name=$(git symbolic-ref HEAD 2>/dev/null) &&
test "z$name" = zrefs/heads/both test "z$name" = zrefs/heads/both

' '


test_expect_success 'checkout with ambiguous tag/branch names' ' test_expect_success 'checkout with ambiguous tag/branch names' '

git reset --hard && git reset --hard &&
git checkout master && git checkout master &&


@ -351,26 +342,19 @@ test_expect_success 'checkout with ambiguous tag/branch names' '
else else
: happy : happy
fi fi

' '


test_expect_success 'switch branches while in subdirectory' ' test_expect_success 'switch branches while in subdirectory' '

git reset --hard && git reset --hard &&
git checkout master && git checkout master &&


mkdir subs && mkdir subs &&
( git -C subs checkout side &&
cd subs &&
git checkout side
) &&
! test -f subs/one && ! test -f subs/one &&
rm -fr subs rm -fr subs

' '


test_expect_success 'checkout specific path while in subdirectory' ' test_expect_success 'checkout specific path while in subdirectory' '

git reset --hard && git reset --hard &&
git checkout side && git checkout side &&
mkdir subs && mkdir subs &&
@ -380,30 +364,26 @@ test_expect_success 'checkout specific path while in subdirectory' '


git checkout master && git checkout master &&
mkdir -p subs && mkdir -p subs &&
( git -C subs checkout side -- bero &&
cd subs &&
git checkout side -- bero
) &&
test -f subs/bero test -f subs/bero

' '


test_expect_success \ test_expect_success 'checkout w/--track sets up tracking' '
'checkout w/--track sets up tracking' '
git config branch.autosetupmerge false && git config branch.autosetupmerge false &&
git checkout master && git checkout master &&
git checkout --track -b track1 && git checkout --track -b track1 &&
test "$(git config branch.track1.remote)" && test "$(git config branch.track1.remote)" &&
test "$(git config branch.track1.merge)"' test "$(git config branch.track1.merge)"
'


test_expect_success \ test_expect_success 'checkout w/autosetupmerge=always sets up tracking' '
'checkout w/autosetupmerge=always sets up tracking' '
test_when_finished git config branch.autosetupmerge false && test_when_finished git config branch.autosetupmerge false &&
git config branch.autosetupmerge always && git config branch.autosetupmerge always &&
git checkout master && git checkout master &&
git checkout -b track2 && git checkout -b track2 &&
test "$(git config branch.track2.remote)" && test "$(git config branch.track2.remote)" &&
test "$(git config branch.track2.merge)"' test "$(git config branch.track2.merge)"
'


test_expect_success 'checkout w/--track from non-branch HEAD fails' ' test_expect_success 'checkout w/--track from non-branch HEAD fails' '
git checkout master^0 && git checkout master^0 &&
@ -435,8 +415,7 @@ test_expect_success 'detach a symbolic link HEAD' '
test "z$(git rev-parse --verify refs/heads/master)" = "z$here" test "z$(git rev-parse --verify refs/heads/master)" = "z$here"
' '


test_expect_success \ test_expect_success 'checkout with --track fakes a sensible -b <name>' '
'checkout with --track fakes a sensible -b <name>' '
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" && git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" &&
git update-ref refs/remotes/origin/koala/bear renamer && git update-ref refs/remotes/origin/koala/bear renamer &&


@ -457,9 +436,9 @@ test_expect_success \
test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)"
' '


test_expect_success \ test_expect_success 'checkout with --track, but without -b, fails with too short tracked name' '
'checkout with --track, but without -b, fails with too short tracked name' ' test_must_fail git checkout --track renamer
test_must_fail git checkout --track renamer' '


setup_conflicting_index () { setup_conflicting_index () {
rm -f .git/index && rm -f .git/index &&
@ -609,7 +588,6 @@ test_expect_success 'failing checkout -b should not break working tree' '
test $(git symbolic-ref HEAD) = refs/heads/master && test $(git symbolic-ref HEAD) = refs/heads/master &&
git diff --exit-code && git diff --exit-code &&
git diff --cached --exit-code git diff --cached --exit-code

' '


test_expect_success 'switch out of non-branch' ' test_expect_success 'switch out of non-branch' '