SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2012 SZEDER Gábor |
| 4 | # |
| 5 | |
| 6 | test_description='test git-specific bash prompt functions' |
| 7 | |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 10 | |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 11 | . ./lib-bash.sh |
| 12 | |
Felipe Contreras | af31a45 | 2012-05-22 22:46:40 +0200 | [diff] [blame] | 13 | . "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 14 | |
| 15 | actual="$TRASH_DIRECTORY/actual" |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 16 | c_red='\\[\\e[31m\\]' |
| 17 | c_green='\\[\\e[32m\\]' |
| 18 | c_lblue='\\[\\e[1;34m\\]' |
| 19 | c_clear='\\[\\e[0m\\]' |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 20 | |
| 21 | test_expect_success 'setup for prompt tests' ' |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 22 | git init otherrepo && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 23 | echo 1 >file && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 24 | git add file && |
| 25 | test_tick && |
| 26 | git commit -m initial && |
| 27 | git tag -a -m msg1 t1 && |
| 28 | git checkout -b b1 && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 29 | echo 2 >file && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 30 | git commit -m "second b1" file && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 31 | echo 3 >file && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 32 | git commit -m "third b1" file && |
| 33 | git tag -a -m msg2 t2 && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 34 | git checkout -b b2 main && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 35 | echo 0 >file && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 36 | git commit -m "second b2" file && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 37 | echo 00 >file && |
Zoltan Klinger | b71dc3e | 2013-04-25 19:28:54 +1000 | [diff] [blame] | 38 | git commit -m "another b2" file && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 39 | echo 000 >file && |
Zoltan Klinger | b71dc3e | 2013-04-25 19:28:54 +1000 | [diff] [blame] | 40 | git commit -m "yet another b2" file && |
Jess Austin | 0120b8c | 2015-01-06 20:22:27 -0500 | [diff] [blame] | 41 | mkdir ignored_dir && |
| 42 | echo "ignored_dir/" >>.gitignore && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 43 | git checkout main |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 44 | ' |
| 45 | |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 46 | test_expect_success 'prompt - branch name' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 47 | printf " (main)" >expected && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 48 | __git_ps1 >"$actual" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 49 | test_cmp expected "$actual" |
| 50 | ' |
| 51 | |
SZEDER Gábor | 868dc1a | 2012-08-24 19:52:48 +0200 | [diff] [blame] | 52 | test_expect_success SYMLINKS 'prompt - branch name - symlink symref' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 53 | printf " (main)" >expected && |
| 54 | test_when_finished "git checkout main" && |
SZEDER Gábor | 868dc1a | 2012-08-24 19:52:48 +0200 | [diff] [blame] | 55 | test_config core.preferSymlinkRefs true && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 56 | git checkout main && |
SZEDER Gábor | 868dc1a | 2012-08-24 19:52:48 +0200 | [diff] [blame] | 57 | __git_ps1 >"$actual" && |
| 58 | test_cmp expected "$actual" |
| 59 | ' |
| 60 | |
SZEDER Gábor | e3e0b93 | 2013-06-24 02:16:02 +0200 | [diff] [blame] | 61 | test_expect_success 'prompt - unborn branch' ' |
| 62 | printf " (unborn)" >expected && |
| 63 | git checkout --orphan unborn && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 64 | test_when_finished "git checkout main" && |
SZEDER Gábor | e3e0b93 | 2013-06-24 02:16:02 +0200 | [diff] [blame] | 65 | __git_ps1 >"$actual" && |
| 66 | test_cmp expected "$actual" |
| 67 | ' |
| 68 | |
William Chargin | 6ec6330 | 2018-08-06 11:35:08 -0700 | [diff] [blame] | 69 | if test_have_prereq !FUNNYNAMES; then |
SZEDER Gábor | a4889e6 | 2013-08-17 11:01:58 +0200 | [diff] [blame] | 70 | say 'Your filesystem does not allow newlines in filenames.' |
| 71 | fi |
| 72 | |
| 73 | test_expect_success FUNNYNAMES 'prompt - with newline in path' ' |
William Chargin | 6ec6330 | 2018-08-06 11:35:08 -0700 | [diff] [blame] | 74 | repo_with_newline="repo |
| 75 | with |
| 76 | newline" && |
| 77 | mkdir "$repo_with_newline" && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 78 | printf " (main)" >expected && |
SZEDER Gábor | a4889e6 | 2013-08-17 11:01:58 +0200 | [diff] [blame] | 79 | git init "$repo_with_newline" && |
| 80 | test_when_finished "rm -rf \"$repo_with_newline\"" && |
| 81 | mkdir "$repo_with_newline"/subdir && |
| 82 | ( |
| 83 | cd "$repo_with_newline/subdir" && |
| 84 | __git_ps1 >"$actual" |
| 85 | ) && |
| 86 | test_cmp expected "$actual" |
| 87 | ' |
| 88 | |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 89 | test_expect_success 'prompt - detached head' ' |
SZEDER Gábor | e8f21ca | 2013-06-24 01:55:42 +0200 | [diff] [blame] | 90 | printf " ((%s...))" $(git log -1 --format="%h" --abbrev=13 b1^) >expected && |
| 91 | test_config core.abbrev 13 && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 92 | git checkout b1^ && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 93 | test_when_finished "git checkout main" && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 94 | __git_ps1 >"$actual" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 95 | test_cmp expected "$actual" |
| 96 | ' |
| 97 | |
| 98 | test_expect_success 'prompt - describe detached head - contains' ' |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 99 | printf " ((t2~1))" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 100 | git checkout b1^ && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 101 | test_when_finished "git checkout main" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 102 | ( |
| 103 | GIT_PS1_DESCRIBE_STYLE=contains && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 104 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 105 | ) && |
| 106 | test_cmp expected "$actual" |
| 107 | ' |
| 108 | |
| 109 | test_expect_success 'prompt - describe detached head - branch' ' |
Johannes Schindelin | 7550424 | 2016-04-22 15:39:01 +0200 | [diff] [blame] | 110 | printf " ((tags/t2~1))" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 111 | git checkout b1^ && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 112 | test_when_finished "git checkout main" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 113 | ( |
| 114 | GIT_PS1_DESCRIBE_STYLE=branch && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 115 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 116 | ) && |
| 117 | test_cmp expected "$actual" |
| 118 | ' |
| 119 | |
| 120 | test_expect_success 'prompt - describe detached head - describe' ' |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 121 | printf " ((t1-1-g%s))" $(git log -1 --format="%h" b1^) >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 122 | git checkout b1^ && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 123 | test_when_finished "git checkout main" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 124 | ( |
| 125 | GIT_PS1_DESCRIBE_STYLE=describe && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 126 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 127 | ) && |
| 128 | test_cmp expected "$actual" |
| 129 | ' |
| 130 | |
| 131 | test_expect_success 'prompt - describe detached head - default' ' |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 132 | printf " ((t2))" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 133 | git checkout --detach b1 && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 134 | test_when_finished "git checkout main" && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 135 | __git_ps1 >"$actual" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 136 | test_cmp expected "$actual" |
| 137 | ' |
| 138 | |
| 139 | test_expect_success 'prompt - inside .git directory' ' |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 140 | printf " (GIT_DIR!)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 141 | ( |
| 142 | cd .git && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 143 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 144 | ) && |
| 145 | test_cmp expected "$actual" |
| 146 | ' |
| 147 | |
| 148 | test_expect_success 'prompt - deep inside .git directory' ' |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 149 | printf " (GIT_DIR!)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 150 | ( |
Christian Couder | 5340d47 | 2018-05-26 08:47:45 +0200 | [diff] [blame] | 151 | cd .git/objects && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 152 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 153 | ) && |
| 154 | test_cmp expected "$actual" |
| 155 | ' |
| 156 | |
| 157 | test_expect_success 'prompt - inside bare repository' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 158 | printf " (BARE:main)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 159 | git init --bare bare.git && |
| 160 | test_when_finished "rm -rf bare.git" && |
| 161 | ( |
| 162 | cd bare.git && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 163 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 164 | ) && |
| 165 | test_cmp expected "$actual" |
| 166 | ' |
| 167 | |
| 168 | test_expect_success 'prompt - interactive rebase' ' |
Elijah Newren | 6d04ce7 | 2020-02-15 21:36:35 +0000 | [diff] [blame] | 169 | printf " (b1|REBASE 2/3)" >expected && |
SZEDER Gábor | 7412290 | 2012-08-24 20:03:58 +0200 | [diff] [blame] | 170 | write_script fake_editor.sh <<-\EOF && |
| 171 | echo "exec echo" >"$1" |
| 172 | echo "edit $(git log -1 --format="%h")" >>"$1" |
| 173 | echo "exec echo" >>"$1" |
| 174 | EOF |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 175 | test_when_finished "rm -f fake_editor.sh" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 176 | test_set_editor "$TRASH_DIRECTORY/fake_editor.sh" && |
| 177 | git checkout b1 && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 178 | test_when_finished "git checkout main" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 179 | git rebase -i HEAD^ && |
Johannes Sixt | c00bfc9 | 2016-09-05 21:00:47 +0200 | [diff] [blame] | 180 | test_when_finished "git rebase --abort" && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 181 | __git_ps1 >"$actual" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 182 | test_cmp expected "$actual" |
| 183 | ' |
| 184 | |
| 185 | test_expect_success 'prompt - rebase merge' ' |
Elijah Newren | 6d04ce7 | 2020-02-15 21:36:35 +0000 | [diff] [blame] | 186 | printf " (b2|REBASE 1/3)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 187 | git checkout b2 && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 188 | test_when_finished "git checkout main" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 189 | test_must_fail git rebase --merge b1 b2 && |
| 190 | test_when_finished "git rebase --abort" && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 191 | __git_ps1 >"$actual" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 192 | test_cmp expected "$actual" |
| 193 | ' |
| 194 | |
Elijah Newren | 6d04ce7 | 2020-02-15 21:36:35 +0000 | [diff] [blame] | 195 | test_expect_success 'prompt - rebase am' ' |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 196 | printf " (b2|REBASE 1/3)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 197 | git checkout b2 && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 198 | test_when_finished "git checkout main" && |
Elijah Newren | 10cdb9f | 2020-02-15 21:36:41 +0000 | [diff] [blame] | 199 | test_must_fail git rebase --apply b1 b2 && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 200 | test_when_finished "git rebase --abort" && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 201 | __git_ps1 >"$actual" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 202 | test_cmp expected "$actual" |
| 203 | ' |
| 204 | |
| 205 | test_expect_success 'prompt - merge' ' |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 206 | printf " (b1|MERGING)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 207 | git checkout b1 && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 208 | test_when_finished "git checkout main" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 209 | test_must_fail git merge b2 && |
| 210 | test_when_finished "git reset --hard" && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 211 | __git_ps1 >"$actual" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 212 | test_cmp expected "$actual" |
| 213 | ' |
| 214 | |
| 215 | test_expect_success 'prompt - cherry-pick' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 216 | printf " (main|CHERRY-PICKING)" >expected && |
Phillip Wood | e981bf7 | 2019-07-01 07:21:06 -0700 | [diff] [blame] | 217 | test_must_fail git cherry-pick b1 b1^ && |
| 218 | test_when_finished "git cherry-pick --abort" && |
| 219 | __git_ps1 >"$actual" && |
| 220 | test_cmp expected "$actual" && |
| 221 | git reset --merge && |
| 222 | test_must_fail git rev-parse CHERRY_PICK_HEAD && |
| 223 | __git_ps1 >"$actual" && |
| 224 | test_cmp expected "$actual" |
| 225 | ' |
| 226 | |
| 227 | test_expect_success 'prompt - revert' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 228 | printf " (main|REVERTING)" >expected && |
Phillip Wood | e981bf7 | 2019-07-01 07:21:06 -0700 | [diff] [blame] | 229 | test_must_fail git revert b1^ b1 && |
| 230 | test_when_finished "git revert --abort" && |
| 231 | __git_ps1 >"$actual" && |
| 232 | test_cmp expected "$actual" && |
| 233 | git reset --merge && |
| 234 | test_must_fail git rev-parse REVERT_HEAD && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 235 | __git_ps1 >"$actual" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 236 | test_cmp expected "$actual" |
| 237 | ' |
| 238 | |
| 239 | test_expect_success 'prompt - bisect' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 240 | printf " (main|BISECTING)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 241 | git bisect start && |
| 242 | test_when_finished "git bisect reset" && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 243 | __git_ps1 >"$actual" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 244 | test_cmp expected "$actual" |
| 245 | ' |
| 246 | |
| 247 | test_expect_success 'prompt - dirty status indicator - clean' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 248 | printf " (main)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 249 | ( |
| 250 | GIT_PS1_SHOWDIRTYSTATE=y && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 251 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 252 | ) && |
| 253 | test_cmp expected "$actual" |
| 254 | ' |
| 255 | |
| 256 | test_expect_success 'prompt - dirty status indicator - dirty worktree' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 257 | printf " (main *)" >expected && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 258 | echo "dirty" >file && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 259 | test_when_finished "git reset --hard" && |
| 260 | ( |
| 261 | GIT_PS1_SHOWDIRTYSTATE=y && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 262 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 263 | ) && |
| 264 | test_cmp expected "$actual" |
| 265 | ' |
| 266 | |
| 267 | test_expect_success 'prompt - dirty status indicator - dirty index' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 268 | printf " (main +)" >expected && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 269 | echo "dirty" >file && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 270 | test_when_finished "git reset --hard" && |
| 271 | git add -u && |
| 272 | ( |
| 273 | GIT_PS1_SHOWDIRTYSTATE=y && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 274 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 275 | ) && |
| 276 | test_cmp expected "$actual" |
| 277 | ' |
| 278 | |
| 279 | test_expect_success 'prompt - dirty status indicator - dirty index and worktree' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 280 | printf " (main *+)" >expected && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 281 | echo "dirty index" >file && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 282 | test_when_finished "git reset --hard" && |
| 283 | git add -u && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 284 | echo "dirty worktree" >file && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 285 | ( |
| 286 | GIT_PS1_SHOWDIRTYSTATE=y && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 287 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 288 | ) && |
| 289 | test_cmp expected "$actual" |
| 290 | ' |
| 291 | |
SZEDER Gábor | a30d11e | 2015-11-21 12:30:07 +0100 | [diff] [blame] | 292 | test_expect_success 'prompt - dirty status indicator - orphan branch - clean' ' |
| 293 | printf " (orphan #)" >expected && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 294 | test_when_finished "git checkout main" && |
SZEDER Gábor | a30d11e | 2015-11-21 12:30:07 +0100 | [diff] [blame] | 295 | git checkout --orphan orphan && |
| 296 | git reset --hard && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 297 | ( |
| 298 | GIT_PS1_SHOWDIRTYSTATE=y && |
SZEDER Gábor | a30d11e | 2015-11-21 12:30:07 +0100 | [diff] [blame] | 299 | __git_ps1 >"$actual" |
| 300 | ) && |
| 301 | test_cmp expected "$actual" |
| 302 | ' |
| 303 | |
SZEDER Gábor | c26f70c | 2015-11-21 12:30:09 +0100 | [diff] [blame] | 304 | test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index' ' |
SZEDER Gábor | a30d11e | 2015-11-21 12:30:07 +0100 | [diff] [blame] | 305 | printf " (orphan +)" >expected && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 306 | test_when_finished "git checkout main" && |
SZEDER Gábor | a30d11e | 2015-11-21 12:30:07 +0100 | [diff] [blame] | 307 | git checkout --orphan orphan && |
| 308 | ( |
| 309 | GIT_PS1_SHOWDIRTYSTATE=y && |
| 310 | __git_ps1 >"$actual" |
| 311 | ) && |
| 312 | test_cmp expected "$actual" |
| 313 | ' |
| 314 | |
SZEDER Gábor | c26f70c | 2015-11-21 12:30:09 +0100 | [diff] [blame] | 315 | test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index and worktree' ' |
SZEDER Gábor | a30d11e | 2015-11-21 12:30:07 +0100 | [diff] [blame] | 316 | printf " (orphan *+)" >expected && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 317 | test_when_finished "git checkout main" && |
SZEDER Gábor | a30d11e | 2015-11-21 12:30:07 +0100 | [diff] [blame] | 318 | git checkout --orphan orphan && |
| 319 | >file && |
| 320 | ( |
| 321 | GIT_PS1_SHOWDIRTYSTATE=y && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 322 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 323 | ) && |
| 324 | test_cmp expected "$actual" |
| 325 | ' |
| 326 | |
Martin Erik Werner | dc7e7bc | 2013-02-13 21:58:19 +0100 | [diff] [blame] | 327 | test_expect_success 'prompt - dirty status indicator - shell variable unset with config disabled' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 328 | printf " (main)" >expected && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 329 | echo "dirty" >file && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 330 | test_when_finished "git reset --hard" && |
| 331 | test_config bash.showDirtyState false && |
| 332 | ( |
Martin Erik Werner | dc7e7bc | 2013-02-13 21:58:19 +0100 | [diff] [blame] | 333 | sane_unset GIT_PS1_SHOWDIRTYSTATE && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 334 | __git_ps1 >"$actual" |
Martin Erik Werner | dc7e7bc | 2013-02-13 21:58:19 +0100 | [diff] [blame] | 335 | ) && |
| 336 | test_cmp expected "$actual" |
| 337 | ' |
| 338 | |
| 339 | test_expect_success 'prompt - dirty status indicator - shell variable unset with config enabled' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 340 | printf " (main)" >expected && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 341 | echo "dirty" >file && |
Martin Erik Werner | dc7e7bc | 2013-02-13 21:58:19 +0100 | [diff] [blame] | 342 | test_when_finished "git reset --hard" && |
| 343 | test_config bash.showDirtyState true && |
| 344 | ( |
| 345 | sane_unset GIT_PS1_SHOWDIRTYSTATE && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 346 | __git_ps1 >"$actual" |
Martin Erik Werner | dc7e7bc | 2013-02-13 21:58:19 +0100 | [diff] [blame] | 347 | ) && |
| 348 | test_cmp expected "$actual" |
| 349 | ' |
| 350 | |
| 351 | test_expect_success 'prompt - dirty status indicator - shell variable set with config disabled' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 352 | printf " (main)" >expected && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 353 | echo "dirty" >file && |
Martin Erik Werner | dc7e7bc | 2013-02-13 21:58:19 +0100 | [diff] [blame] | 354 | test_when_finished "git reset --hard" && |
| 355 | test_config bash.showDirtyState false && |
| 356 | ( |
| 357 | GIT_PS1_SHOWDIRTYSTATE=y && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 358 | __git_ps1 >"$actual" |
Martin Erik Werner | dc7e7bc | 2013-02-13 21:58:19 +0100 | [diff] [blame] | 359 | ) && |
| 360 | test_cmp expected "$actual" |
| 361 | ' |
| 362 | |
| 363 | test_expect_success 'prompt - dirty status indicator - shell variable set with config enabled' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 364 | printf " (main *)" >expected && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 365 | echo "dirty" >file && |
Martin Erik Werner | dc7e7bc | 2013-02-13 21:58:19 +0100 | [diff] [blame] | 366 | test_when_finished "git reset --hard" && |
| 367 | test_config bash.showDirtyState true && |
| 368 | ( |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 369 | GIT_PS1_SHOWDIRTYSTATE=y && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 370 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 371 | ) && |
| 372 | test_cmp expected "$actual" |
| 373 | ' |
| 374 | |
| 375 | test_expect_success 'prompt - dirty status indicator - not shown inside .git directory' ' |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 376 | printf " (GIT_DIR!)" >expected && |
| 377 | echo "dirty" >file && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 378 | test_when_finished "git reset --hard" && |
| 379 | ( |
| 380 | GIT_PS1_SHOWDIRTYSTATE=y && |
| 381 | cd .git && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 382 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 383 | ) && |
| 384 | test_cmp expected "$actual" |
| 385 | ' |
| 386 | |
| 387 | test_expect_success 'prompt - stash status indicator - no stash' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 388 | printf " (main)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 389 | ( |
| 390 | GIT_PS1_SHOWSTASHSTATE=y && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 391 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 392 | ) && |
| 393 | test_cmp expected "$actual" |
| 394 | ' |
| 395 | |
| 396 | test_expect_success 'prompt - stash status indicator - stash' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 397 | printf " (main $)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 398 | echo 2 >file && |
| 399 | git stash && |
| 400 | test_when_finished "git stash drop" && |
SZEDER Gábor | dd0b72c | 2011-04-01 17:47:37 +0200 | [diff] [blame] | 401 | git pack-refs --all && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 402 | ( |
| 403 | GIT_PS1_SHOWSTASHSTATE=y && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 404 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 405 | ) && |
| 406 | test_cmp expected "$actual" |
| 407 | ' |
| 408 | |
| 409 | test_expect_success 'prompt - stash status indicator - not shown inside .git directory' ' |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 410 | printf " (GIT_DIR!)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 411 | echo 2 >file && |
| 412 | git stash && |
| 413 | test_when_finished "git stash drop" && |
| 414 | ( |
| 415 | GIT_PS1_SHOWSTASHSTATE=y && |
| 416 | cd .git && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 417 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 418 | ) && |
| 419 | test_cmp expected "$actual" |
| 420 | ' |
| 421 | |
| 422 | test_expect_success 'prompt - untracked files status indicator - no untracked files' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 423 | printf " (main)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 424 | ( |
| 425 | GIT_PS1_SHOWUNTRACKEDFILES=y && |
| 426 | cd otherrepo && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 427 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 428 | ) && |
| 429 | test_cmp expected "$actual" |
| 430 | ' |
| 431 | |
| 432 | test_expect_success 'prompt - untracked files status indicator - untracked files' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 433 | printf " (main %%)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 434 | ( |
| 435 | GIT_PS1_SHOWUNTRACKEDFILES=y && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 436 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 437 | ) && |
| 438 | test_cmp expected "$actual" |
| 439 | ' |
| 440 | |
SZEDER Gábor | 6bfab99 | 2015-07-19 13:28:05 +0200 | [diff] [blame] | 441 | test_expect_success 'prompt - untracked files status indicator - empty untracked dir' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 442 | printf " (main)" >expected && |
SZEDER Gábor | 6bfab99 | 2015-07-19 13:28:05 +0200 | [diff] [blame] | 443 | mkdir otherrepo/untracked-dir && |
| 444 | test_when_finished "rm -rf otherrepo/untracked-dir" && |
| 445 | ( |
| 446 | GIT_PS1_SHOWUNTRACKEDFILES=y && |
| 447 | cd otherrepo && |
| 448 | __git_ps1 >"$actual" |
| 449 | ) && |
| 450 | test_cmp expected "$actual" |
| 451 | ' |
| 452 | |
| 453 | test_expect_success 'prompt - untracked files status indicator - non-empty untracked dir' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 454 | printf " (main %%)" >expected && |
SZEDER Gábor | 6bfab99 | 2015-07-19 13:28:05 +0200 | [diff] [blame] | 455 | mkdir otherrepo/untracked-dir && |
| 456 | test_when_finished "rm -rf otherrepo/untracked-dir" && |
| 457 | >otherrepo/untracked-dir/untracked-file && |
| 458 | ( |
| 459 | GIT_PS1_SHOWUNTRACKEDFILES=y && |
| 460 | cd otherrepo && |
| 461 | __git_ps1 >"$actual" |
| 462 | ) && |
| 463 | test_cmp expected "$actual" |
| 464 | ' |
| 465 | |
Cody A Taylor | 9bdc517 | 2015-03-12 19:24:50 -0700 | [diff] [blame] | 466 | test_expect_success 'prompt - untracked files status indicator - untracked files outside cwd' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 467 | printf " (main %%)" >expected && |
Cody A Taylor | 9bdc517 | 2015-03-12 19:24:50 -0700 | [diff] [blame] | 468 | ( |
| 469 | mkdir -p ignored_dir && |
| 470 | cd ignored_dir && |
| 471 | GIT_PS1_SHOWUNTRACKEDFILES=y && |
| 472 | __git_ps1 >"$actual" |
| 473 | ) && |
| 474 | test_cmp expected "$actual" |
| 475 | ' |
| 476 | |
Martin Erik Werner | 58978e8 | 2013-02-13 21:58:18 +0100 | [diff] [blame] | 477 | test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 478 | printf " (main)" >expected && |
Martin Erik Werner | 58978e8 | 2013-02-13 21:58:18 +0100 | [diff] [blame] | 479 | test_config bash.showUntrackedFiles false && |
| 480 | ( |
| 481 | sane_unset GIT_PS1_SHOWUNTRACKEDFILES && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 482 | __git_ps1 >"$actual" |
Martin Erik Werner | 58978e8 | 2013-02-13 21:58:18 +0100 | [diff] [blame] | 483 | ) && |
| 484 | test_cmp expected "$actual" |
| 485 | ' |
| 486 | |
| 487 | test_expect_success 'prompt - untracked files status indicator - shell variable unset with config enabled' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 488 | printf " (main)" >expected && |
Martin Erik Werner | 58978e8 | 2013-02-13 21:58:18 +0100 | [diff] [blame] | 489 | test_config bash.showUntrackedFiles true && |
| 490 | ( |
| 491 | sane_unset GIT_PS1_SHOWUNTRACKEDFILES && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 492 | __git_ps1 >"$actual" |
Martin Erik Werner | 58978e8 | 2013-02-13 21:58:18 +0100 | [diff] [blame] | 493 | ) && |
| 494 | test_cmp expected "$actual" |
| 495 | ' |
| 496 | |
| 497 | test_expect_success 'prompt - untracked files status indicator - shell variable set with config disabled' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 498 | printf " (main)" >expected && |
Martin Erik Werner | 58978e8 | 2013-02-13 21:58:18 +0100 | [diff] [blame] | 499 | test_config bash.showUntrackedFiles false && |
| 500 | ( |
| 501 | GIT_PS1_SHOWUNTRACKEDFILES=y && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 502 | __git_ps1 >"$actual" |
Martin Erik Werner | 58978e8 | 2013-02-13 21:58:18 +0100 | [diff] [blame] | 503 | ) && |
| 504 | test_cmp expected "$actual" |
| 505 | ' |
| 506 | |
| 507 | test_expect_success 'prompt - untracked files status indicator - shell variable set with config enabled' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 508 | printf " (main %%)" >expected && |
Martin Erik Werner | 58978e8 | 2013-02-13 21:58:18 +0100 | [diff] [blame] | 509 | test_config bash.showUntrackedFiles true && |
| 510 | ( |
| 511 | GIT_PS1_SHOWUNTRACKEDFILES=y && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 512 | __git_ps1 >"$actual" |
Martin Erik Werner | 58978e8 | 2013-02-13 21:58:18 +0100 | [diff] [blame] | 513 | ) && |
| 514 | test_cmp expected "$actual" |
| 515 | ' |
| 516 | |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 517 | test_expect_success 'prompt - untracked files status indicator - not shown inside .git directory' ' |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 518 | printf " (GIT_DIR!)" >expected && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 519 | ( |
| 520 | GIT_PS1_SHOWUNTRACKEDFILES=y && |
| 521 | cd .git && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 522 | __git_ps1 >"$actual" |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 523 | ) && |
| 524 | test_cmp expected "$actual" |
| 525 | ' |
| 526 | |
| 527 | test_expect_success 'prompt - format string starting with dash' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 528 | printf -- "-main" >expected && |
SZEDER Gábor | 4fe00b4 | 2013-06-17 22:34:16 +0200 | [diff] [blame] | 529 | __git_ps1 "-%s" >"$actual" && |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 530 | test_cmp expected "$actual" |
| 531 | ' |
| 532 | |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 533 | test_expect_success 'prompt - pc mode' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 534 | printf "BEFORE: (\${__git_ps1_branch_name}):AFTER\\nmain" >expected && |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 535 | ( |
| 536 | __git_ps1 "BEFORE:" ":AFTER" >"$actual" && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 537 | test_must_be_empty "$actual" && |
Richard Hansen | 8976500 | 2014-04-21 19:53:09 -0400 | [diff] [blame] | 538 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 539 | ) && |
| 540 | test_cmp expected "$actual" |
| 541 | ' |
| 542 | |
| 543 | test_expect_success 'prompt - bash color pc mode - branch name' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 544 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nmain" >expected && |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 545 | ( |
| 546 | GIT_PS1_SHOWCOLORHINTS=y && |
Eric Sunshine | cff4243 | 2018-07-01 20:24:04 -0400 | [diff] [blame] | 547 | __git_ps1 "BEFORE:" ":AFTER" >"$actual" && |
Richard Hansen | 8976500 | 2014-04-21 19:53:09 -0400 | [diff] [blame] | 548 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 549 | ) && |
| 550 | test_cmp expected "$actual" |
| 551 | ' |
| 552 | |
| 553 | test_expect_success 'prompt - bash color pc mode - detached head' ' |
Richard Hansen | 8976500 | 2014-04-21 19:53:09 -0400 | [diff] [blame] | 554 | printf "BEFORE: (${c_red}\${__git_ps1_branch_name}${c_clear}):AFTER\\n(%s...)" $(git log -1 --format="%h" b1^) >expected && |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 555 | git checkout b1^ && |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 556 | test_when_finished "git checkout main" && |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 557 | ( |
| 558 | GIT_PS1_SHOWCOLORHINTS=y && |
| 559 | __git_ps1 "BEFORE:" ":AFTER" && |
Richard Hansen | 8976500 | 2014-04-21 19:53:09 -0400 | [diff] [blame] | 560 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 561 | ) && |
| 562 | test_cmp expected "$actual" |
| 563 | ' |
| 564 | |
| 565 | test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 566 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\nmain" >expected && |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 567 | echo "dirty" >file && |
| 568 | test_when_finished "git reset --hard" && |
| 569 | ( |
| 570 | GIT_PS1_SHOWDIRTYSTATE=y && |
| 571 | GIT_PS1_SHOWCOLORHINTS=y && |
| 572 | __git_ps1 "BEFORE:" ":AFTER" && |
Richard Hansen | 8976500 | 2014-04-21 19:53:09 -0400 | [diff] [blame] | 573 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 574 | ) && |
| 575 | test_cmp expected "$actual" |
| 576 | ' |
| 577 | |
| 578 | test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 579 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\nmain" >expected && |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 580 | echo "dirty" >file && |
| 581 | test_when_finished "git reset --hard" && |
| 582 | git add -u && |
| 583 | ( |
| 584 | GIT_PS1_SHOWDIRTYSTATE=y && |
| 585 | GIT_PS1_SHOWCOLORHINTS=y && |
| 586 | __git_ps1 "BEFORE:" ":AFTER" && |
Richard Hansen | 8976500 | 2014-04-21 19:53:09 -0400 | [diff] [blame] | 587 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 588 | ) && |
| 589 | test_cmp expected "$actual" |
| 590 | ' |
| 591 | |
| 592 | test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 593 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\nmain" >expected && |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 594 | echo "dirty index" >file && |
| 595 | test_when_finished "git reset --hard" && |
| 596 | git add -u && |
| 597 | echo "dirty worktree" >file && |
| 598 | ( |
| 599 | GIT_PS1_SHOWCOLORHINTS=y && |
| 600 | GIT_PS1_SHOWDIRTYSTATE=y && |
| 601 | __git_ps1 "BEFORE:" ":AFTER" && |
Richard Hansen | 8976500 | 2014-04-21 19:53:09 -0400 | [diff] [blame] | 602 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 603 | ) && |
| 604 | test_cmp expected "$actual" |
| 605 | ' |
| 606 | |
| 607 | test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 608 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\nmain" >expected && |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 609 | ( |
| 610 | GIT_PS1_SHOWDIRTYSTATE=y && |
| 611 | GIT_PS1_SHOWCOLORHINTS=y && |
| 612 | cd otherrepo && |
| 613 | __git_ps1 "BEFORE:" ":AFTER" && |
Richard Hansen | 8976500 | 2014-04-21 19:53:09 -0400 | [diff] [blame] | 614 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 615 | ) && |
| 616 | test_cmp expected "$actual" |
| 617 | ' |
| 618 | |
| 619 | test_expect_success 'prompt - bash color pc mode - inside .git directory' ' |
Richard Hansen | 8976500 | 2014-04-21 19:53:09 -0400 | [diff] [blame] | 620 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nGIT_DIR!" >expected && |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 621 | echo "dirty" >file && |
| 622 | test_when_finished "git reset --hard" && |
| 623 | ( |
| 624 | GIT_PS1_SHOWDIRTYSTATE=y && |
| 625 | GIT_PS1_SHOWCOLORHINTS=y && |
| 626 | cd .git && |
| 627 | __git_ps1 "BEFORE:" ":AFTER" && |
Richard Hansen | 8976500 | 2014-04-21 19:53:09 -0400 | [diff] [blame] | 628 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 629 | ) && |
| 630 | test_cmp expected "$actual" |
| 631 | ' |
| 632 | |
| 633 | test_expect_success 'prompt - bash color pc mode - stash status indicator' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 634 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_lblue}\$${c_clear}):AFTER\\nmain" >expected && |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 635 | echo 2 >file && |
| 636 | git stash && |
| 637 | test_when_finished "git stash drop" && |
| 638 | ( |
| 639 | GIT_PS1_SHOWSTASHSTATE=y && |
| 640 | GIT_PS1_SHOWCOLORHINTS=y && |
| 641 | __git_ps1 "BEFORE:" ":AFTER" && |
Richard Hansen | 8976500 | 2014-04-21 19:53:09 -0400 | [diff] [blame] | 642 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 643 | ) && |
| 644 | test_cmp expected "$actual" |
| 645 | ' |
| 646 | |
| 647 | test_expect_success 'prompt - bash color pc mode - untracked files status indicator' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 648 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\nmain" >expected && |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 649 | ( |
| 650 | GIT_PS1_SHOWUNTRACKEDFILES=y && |
| 651 | GIT_PS1_SHOWCOLORHINTS=y && |
| 652 | __git_ps1 "BEFORE:" ":AFTER" && |
Richard Hansen | 8976500 | 2014-04-21 19:53:09 -0400 | [diff] [blame] | 653 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 654 | ) && |
| 655 | test_cmp expected "$actual" |
| 656 | ' |
| 657 | |
Eduardo R. D'Avila | f3bd62d | 2013-06-26 00:05:15 -0300 | [diff] [blame] | 658 | test_expect_success 'prompt - zsh color pc mode' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 659 | printf "BEFORE: (%%F{green}main%%f):AFTER" >expected && |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 660 | ( |
| 661 | ZSH_VERSION=5.0.0 && |
| 662 | GIT_PS1_SHOWCOLORHINTS=y && |
Richard Hansen | 1e4119c | 2014-05-19 18:55:37 -0400 | [diff] [blame] | 663 | __git_ps1 "BEFORE:" ":AFTER" && |
| 664 | printf "%s" "$PS1" >"$actual" |
Eduardo R. D'Avila | 1572e18 | 2013-06-26 00:05:13 -0300 | [diff] [blame] | 665 | ) && |
| 666 | test_cmp expected "$actual" |
| 667 | ' |
| 668 | |
Jess Austin | 0120b8c | 2015-01-06 20:22:27 -0500 | [diff] [blame] | 669 | test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 670 | printf " (main)" >expected && |
Jess Austin | 0120b8c | 2015-01-06 20:22:27 -0500 | [diff] [blame] | 671 | test_config bash.hideIfPwdIgnored false && |
| 672 | ( |
| 673 | cd ignored_dir && |
| 674 | __git_ps1 >"$actual" |
| 675 | ) && |
| 676 | test_cmp expected "$actual" |
| 677 | ' |
| 678 | |
| 679 | test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled, pc mode' ' |
| 680 | printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected && |
| 681 | test_config bash.hideIfPwdIgnored false && |
| 682 | ( |
| 683 | cd ignored_dir && |
| 684 | __git_ps1 "BEFORE:" ":AFTER" && |
| 685 | printf "%s" "$PS1" >"$actual" |
| 686 | ) && |
| 687 | test_cmp expected "$actual" |
| 688 | ' |
| 689 | |
| 690 | test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 691 | printf " (main)" >expected && |
Jess Austin | 0120b8c | 2015-01-06 20:22:27 -0500 | [diff] [blame] | 692 | ( |
| 693 | cd ignored_dir && |
| 694 | __git_ps1 >"$actual" |
| 695 | ) && |
| 696 | test_cmp expected "$actual" |
| 697 | ' |
| 698 | |
| 699 | test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset, pc mode' ' |
| 700 | printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected && |
| 701 | ( |
| 702 | cd ignored_dir && |
| 703 | __git_ps1 "BEFORE:" ":AFTER" && |
| 704 | printf "%s" "$PS1" >"$actual" |
| 705 | ) && |
| 706 | test_cmp expected "$actual" |
| 707 | ' |
| 708 | |
| 709 | test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled' ' |
Johannes Schindelin | 8dcf73c | 2020-11-18 23:44:45 +0000 | [diff] [blame] | 710 | printf " (main)" >expected && |
Jess Austin | 0120b8c | 2015-01-06 20:22:27 -0500 | [diff] [blame] | 711 | test_config bash.hideIfPwdIgnored false && |
| 712 | ( |
| 713 | cd ignored_dir && |
| 714 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && |
| 715 | __git_ps1 >"$actual" |
| 716 | ) && |
| 717 | test_cmp expected "$actual" |
| 718 | ' |
| 719 | |
| 720 | test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled, pc mode' ' |
| 721 | printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected && |
| 722 | test_config bash.hideIfPwdIgnored false && |
| 723 | ( |
| 724 | cd ignored_dir && |
| 725 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && |
| 726 | __git_ps1 "BEFORE:" ":AFTER" && |
| 727 | printf "%s" "$PS1" >"$actual" |
| 728 | ) && |
| 729 | test_cmp expected "$actual" |
| 730 | ' |
| 731 | |
| 732 | test_expect_success 'prompt - hide if pwd ignored - env var set, config unset' ' |
Jess Austin | 0120b8c | 2015-01-06 20:22:27 -0500 | [diff] [blame] | 733 | ( |
| 734 | cd ignored_dir && |
| 735 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && |
| 736 | __git_ps1 >"$actual" |
| 737 | ) && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 738 | test_must_be_empty "$actual" |
Jess Austin | 0120b8c | 2015-01-06 20:22:27 -0500 | [diff] [blame] | 739 | ' |
| 740 | |
| 741 | test_expect_success 'prompt - hide if pwd ignored - env var set, config unset, pc mode' ' |
| 742 | printf "BEFORE::AFTER" >expected && |
| 743 | ( |
| 744 | cd ignored_dir && |
| 745 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && |
| 746 | __git_ps1 "BEFORE:" ":AFTER" && |
| 747 | printf "%s" "$PS1" >"$actual" |
| 748 | ) && |
| 749 | test_cmp expected "$actual" |
| 750 | ' |
| 751 | |
SZEDER Gábor | d31f298 | 2018-02-24 00:39:48 +0100 | [diff] [blame] | 752 | test_expect_success 'prompt - hide if pwd ignored - inside gitdir' ' |
Jess Austin | 0120b8c | 2015-01-06 20:22:27 -0500 | [diff] [blame] | 753 | printf " (GIT_DIR!)" >expected && |
| 754 | ( |
| 755 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && |
| 756 | cd .git && |
SZEDER Gábor | d31f298 | 2018-02-24 00:39:48 +0100 | [diff] [blame] | 757 | __git_ps1 >"$actual" |
Jess Austin | 0120b8c | 2015-01-06 20:22:27 -0500 | [diff] [blame] | 758 | ) && |
| 759 | test_cmp expected "$actual" |
| 760 | ' |
| 761 | |
SZEDER Gábor | 963c040 | 2012-05-09 02:44:33 +0200 | [diff] [blame] | 762 | test_done |