Imported Upstream version 2.19.4
[platform/upstream/git.git] / t / t9903-bash-prompt.sh
index 9150984..81a5179 100755 (executable)
@@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '
        git commit -m "another b2" file &&
        echo 000 >file &&
        git commit -m "yet another b2" file &&
+       mkdir ignored_dir &&
+       echo "ignored_dir/" >>.gitignore &&
        git checkout master
 '
 
@@ -61,18 +63,15 @@ test_expect_success 'prompt - unborn branch' '
        test_cmp expected "$actual"
 '
 
-repo_with_newline='repo
-with
-newline'
-
-if mkdir "$repo_with_newline" 2>/dev/null
-then
-       test_set_prereq FUNNYNAMES
-else
+if test_have_prereq !FUNNYNAMES; then
        say 'Your filesystem does not allow newlines in filenames.'
 fi
 
 test_expect_success FUNNYNAMES 'prompt - with newline in path' '
+    repo_with_newline="repo
+with
+newline" &&
+       mkdir "$repo_with_newline" &&
        printf " (master)" >expected &&
        git init "$repo_with_newline" &&
        test_when_finished "rm -rf \"$repo_with_newline\"" &&
@@ -105,7 +104,7 @@ test_expect_success 'prompt - describe detached head - contains' '
 '
 
 test_expect_success 'prompt - describe detached head - branch' '
-       printf " ((b1~1))" >expected &&
+       printf " ((tags/t2~1))" >expected &&
        git checkout b1^ &&
        test_when_finished "git checkout master" &&
        (
@@ -146,7 +145,7 @@ test_expect_success 'prompt - inside .git directory' '
 test_expect_success 'prompt - deep inside .git directory' '
        printf " (GIT_DIR!)" >expected &&
        (
-               cd .git/refs/heads &&
+               cd .git/objects &&
                __git_ps1 >"$actual"
        ) &&
        test_cmp expected "$actual"
@@ -164,7 +163,7 @@ test_expect_success 'prompt - inside bare repository' '
 '
 
 test_expect_success 'prompt - interactive rebase' '
-       printf " (b1|REBASE-i 2/3)" >expected
+       printf " (b1|REBASE-i 2/3)" >expected &&
        write_script fake_editor.sh <<-\EOF &&
                echo "exec echo" >"$1"
                echo "edit $(git log -1 --format="%h")" >>"$1"
@@ -175,7 +174,7 @@ test_expect_success 'prompt - interactive rebase' '
        git checkout b1 &&
        test_when_finished "git checkout master" &&
        git rebase -i HEAD^ &&
-       test_when_finished "git rebase --abort"
+       test_when_finished "git rebase --abort" &&
        __git_ps1 >"$actual" &&
        test_cmp expected "$actual"
 '
@@ -271,11 +270,36 @@ test_expect_success 'prompt - dirty status indicator - dirty index and worktree'
        test_cmp expected "$actual"
 '
 
-test_expect_success 'prompt - dirty status indicator - before root commit' '
-       printf " (master #)" >expected &&
+test_expect_success 'prompt - dirty status indicator - orphan branch - clean' '
+       printf " (orphan #)" >expected &&
+       test_when_finished "git checkout master" &&
+       git checkout --orphan orphan &&
+       git reset --hard &&
+       (
+               GIT_PS1_SHOWDIRTYSTATE=y &&
+               __git_ps1 >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index' '
+       printf " (orphan +)" >expected &&
+       test_when_finished "git checkout master" &&
+       git checkout --orphan orphan &&
+       (
+               GIT_PS1_SHOWDIRTYSTATE=y &&
+               __git_ps1 >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index and worktree' '
+       printf " (orphan *+)" >expected &&
+       test_when_finished "git checkout master" &&
+       git checkout --orphan orphan &&
+       >file &&
        (
                GIT_PS1_SHOWDIRTYSTATE=y &&
-               cd otherrepo &&
                __git_ps1 >"$actual"
        ) &&
        test_cmp expected "$actual"
@@ -395,6 +419,42 @@ test_expect_success 'prompt - untracked files status indicator - untracked files
        test_cmp expected "$actual"
 '
 
+test_expect_success 'prompt - untracked files status indicator - empty untracked dir' '
+       printf " (master)" >expected &&
+       mkdir otherrepo/untracked-dir &&
+       test_when_finished "rm -rf otherrepo/untracked-dir" &&
+       (
+               GIT_PS1_SHOWUNTRACKEDFILES=y &&
+               cd otherrepo &&
+               __git_ps1 >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - untracked files status indicator - non-empty untracked dir' '
+       printf " (master %%)" >expected &&
+       mkdir otherrepo/untracked-dir &&
+       test_when_finished "rm -rf otherrepo/untracked-dir" &&
+       >otherrepo/untracked-dir/untracked-file &&
+       (
+               GIT_PS1_SHOWUNTRACKEDFILES=y &&
+               cd otherrepo &&
+               __git_ps1 >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - untracked files status indicator - untracked files outside cwd' '
+       printf " (master %%)" >expected &&
+       (
+               mkdir -p ignored_dir &&
+               cd ignored_dir &&
+               GIT_PS1_SHOWUNTRACKEDFILES=y &&
+               __git_ps1 >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
 test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' '
        printf " (master)" >expected &&
        test_config bash.showUntrackedFiles false &&
@@ -453,10 +513,9 @@ test_expect_success 'prompt - format string starting with dash' '
 
 test_expect_success 'prompt - pc mode' '
        printf "BEFORE: (\${__git_ps1_branch_name}):AFTER\\nmaster" >expected &&
-       printf "" >expected_output &&
        (
                __git_ps1 "BEFORE:" ":AFTER" >"$actual" &&
-               test_cmp expected_output "$actual" &&
+               test_must_be_empty "$actual" &&
                printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
        ) &&
        test_cmp expected "$actual"
@@ -466,7 +525,7 @@ test_expect_success 'prompt - bash color pc mode - branch name' '
        printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nmaster" >expected &&
        (
                GIT_PS1_SHOWCOLORHINTS=y &&
-               __git_ps1 "BEFORE:" ":AFTER" >"$actual"
+               __git_ps1 "BEFORE:" ":AFTER" >"$actual" &&
                printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
        ) &&
        test_cmp expected "$actual"
@@ -588,4 +647,97 @@ test_expect_success 'prompt - zsh color pc mode' '
        test_cmp expected "$actual"
 '
 
+test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled' '
+       printf " (master)" >expected &&
+       test_config bash.hideIfPwdIgnored false &&
+       (
+               cd ignored_dir &&
+               __git_ps1 >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled, pc mode' '
+       printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
+       test_config bash.hideIfPwdIgnored false &&
+       (
+               cd ignored_dir &&
+               __git_ps1 "BEFORE:" ":AFTER" &&
+               printf "%s" "$PS1" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset' '
+       printf " (master)" >expected &&
+       (
+               cd ignored_dir &&
+               __git_ps1 >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset, pc mode' '
+       printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
+       (
+               cd ignored_dir &&
+               __git_ps1 "BEFORE:" ":AFTER" &&
+               printf "%s" "$PS1" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled' '
+       printf " (master)" >expected &&
+       test_config bash.hideIfPwdIgnored false &&
+       (
+               cd ignored_dir &&
+               GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+               __git_ps1 >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled, pc mode' '
+       printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
+       test_config bash.hideIfPwdIgnored false &&
+       (
+               cd ignored_dir &&
+               GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+               __git_ps1 "BEFORE:" ":AFTER" &&
+               printf "%s" "$PS1" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var set, config unset' '
+       (
+               cd ignored_dir &&
+               GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+               __git_ps1 >"$actual"
+       ) &&
+       test_must_be_empty "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var set, config unset, pc mode' '
+       printf "BEFORE::AFTER" >expected &&
+       (
+               cd ignored_dir &&
+               GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+               __git_ps1 "BEFORE:" ":AFTER" &&
+               printf "%s" "$PS1" >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - inside gitdir' '
+       printf " (GIT_DIR!)" >expected &&
+       (
+               GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+               cd .git &&
+               __git_ps1 >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
 test_done