diff options
Diffstat (limited to 't/t7102-reset.sh')
-rwxr-xr-x | t/t7102-reset.sh | 384 |
1 files changed, 189 insertions, 195 deletions
diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index 97be0d968d..b1affb001f 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -37,17 +37,23 @@ test_expect_success 'creating initial files and commits' ' echo "2nd line 1st file" >>first && git commit -a -m "modify 1st file" && + head5p2=$(git rev-parse --verify HEAD) && + head5p2f=$(git rev-parse --short HEAD:first) && git rm first && git mv second secondfile && git commit -a -m "remove 1st and rename 2nd" && + head5p1=$(git rev-parse --verify HEAD) && + head5p1s=$(git rev-parse --short HEAD:secondfile) && echo "1st line 2nd file" >secondfile && echo "2nd line 2nd file" >>secondfile && # "git commit -m" would break MinGW, as Windows refuse to pass # $test_encoding encoded parameter to git. commit_msg $test_encoding | git -c "i18n.commitEncoding=$test_encoding" commit -a -F - && - head5=$(git rev-parse --verify HEAD) + head5=$(git rev-parse --verify HEAD) && + head5s=$(git rev-parse --short HEAD:secondfile) && + head5sl=$(git rev-parse HEAD:secondfile) ' # git log --pretty=oneline # to see those SHA1 involved @@ -64,27 +70,27 @@ check_changes () { test_expect_success 'reset --hard message' ' hex=$(git log -1 --format="%h") && - git reset --hard > .actual && - echo HEAD is now at $hex $(commit_msg) > .expected && + git reset --hard >.actual && + echo HEAD is now at $hex $(commit_msg) >.expected && test_i18ncmp .expected .actual ' test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' ' hex=$(git log -1 --format="%h") && - git -c "i18n.logOutputEncoding=$test_encoding" reset --hard > .actual && - echo HEAD is now at $hex $(commit_msg $test_encoding) > .expected && + git -c "i18n.logOutputEncoding=$test_encoding" reset --hard >.actual && + echo HEAD is now at $hex $(commit_msg $test_encoding) >.expected && 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' ' + >.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 --mixed aaaaaa && test_must_fail git reset --soft aaaaaa && @@ -94,15 +100,14 @@ test_expect_success 'giving a non existing revision should fail' ' test_expect_success 'reset --soft with unmerged index should fail' ' touch .git/MERGE_HEAD && - echo "100644 44c5b5884550c17758737edcced463447b91d42b 1 un" | + echo "100644 $head5sl 1 un" | git update-index --index-info && test_must_fail git reset --soft HEAD && rm .git/MERGE_HEAD && git rm --cached -- un ' -test_expect_success \ - 'giving paths with options different than --mixed should fail' ' +test_expect_success 'giving paths with options different than --mixed should fail' ' test_must_fail git reset --soft -- first && test_must_fail git reset --hard -- first && test_must_fail git reset --soft HEAD^ -- first && @@ -122,8 +127,7 @@ test_expect_success 'giving unrecognized options should fail' ' check_changes $head5 ' -test_expect_success \ - 'trying to do reset --soft with pending merge should fail' ' +test_expect_success 'trying to do reset --soft with pending merge should fail' ' git branch branch1 && git branch branch2 && @@ -146,8 +150,7 @@ test_expect_success \ check_changes $head5 ' -test_expect_success \ - 'trying to do reset --soft with pending checkout merge should fail' ' +test_expect_success 'trying to do reset --soft with pending checkout merge should fail' ' git branch branch3 && git branch branch4 && @@ -169,8 +172,7 @@ test_expect_success \ check_changes $head5 ' -test_expect_success \ - 'resetting to HEAD with no changes should succeed and do nothing' ' +test_expect_success 'resetting to HEAD with no changes should succeed and do nothing' ' git reset --hard && check_changes $head5 && git reset --hard HEAD && @@ -189,39 +191,38 @@ test_expect_success \ check_changes $head5 ' ->.diff_expect -cat >.cached_expect <<EOF -diff --git a/secondfile b/secondfile -index 1bbba79..44c5b58 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' ' + >.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^ && - check_changes d1a4bc3abce4829628ae2dcb0d60ef3d1a78b1c4 && + check_changes $head5p1 && test "$(git rev-parse ORIG_HEAD)" = \ $head5 ' ->.diff_expect ->.cached_expect -cat >.cat_expect <<EOF -secondfile: -1st line 2nd file -2nd line 2nd file -3rd line 2nd file -EOF -test_expect_success \ - 'changing files and redo the last commit should succeed' ' +test_expect_success 'changing files and redo the last commit should succeed' ' + >.diff_expect && + >.cached_expect && + cat >.cat_expect <<-\EOF && + secondfile: + 1st line 2nd file + 2nd line 2nd file + 3rd line 2nd file + EOF echo "3rd line 2nd file" >>secondfile && git commit -a -C ORIG_HEAD && head4=$(git rev-parse --verify HEAD) && @@ -230,106 +231,102 @@ test_expect_success \ $head5 ' ->.diff_expect ->.cached_expect -cat >.cat_expect <<EOF -first: -1st file -2nd line 1st file -second: -2nd file -EOF -test_expect_success \ - '--hard reset should change the files and undo commits permanently' ' +test_expect_success '--hard reset should change the files and undo commits permanently' ' + >.diff_expect && + >.cached_expect && + cat >.cat_expect <<-\EOF && + first: + 1st file + 2nd line 1st file + second: + 2nd file + EOF git reset --hard HEAD~2 && - check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e && + check_changes $head5p2 && test "$(git rev-parse ORIG_HEAD)" = \ $head4 ' ->.diff_expect -cat >.cached_expect <<EOF -diff --git a/first b/first -deleted file mode 100644 -index 8206c22..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 1bbba79..0000000 ---- a/second -+++ /dev/null -@@ -1 +0,0 @@ --2nd file -diff --git a/secondfile b/secondfile -new file mode 100644 -index 0000000..44c5b58 ---- /dev/null -+++ b/secondfile -@@ -0,0 +1,2 @@ -+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 \ - 'redoing changes adding them without commit them should succeed' ' +test_expect_success 'redoing changes adding them without commit them should succeed' ' + >.diff_expect && + cat >.cached_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 + diff --git a/secondfile b/secondfile + new file mode 100644 + index 0000000..$head5s + --- /dev/null + +++ b/secondfile + @@ -0,0 +1,2 @@ + +1st line 2nd file + +2nd line 2nd file + EOF + cat >.cat_expect <<-\EOF && + secondfile: + 1st line 2nd file + 2nd line 2nd file + EOF git rm first && git mv second secondfile && echo "1st line 2nd file" >secondfile && echo "2nd line 2nd file" >>secondfile && git add secondfile && - check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e + check_changes $head5p2 ' -cat >.diff_expect <<EOF -diff --git a/first b/first -deleted file mode 100644 -index 8206c22..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 1bbba79..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' ' + 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 && - check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e && - test "$(git rev-parse ORIG_HEAD)" = \ - ddaefe00f1da16864591c61fdc7adb5d7cd6b74e + check_changes $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' ' + >.diff_expect && + >.cached_expect && + cat >.cat_expect <<-\EOF && + secondfile: + 1st line 2nd file + 2nd line 2nd file + EOF git add secondfile && - git reset --hard ddaefe00f1da16864591c61fdc7adb5d7cd6b74e && - + git reset --hard $head5p2 && git rm first && git mv second secondfile && git commit -a -m "remove 1st and rename 2nd" && @@ -342,15 +339,15 @@ test_expect_success 'redoing the last two commits should succeed' ' 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' ' + >.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 branch2 && @@ -368,15 +365,14 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' ' check_changes $head3 ' ->.diff_expect ->.cached_expect -cat >.cat_expect <<EOF -secondfile: -1st line 2nd file -2nd line 2nd file -EOF -test_expect_success \ - '--hard reset to ORIG_HEAD should clear a fast-forward merge' ' +test_expect_success '--hard reset to ORIG_HEAD should clear a fast-forward merge' ' + >.diff_expect && + >.cached_expect && + cat >.cat_expect <<-\EOF && + secondfile: + 1st line 2nd file + 2nd line 2nd file + EOF git reset --hard HEAD^ && check_changes $head5 && @@ -389,52 +385,59 @@ test_expect_success \ check_changes $head5 ' -cat > expect << EOF -diff --git a/file1 b/file1 -index d00491f..7ed6ff8 100644 ---- a/file1 -+++ b/file1 -@@ -1 +1 @@ --1 -+5 -diff --git a/file2 b/file2 -deleted file mode 100644 -index 0cfbf08..0000000 ---- a/file2 -+++ /dev/null -@@ -1 +0,0 @@ --2 -EOF -cat > cached_expect << EOF -diff --git a/file4 b/file4 -new file mode 100644 -index 0000000..b8626c4 ---- /dev/null -+++ b/file4 -@@ -0,0 +1 @@ -+4 -EOF test_expect_success 'test --mixed <paths>' ' - echo 1 > file1 && - echo 2 > file2 && + echo 1 >file1 && + echo 2 >file2 && git add file1 file2 && test_tick && git commit -m files && + before1=$(git rev-parse --short HEAD:file1) && + before2=$(git rev-parse --short HEAD:file2) && git rm file2 && - echo 3 > file3 && - echo 4 > file4 && - echo 5 > file1 && + echo 3 >file3 && + echo 4 >file4 && + echo 5 >file1 && + after1=$(git rev-parse --short $(git hash-object file1)) && + after4=$(git rev-parse --short $(git hash-object file4)) && git add file1 file3 file4 && git reset HEAD -- file1 file2 file3 && test_must_fail git diff --quiet && - git diff > output && + git diff >output && + + cat >expect <<-EOF && + diff --git a/file1 b/file1 + index $before1..$after1 100644 + --- a/file1 + +++ b/file1 + @@ -1 +1 @@ + -1 + +5 + diff --git a/file2 b/file2 + deleted file mode 100644 + index $before2..0000000 + --- a/file2 + +++ /dev/null + @@ -1 +0,0 @@ + -2 + EOF + test_cmp expect output && - git diff --cached > output && + git diff --cached >output && + + cat >cached_expect <<-EOF && + diff --git a/file4 b/file4 + new file mode 100644 + index 0000000..$after4 + --- /dev/null + +++ b/file4 + @@ -0,0 +1 @@ + +4 + EOF + test_cmp cached_expect output ' test_expect_success 'test resetting the index at give paths' ' - mkdir sub && >sub/file1 && >sub/file2 && @@ -447,7 +450,6 @@ test_expect_success 'test resetting the index at give paths' ' echo "$U" && test_must_fail git diff-index --cached --exit-code "$T" && test "$T" != "$U" - ' test_expect_success 'resetting an unmodified path is a no-op' ' @@ -457,14 +459,13 @@ test_expect_success 'resetting an unmodified path is a no-op' ' git diff-index --cached --exit-code HEAD ' -cat > expect << EOF -Unstaged changes after reset: -M file2 -EOF - test_expect_success '--mixed refreshes the index' ' - echo 123 >> file2 && - git reset --mixed HEAD > output && + cat >expect <<-\EOF && + Unstaged changes after reset: + M file2 + EOF + echo 123 >>file2 && + git reset --mixed HEAD >output && test_i18ncmp expect output ' @@ -485,7 +486,6 @@ test_expect_success 'resetting specific path that is unmerged' ' ' test_expect_success 'disambiguation (1)' ' - git reset --hard && >secondfile && git add secondfile && @@ -494,11 +494,9 @@ test_expect_success 'disambiguation (1)' ' test -z "$(git diff --cached --name-only)" && test -f secondfile && test_must_be_empty secondfile - ' test_expect_success 'disambiguation (2)' ' - git reset --hard && >secondfile && git add secondfile && @@ -506,11 +504,9 @@ test_expect_success 'disambiguation (2)' ' test_must_fail git reset secondfile && test -n "$(git diff --cached --name-only -- secondfile)" && test ! -f secondfile - ' test_expect_success 'disambiguation (3)' ' - git reset --hard && >secondfile && git add secondfile && @@ -519,11 +515,9 @@ test_expect_success 'disambiguation (3)' ' test_must_fail git diff --quiet && test -z "$(git diff --cached --name-only)" && test ! -f secondfile - ' test_expect_success 'disambiguation (4)' ' - git reset --hard && >secondfile && git add secondfile && |