Imported Upstream version 2.17.0
[platform/upstream/git.git] / t / t7060-wtstatus.sh
index b8cb490..53cf42f 100755 (executable)
@@ -5,6 +5,7 @@ test_description='basic work tree status reporting'
 . ./test-lib.sh
 
 test_expect_success setup '
+       git config --global advice.statusuoption false &&
        test_commit A &&
        test_commit B oneside added &&
        git checkout A^0 &&
@@ -28,17 +29,20 @@ test_expect_success 'Report new path with conflict' '
        test_cmp expect actual
 '
 
-cat >expect <<EOF
-# On branch side
-# Unmerged paths:
-#   (use "git add/rm <file>..." as appropriate to mark resolution)
-#
-#      deleted by us:      foo
-#
+test_expect_success 'M/D conflict does not segfault' '
+       cat >expect <<EOF &&
+On branch side
+You have unmerged paths.
+  (fix conflicts and run "git commit")
+  (use "git merge --abort" to abort the merge)
+
+Unmerged paths:
+  (use "git add/rm <file>..." as appropriate to mark resolution)
+
+       deleted by us:   foo
+
 no changes added to commit (use "git add" and/or "git commit -a")
 EOF
-
-test_expect_success 'M/D conflict does not segfault' '
        mkdir mdconflict &&
        (
                cd mdconflict &&
@@ -103,7 +107,7 @@ test_expect_success 'git diff-index --cached -M shows 2 added + 1 unmerged' '
        A       THREE
        A       TWO
        EOF
-       git diff-index --cached --name-status HEAD >actual &&
+       git diff-index --cached -M --name-status HEAD >actual &&
        test_cmp expected actual
 '
 
@@ -118,4 +122,135 @@ test_expect_success 'git diff-index --cached -C shows 2 copies + 1 unmerged' '
        test_cmp expected actual
 '
 
+
+test_expect_success 'status when conflicts with add and rm advice (deleted by them)' '
+       git reset --hard &&
+       git checkout master &&
+       test_commit init main.txt init &&
+       git checkout -b second_branch &&
+       git rm main.txt &&
+       git commit -m "main.txt deleted on second_branch" &&
+       test_commit second conflict.txt second &&
+       git checkout master &&
+       test_commit on_second main.txt on_second &&
+       test_commit master conflict.txt master &&
+       test_must_fail git merge second_branch &&
+       cat >expected <<\EOF &&
+On branch master
+You have unmerged paths.
+  (fix conflicts and run "git commit")
+  (use "git merge --abort" to abort the merge)
+
+Unmerged paths:
+  (use "git add/rm <file>..." as appropriate to mark resolution)
+
+       both added:      conflict.txt
+       deleted by them: main.txt
+
+no changes added to commit (use "git add" and/or "git commit -a")
+EOF
+       git status --untracked-files=no >actual &&
+       test_i18ncmp expected actual
+'
+
+
+test_expect_success 'prepare for conflicts' '
+       git reset --hard &&
+       git checkout -b conflict &&
+       test_commit one main.txt one &&
+       git branch conflict_second &&
+       git mv main.txt sub_master.txt &&
+       git commit -m "main.txt renamed in sub_master.txt" &&
+       git checkout conflict_second &&
+       git mv main.txt sub_second.txt &&
+       git commit -m "main.txt renamed in sub_second.txt"
+'
+
+
+test_expect_success 'status when conflicts with add and rm advice (both deleted)' '
+       test_must_fail git merge conflict &&
+       cat >expected <<\EOF &&
+On branch conflict_second
+You have unmerged paths.
+  (fix conflicts and run "git commit")
+  (use "git merge --abort" to abort the merge)
+
+Unmerged paths:
+  (use "git add/rm <file>..." as appropriate to mark resolution)
+
+       both deleted:    main.txt
+       added by them:   sub_master.txt
+       added by us:     sub_second.txt
+
+no changes added to commit (use "git add" and/or "git commit -a")
+EOF
+       git status --untracked-files=no >actual &&
+       test_i18ncmp expected actual
+'
+
+
+test_expect_success 'status when conflicts with only rm advice (both deleted)' '
+       git reset --hard conflict_second &&
+       test_must_fail git merge conflict &&
+       git add sub_master.txt &&
+       git add sub_second.txt &&
+       cat >expected <<\EOF &&
+On branch conflict_second
+You have unmerged paths.
+  (fix conflicts and run "git commit")
+  (use "git merge --abort" to abort the merge)
+
+Changes to be committed:
+
+       new file:   sub_master.txt
+
+Unmerged paths:
+  (use "git rm <file>..." to mark resolution)
+
+       both deleted:    main.txt
+
+Untracked files not listed (use -u option to show untracked files)
+EOF
+       git status --untracked-files=no >actual &&
+       test_i18ncmp expected actual &&
+       git reset --hard &&
+       git checkout master
+'
+
+test_expect_success 'status --branch with detached HEAD' '
+       git reset --hard &&
+       git checkout master^0 &&
+       git status --branch --porcelain >actual &&
+       cat >expected <<-EOF &&
+       ## HEAD (no branch)
+       ?? .gitconfig
+       ?? actual
+       ?? expect
+       ?? expected
+       ?? mdconflict/
+       EOF
+       test_i18ncmp expected actual
+'
+
+## Duplicate the above test and verify --porcelain=v1 arg parsing.
+test_expect_success 'status --porcelain=v1 --branch with detached HEAD' '
+       git reset --hard &&
+       git checkout master^0 &&
+       git status --branch --porcelain=v1 >actual &&
+       cat >expected <<-EOF &&
+       ## HEAD (no branch)
+       ?? .gitconfig
+       ?? actual
+       ?? expect
+       ?? expected
+       ?? mdconflict/
+       EOF
+       test_i18ncmp expected actual
+'
+
+## Verify parser error on invalid --porcelain argument.
+test_expect_success 'status --porcelain=bogus' '
+       test_must_fail git status --porcelain=bogus
+'
+
 test_done