Merge branch 'rs/strbuf-setlen-assert'
[gitweb.git] / t / t6022-merge-rename.sh
index 1f29c0a94d672d75b76743ba8a8edf1558401987..5f3b604fd99b22c73cfdebf0f1cf13539e1af3e4 100755 (executable)
@@ -99,245 +99,147 @@ git checkout master'
 
 test_expect_success 'pull renaming branch into unrenaming one' \
 '
-       git show-branch
-       git pull . white && {
-               echo "BAD: should have conflicted"
-               return 1
-       }
-       git ls-files -s
-       test "$(git ls-files -u B | wc -l)" -eq 3 || {
-               echo "BAD: should have left stages for B"
-               return 1
-       }
-       test "$(git ls-files -s N | wc -l)" -eq 1 || {
-               echo "BAD: should have merged N"
-               return 1
-       }
+       git show-branch &&
+       test_expect_code 1 git pull . white &&
+       git ls-files -s &&
+       git ls-files -u B >b.stages &&
+       test_line_count = 3 b.stages &&
+       git ls-files -s N >n.stages &&
+       test_line_count = 1 n.stages &&
        sed -ne "/^g/{
        p
        q
-       }" B | grep master || {
-               echo "BAD: should have listed our change first"
-               return 1
-       }
-       test "$(git diff white N | wc -l)" -eq 0 || {
-               echo "BAD: should have taken colored branch"
-               return 1
-       }
+       }" B | grep master &&
+       git diff --exit-code white N
 '
 
 test_expect_success 'pull renaming branch into another renaming one' \
 '
-       rm -f B
-       git reset --hard
-       git checkout red
-       git pull . white && {
-               echo "BAD: should have conflicted"
-               return 1
-       }
-       test "$(git ls-files -u B | wc -l)" -eq 3 || {
-               echo "BAD: should have left stages"
-               return 1
-       }
-       test "$(git ls-files -s N | wc -l)" -eq 1 || {
-               echo "BAD: should have merged N"
-               return 1
-       }
+       rm -f B &&
+       git reset --hard &&
+       git checkout red &&
+       test_expect_code 1 git pull . white &&
+       git ls-files -u B >b.stages &&
+       test_line_count = 3 b.stages &&
+       git ls-files -s N >n.stages &&
+       test_line_count = 1 n.stages &&
        sed -ne "/^g/{
        p
        q
-       }" B | grep red || {
-               echo "BAD: should have listed our change first"
-               return 1
-       }
-       test "$(git diff white N | wc -l)" -eq 0 || {
-               echo "BAD: should have taken colored branch"
-               return 1
-       }
+       }" B | grep red &&
+       git diff --exit-code white N
 '
 
 test_expect_success 'pull unrenaming branch into renaming one' \
 '
-       git reset --hard
-       git show-branch
-       git pull . master && {
-               echo "BAD: should have conflicted"
-               return 1
-       }
-       test "$(git ls-files -u B | wc -l)" -eq 3 || {
-               echo "BAD: should have left stages"
-               return 1
-       }
-       test "$(git ls-files -s N | wc -l)" -eq 1 || {
-               echo "BAD: should have merged N"
-               return 1
-       }
+       git reset --hard &&
+       git show-branch &&
+       test_expect_code 1 git pull . master &&
+       git ls-files -u B >b.stages &&
+       test_line_count = 3 b.stages &&
+       git ls-files -s N >n.stages &&
+       test_line_count = 1 n.stages &&
        sed -ne "/^g/{
        p
        q
-       }" B | grep red || {
-               echo "BAD: should have listed our change first"
-               return 1
-       }
-       test "$(git diff white N | wc -l)" -eq 0 || {
-               echo "BAD: should have taken colored branch"
-               return 1
-       }
+       }" B | grep red &&
+       git diff --exit-code white N
 '
 
 test_expect_success 'pull conflicting renames' \
 '
-       git reset --hard
-       git show-branch
-       git pull . blue && {
-               echo "BAD: should have conflicted"
-               return 1
-       }
-       test "$(git ls-files -u A | wc -l)" -eq 1 || {
-               echo "BAD: should have left a stage"
-               return 1
-       }
-       test "$(git ls-files -u B | wc -l)" -eq 1 || {
-               echo "BAD: should have left a stage"
-               return 1
-       }
-       test "$(git ls-files -u C | wc -l)" -eq 1 || {
-               echo "BAD: should have left a stage"
-               return 1
-       }
-       test "$(git ls-files -s N | wc -l)" -eq 1 || {
-               echo "BAD: should have merged N"
-               return 1
-       }
+       git reset --hard &&
+       git show-branch &&
+       test_expect_code 1 git pull . blue &&
+       git ls-files -u A >a.stages &&
+       test_line_count = 1 a.stages &&
+       git ls-files -u B >b.stages &&
+       test_line_count = 1 b.stages &&
+       git ls-files -u C >c.stages &&
+       test_line_count = 1 c.stages &&
+       git ls-files -s N >n.stages &&
+       test_line_count = 1 n.stages &&
        sed -ne "/^g/{
        p
        q
-       }" B | grep red || {
-               echo "BAD: should have listed our change first"
-               return 1
-       }
-       test "$(git diff white N | wc -l)" -eq 0 || {
-               echo "BAD: should have taken colored branch"
-               return 1
-       }
+       }" B | grep red &&
+       git diff --exit-code white N
 '
 
 test_expect_success 'interference with untracked working tree file' '
-
-       git reset --hard
-       git show-branch
-       echo >A this file should not matter
-       git pull . white && {
-               echo "BAD: should have conflicted"
-               return 1
-       }
-       test -f A || {
-               echo "BAD: should have left A intact"
-               return 1
-       }
+       git reset --hard &&
+       git show-branch &&
+       echo >A this file should not matter &&
+       test_expect_code 1 git pull . white &&
+       test_path_is_file A
 '
 
 test_expect_success 'interference with untracked working tree file' '
-
-       git reset --hard
-       git checkout white
-       git show-branch
-       rm -f A
-       echo >A this file should not matter
-       git pull . red && {
-               echo "BAD: should have conflicted"
-               return 1
-       }
-       test -f A || {
-               echo "BAD: should have left A intact"
-               return 1
-       }
+       git reset --hard &&
+       git checkout white &&
+       git show-branch &&
+       rm -f A &&
+       echo >A this file should not matter &&
+       test_expect_code 1 git pull . red &&
+       test_path_is_file A
 '
 
 test_expect_success 'interference with untracked working tree file' '
-
-       git reset --hard
-       rm -f A M
-       git checkout -f master
-       git tag -f anchor
-       git show-branch
-       git pull . yellow || {
-               echo "BAD: should have cleanly merged"
-               return 1
-       }
-       test -f M && {
-               echo "BAD: should have removed M"
-               return 1
-       }
+       git reset --hard &&
+       rm -f A M &&
+       git checkout -f master &&
+       git tag -f anchor &&
+       git show-branch &&
+       git pull . yellow &&
+       test_path_is_missing M &&
        git reset --hard anchor
 '
 
 test_expect_success 'updated working tree file should prevent the merge' '
-
-       git reset --hard
-       rm -f A M
-       git checkout -f master
-       git tag -f anchor
-       git show-branch
-       echo >>M one line addition
-       cat M >M.saved
-       git pull . yellow && {
-               echo "BAD: should have complained"
-               return 1
-       }
-       test_cmp M M.saved || {
-               echo "BAD: should have left M intact"
-               return 1
-       }
+       git reset --hard &&
+       rm -f A M &&
+       git checkout -f master &&
+       git tag -f anchor &&
+       git show-branch &&
+       echo >>M one line addition &&
+       cat M >M.saved &&
+       test_expect_code 128 git pull . yellow &&
+       test_cmp M M.saved &&
        rm -f M.saved
 '
 
 test_expect_success 'updated working tree file should prevent the merge' '
-
-       git reset --hard
-       rm -f A M
-       git checkout -f master
-       git tag -f anchor
-       git show-branch
-       echo >>M one line addition
-       cat M >M.saved
-       git update-index M
-       git pull . yellow && {
-               echo "BAD: should have complained"
-               return 1
-       }
-       test_cmp M M.saved || {
-               echo "BAD: should have left M intact"
-               return 1
-       }
+       git reset --hard &&
+       rm -f A M &&
+       git checkout -f master &&
+       git tag -f anchor &&
+       git show-branch &&
+       echo >>M one line addition &&
+       cat M >M.saved &&
+       git update-index M &&
+       test_expect_code 128 git pull . yellow &&
+       test_cmp M M.saved &&
        rm -f M.saved
 '
 
 test_expect_success 'interference with untracked working tree file' '
-
-       git reset --hard
-       rm -f A M
-       git checkout -f yellow
-       git tag -f anchor
-       git show-branch
-       echo >M this file should not matter
-       git pull . master || {
-               echo "BAD: should have cleanly merged"
-               return 1
-       }
-       test -f M || {
-               echo "BAD: should have left M intact"
-               return 1
-       }
-       git ls-files -s | grep M && {
-               echo "BAD: M must be untracked in the result"
-               return 1
-       }
+       git reset --hard &&
+       rm -f A M &&
+       git checkout -f yellow &&
+       git tag -f anchor &&
+       git show-branch &&
+       echo >M this file should not matter &&
+       git pull . master &&
+       test_path_is_file M &&
+       ! {
+               git ls-files -s |
+               grep M
+       } &&
        git reset --hard anchor
 '
 
 test_expect_success 'merge of identical changes in a renamed file' '
-       rm -f A M N
+       rm -f A M N &&
        git reset --hard &&
        git checkout change+rename &&
        GIT_MERGE_VERBOSITY=3 git merge change | grep "^Skipped B" &&
@@ -394,7 +296,7 @@ test_expect_success 'Rename+D/F conflict; renamed file merges + dir not in way'
        test_cmp expected dir
 '
 
-test_expect_failure 'Rename+D/F conflict; renamed file merges but dir in way' '
+test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '
        git reset --hard &&
        rm -rf dir~* &&
        git checkout -q renamed-file-has-no-conflicts^0 &&
@@ -404,8 +306,8 @@ test_expect_failure 'Rename+D/F conflict; renamed file merges but dir in way' '
        grep "Auto-merging dir" output &&
        grep "Adding as dir~HEAD instead" output &&
 
-       test 2 = "$(git ls-files -u | wc -l)" &&
-       test 2 = "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
+       test 2 -eq "$(git ls-files -u | wc -l)" &&
+       test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
 
        test_must_fail git diff --quiet &&
        test_must_fail git diff --cached --quiet &&
@@ -415,7 +317,7 @@ test_expect_failure 'Rename+D/F conflict; renamed file merges but dir in way' '
        test_cmp expected dir~HEAD
 '
 
-test_expect_failure 'Same as previous, but merged other way' '
+test_expect_success 'Same as previous, but merged other way' '
        git reset --hard &&
        rm -rf dir~* &&
        git checkout -q dir-in-way^0 &&
@@ -426,8 +328,8 @@ test_expect_failure 'Same as previous, but merged other way' '
        grep "Auto-merging dir" output &&
        grep "Adding as dir~renamed-file-has-no-conflicts instead" output &&
 
-       test 2 = "$(git ls-files -u | wc -l)" &&
-       test 2 = "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
+       test 2 -eq "$(git ls-files -u | wc -l)" &&
+       test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
 
        test_must_fail git diff --quiet &&
        test_must_fail git diff --cached --quiet &&
@@ -455,14 +357,14 @@ cat >expected <<\EOF &&
 >>>>>>> dir-not-in-way
 EOF
 
-test_expect_failure 'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
+test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
        git reset --hard &&
        rm -rf dir~* &&
        git checkout -q renamed-file-has-conflicts^0 &&
        test_must_fail git merge --strategy=recursive dir-not-in-way &&
 
-       test 3 = "$(git ls-files -u | wc -l)" &&
-       test 3 = "$(git ls-files -u dir | wc -l)" &&
+       test 3 -eq "$(git ls-files -u | wc -l)" &&
+       test 3 -eq "$(git ls-files -u dir | wc -l)" &&
 
        test_must_fail git diff --quiet &&
        test_must_fail git diff --cached --quiet &&
@@ -471,7 +373,7 @@ test_expect_failure 'Rename+D/F conflict; renamed file cannot merge, dir not in
        test_cmp expected dir
 '
 
-test_expect_failure 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
+test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
        modify s/dir-not-in-way/dir-in-way/ expected &&
 
        git reset --hard &&
@@ -479,9 +381,9 @@ test_expect_failure 'Rename+D/F conflict; renamed file cannot merge and dir in t
        git checkout -q renamed-file-has-conflicts^0 &&
        test_must_fail git merge --strategy=recursive dir-in-way &&
 
-       test 5 = "$(git ls-files -u | wc -l)" &&
-       test 3 = "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
-       test 2 = "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
+       test 5 -eq "$(git ls-files -u | wc -l)" &&
+       test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
+       test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
 
        test_must_fail git diff --quiet &&
        test_must_fail git diff --cached --quiet &&
@@ -509,15 +411,15 @@ cat >expected <<\EOF &&
 >>>>>>> renamed-file-has-conflicts
 EOF
 
-test_expect_failure 'Same as previous, but merged other way' '
+test_expect_success 'Same as previous, but merged other way' '
        git reset --hard &&
        rm -rf dir~* &&
        git checkout -q dir-in-way^0 &&
        test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
 
-       test 5 = "$(git ls-files -u | wc -l)" &&
-       test 3 = "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
-       test 2 = "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
+       test 5 -eq "$(git ls-files -u | wc -l)" &&
+       test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
+       test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
 
        test_must_fail git diff --quiet &&
        test_must_fail git diff --cached --quiet &&
@@ -549,13 +451,13 @@ test_expect_success 'setup both rename source and destination involved in D/F co
        git commit -m "Conflicts in the way"
 '
 
-test_expect_failure 'both rename source and destination involved in D/F conflict' '
+test_expect_success 'both rename source and destination involved in D/F conflict' '
        git reset --hard &&
        rm -rf dir~* &&
        git checkout -q rename-dest^0 &&
        test_must_fail git merge --strategy=recursive source-conflict &&
 
-       test 1 = "$(git ls-files -u | wc -l)" &&
+       test 1 -eq "$(git ls-files -u | wc -l)" &&
 
        test_must_fail git diff --quiet &&
 
@@ -589,18 +491,18 @@ test_expect_success 'setup pair rename to parent of other (D/F conflicts)' '
        git commit -m "Rename one/file -> two"
 '
 
-test_expect_failure 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
+test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
        git checkout -q rename-one^0 &&
        mkdir one &&
        test_must_fail git merge --strategy=recursive rename-two &&
 
-       test 2 = "$(git ls-files -u | wc -l)" &&
-       test 1 = "$(git ls-files -u one | wc -l)" &&
-       test 1 = "$(git ls-files -u two | wc -l)" &&
+       test 2 -eq "$(git ls-files -u | wc -l)" &&
+       test 1 -eq "$(git ls-files -u one | wc -l)" &&
+       test 1 -eq "$(git ls-files -u two | wc -l)" &&
 
        test_must_fail git diff --quiet &&
 
-       test 4 = $(find . | grep -v .git | wc -l) &&
+       test 4 -eq $(find . | grep -v .git | wc -l) &&
 
        test -d one &&
        test -f one~rename-two &&
@@ -614,13 +516,13 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean sta
        git clean -fdqx &&
        test_must_fail git merge --strategy=recursive rename-two &&
 
-       test 2 = "$(git ls-files -u | wc -l)" &&
-       test 1 = "$(git ls-files -u one | wc -l)" &&
-       test 1 = "$(git ls-files -u two | wc -l)" &&
+       test 2 -eq "$(git ls-files -u | wc -l)" &&
+       test 1 -eq "$(git ls-files -u one | wc -l)" &&
+       test 1 -eq "$(git ls-files -u two | wc -l)" &&
 
        test_must_fail git diff --quiet &&
 
-       test 3 = $(find . | grep -v .git | wc -l) &&
+       test 3 -eq $(find . | grep -v .git | wc -l) &&
 
        test -f one &&
        test -f two &&
@@ -656,12 +558,12 @@ test_expect_success 'check handling of differently renamed file with D/F conflic
        git checkout -q first-rename^0 &&
        test_must_fail git merge --strategy=recursive second-rename &&
 
-       test 5 = "$(git ls-files -s | wc -l)" &&
-       test 3 = "$(git ls-files -u | wc -l)" &&
-       test 1 = "$(git ls-files -u one | wc -l)" &&
-       test 1 = "$(git ls-files -u two | wc -l)" &&
-       test 1 = "$(git ls-files -u original | wc -l)" &&
-       test 2 = "$(git ls-files -o | wc -l)" &&
+       test 5 -eq "$(git ls-files -s | wc -l)" &&
+       test 3 -eq "$(git ls-files -u | wc -l)" &&
+       test 1 -eq "$(git ls-files -u one | wc -l)" &&
+       test 1 -eq "$(git ls-files -u two | wc -l)" &&
+       test 1 -eq "$(git ls-files -u original | wc -l)" &&
+       test 2 -eq "$(git ls-files -o | wc -l)" &&
 
        test -f one/file &&
        test -f two/file &&
@@ -692,19 +594,82 @@ test_expect_success 'setup rename one file to two; directories moving out of the
        git commit -m "Rename to two"
 '
 
-test_expect_failure 'check handling of differently renamed file with D/F conflicts' '
+test_expect_success 'check handling of differently renamed file with D/F conflicts' '
        git checkout -q first-rename-redo^0 &&
        test_must_fail git merge --strategy=recursive second-rename-redo &&
 
-       test 3 = "$(git ls-files -u | wc -l)" &&
-       test 1 = "$(git ls-files -u one | wc -l)" &&
-       test 1 = "$(git ls-files -u two | wc -l)" &&
-       test 1 = "$(git ls-files -u original | wc -l)" &&
-       test 0 = "$(git ls-files -o | wc -l)" &&
+       test 3 -eq "$(git ls-files -u | wc -l)" &&
+       test 1 -eq "$(git ls-files -u one | wc -l)" &&
+       test 1 -eq "$(git ls-files -u two | wc -l)" &&
+       test 1 -eq "$(git ls-files -u original | wc -l)" &&
+       test 0 -eq "$(git ls-files -o | wc -l)" &&
 
        test -f one &&
        test -f two &&
        ! test -f original
 '
 
+test_expect_success 'setup avoid unnecessary update, normal rename' '
+       git reset --hard &&
+       git checkout --orphan avoid-unnecessary-update-1 &&
+       git rm -rf . &&
+       git clean -fdqx &&
+
+       printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
+       git add -A &&
+       git commit -m "Common commmit" &&
+
+       git mv original rename &&
+       echo 11 >>rename &&
+       git add -u &&
+       git commit -m "Renamed and modified" &&
+
+       git checkout -b merge-branch-1 HEAD~1 &&
+       echo "random content" >random-file &&
+       git add -A &&
+       git commit -m "Random, unrelated changes"
+'
+
+test_expect_success 'avoid unnecessary update, normal rename' '
+       git checkout -q avoid-unnecessary-update-1^0 &&
+       test-chmtime =1000000000 rename &&
+       test-chmtime -v +0 rename >expect &&
+       git merge merge-branch-1 &&
+       test-chmtime -v +0 rename >actual &&
+       test_cmp expect actual # "rename" should have stayed intact
+'
+
+test_expect_success 'setup to test avoiding unnecessary update, with D/F conflict' '
+       git reset --hard &&
+       git checkout --orphan avoid-unnecessary-update-2 &&
+       git rm -rf . &&
+       git clean -fdqx &&
+
+       mkdir df &&
+       printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
+       git add -A &&
+       git commit -m "Common commmit" &&
+
+       git mv df/file temp &&
+       rm -rf df &&
+       git mv temp df &&
+       echo 11 >>df &&
+       git add -u &&
+       git commit -m "Renamed and modified" &&
+
+       git checkout -b merge-branch-2 HEAD~1 &&
+       >unrelated-change &&
+       git add unrelated-change &&
+       git commit -m "Only unrelated changes"
+'
+
+test_expect_failure 'avoid unnecessary update, with D/F conflict' '
+       git checkout -q avoid-unnecessary-update-2^0 &&
+       test-chmtime =1000000000 df &&
+       test-chmtime -v +0 df >expect &&
+       git merge merge-branch-2 &&
+       test-chmtime -v +0 df >actual &&
+       test_cmp expect actual # "df" should have stayed intact
+'
+
 test_done