git/t/t9903-bash-prompt.sh

779 строки
21 KiB
Bash
Исходник Обычный вид История

#!/bin/sh
#
# Copyright (c) 2012 SZEDER Gábor
#
test_description='test git-specific bash prompt functions'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
tests: mark tests relying on the current default for `init.defaultBranch` In addition to the manual adjustment to let the `linux-gcc` CI job run the test suite with `master` and then with `main`, this patch makes sure that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts that currently rely on the initial branch name being `master by default. To determine which test scripts to mark up, the first step was to force-set the default branch name to `master` in - all test scripts that contain the keyword `master`, - t4211, which expects `t/t4211/history.export` with a hard-coded ref to initialize the default branch, - t5560 because it sources `t/t556x_common` which uses `master`, - t8002 and t8012 because both source `t/annotate-tests.sh` which also uses `master`) This trick was performed by this command: $ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\ ' $(git grep -l master t/t[0-9]*.sh) \ t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh After that, careful, manual inspection revealed that some of the test scripts containing the needle `master` do not actually rely on a specific default branch name: either they mention `master` only in a comment, or they initialize that branch specificially, or they do not actually refer to the current default branch. Therefore, the aforementioned modification was undone in those test scripts thusly: $ git checkout HEAD -- \ t/t0027-auto-crlf.sh t/t0060-path-utils.sh \ t/t1011-read-tree-sparse-checkout.sh \ t/t1305-config-include.sh t/t1309-early-config.sh \ t/t1402-check-ref-format.sh t/t1450-fsck.sh \ t/t2024-checkout-dwim.sh \ t/t2106-update-index-assume-unchanged.sh \ t/t3040-subprojects-basic.sh t/t3301-notes.sh \ t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \ t/t3436-rebase-more-options.sh \ t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \ t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \ t/t5511-refspec.sh t/t5526-fetch-submodules.sh \ t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \ t/t5548-push-porcelain.sh \ t/t5552-skipping-fetch-negotiator.sh \ t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \ t/t5614-clone-submodules-shallow.sh \ t/t7508-status.sh t/t7606-merge-custom.sh \ t/t9302-fast-import-unpack-limit.sh We excluded one set of test scripts in these commands, though: the range of `git p4` tests. The reason? `git p4` stores the (foreign) remote branch in the branch called `p4/master`, which is obviously not the default branch. Manual analysis revealed that only five of these tests actually require a specific default branch name to pass; They were modified thusly: $ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\ ' t/t980[0167]*.sh t/t9811*.sh Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-19 02:44:19 +03:00
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./lib-bash.sh
completion: split __git_ps1 into a separate script bash-completion 1.90 shipped with support to load completions dynamically[1], which means the git completion script wouldn't be loaded until the user types 'git <tab>'--this creates a problem to people using __git_ps1(); that function won't be available when the shell is first created. For now distributions have workarounded this issue by moving the git completion to the "compatdir"[2]; this of course is not ideal. The solution, proposed by Kerrick Staley[3], is to split the git script in two; the part that deals with __git_ps1() in one (i.e. git-prompt.sh), and everything else in another (i.e. git-completion.bash). Another benefit of this is that zsh user that are not interested in the bash completion can use it for their prompts, which has been tried before[4]. The only slight issue is that __gitdir() would be duplicated, but this is probably not a big deal. So let's go ahead and move __git_ps1() to a new file. While at this, I took the liberty to reformat the help text in the new file. [1] http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=commitdiff;h=99c4f7f25f50a7cb2fce86055bddfe389effa559 [2] http://projects.archlinux.org/svntogit/packages.git/commit/trunk?h=packages/git&id=974380fabb8f9f412990b17063bf578d98c44a82 [3] http://mid.gmane.org/CANaWP3w9KDu57aHquRRYt8td_haSWTBKs7zUHy-xu0B61gmr9A@mail.gmail.com [4] http://mid.gmane.org/1303824288-15591-1-git-send-email-mstormo@gmail.com Cc: Kerrick Staley <mail@kerrickstaley.com> Cc: Marius Storm-Olsen <mstormo@gmail.com> Cc: Ville Skyttä <ville.skytta@iki.fi> Cc: Dan McGee <dan@archlinux.org> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-23 00:46:40 +04:00
. "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh"
actual="$TRASH_DIRECTORY/actual"
c_red='\001\e[31m\002'
c_green='\001\e[32m\002'
c_lblue='\001\e[1;34m\002'
c_clear='\001\e[0m\002'
test_expect_success 'setup for prompt tests' '
git init otherrepo &&
echo 1 >file &&
git add file &&
test_tick &&
git commit -m initial &&
git tag -a -m msg1 t1 &&
git checkout -b b1 &&
echo 2 >file &&
git commit -m "second b1" file &&
echo 3 >file &&
git commit -m "third b1" file &&
git tag -a -m msg2 t2 &&
git checkout -b b2 main &&
echo 0 >file &&
git commit -m "second b2" file &&
echo 00 >file &&
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 main
'
test_expect_success 'prompt - branch name' '
printf " (main)" >expected &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success SYMLINKS 'prompt - branch name - symlink symref' '
printf " (main)" >expected &&
test_when_finished "git checkout main" &&
test_config core.preferSymlinkRefs true &&
git checkout main &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'
bash prompt: combine 'git rev-parse' for detached head When describing a detached HEAD according to the $GIT_PS1_DESCRIBE environment variable fails, __git_ps1() now runs the '$(git rev-parse --short HEAD)' command substitution to get the abbreviated detached HEAD commit object name. This imposes the overhead of fork()ing a subshell and fork()+exec()ing a git process. Avoid this overhead by combining this command substitution with the "main" 'git rev-parse' execution for getting the path to the .git directory & co. This means that we'll look for the abbreviated commit object name even when it's not necessary, because we're on a branch or the detached HEAD can be described. It doesn't matter, however, because once 'git rev-parse' is up and running to fulfill all those other queries, the additional overhead of looking for the abbreviated commit object name is not measurable because it's lost in the noise. There is a caveat, however, when we are on an unborn branch, because in that case HEAD doesn't point to a valid commit, hence the query for the abbreviated commit object name fails. Therefore, '--short HEAD' must be the last options to 'git rev-parse' in order to get all the other necessary information for the prompt even on an unborn branch. Furthermore, in that case, and in that case only, 'git rev-parse' doesn't output the last line containing the abbreviated commit object name, obviously, so we have to take care to only parse it if 'git rev-parse' exited without any error. Although there are tests already excercising __git_ps1() on unborn branches, they all do so implicitly. Add a test that checks this explicitly. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
2013-06-24 04:16:02 +04:00
test_expect_success 'prompt - unborn branch' '
printf " (unborn)" >expected &&
git checkout --orphan unborn &&
test_when_finished "git checkout main" &&
bash prompt: combine 'git rev-parse' for detached head When describing a detached HEAD according to the $GIT_PS1_DESCRIBE environment variable fails, __git_ps1() now runs the '$(git rev-parse --short HEAD)' command substitution to get the abbreviated detached HEAD commit object name. This imposes the overhead of fork()ing a subshell and fork()+exec()ing a git process. Avoid this overhead by combining this command substitution with the "main" 'git rev-parse' execution for getting the path to the .git directory & co. This means that we'll look for the abbreviated commit object name even when it's not necessary, because we're on a branch or the detached HEAD can be described. It doesn't matter, however, because once 'git rev-parse' is up and running to fulfill all those other queries, the additional overhead of looking for the abbreviated commit object name is not measurable because it's lost in the noise. There is a caveat, however, when we are on an unborn branch, because in that case HEAD doesn't point to a valid commit, hence the query for the abbreviated commit object name fails. Therefore, '--short HEAD' must be the last options to 'git rev-parse' in order to get all the other necessary information for the prompt even on an unborn branch. Furthermore, in that case, and in that case only, 'git rev-parse' doesn't output the last line containing the abbreviated commit object name, obviously, so we have to take care to only parse it if 'git rev-parse' exited without any error. Although there are tests already excercising __git_ps1() on unborn branches, they all do so implicitly. Add a test that checks this explicitly. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
2013-06-24 04:16:02 +04:00
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'
if test_have_prereq !FUNNYNAMES; then
bash prompt: test the prompt with newline in repository path Newlines in the path to a git repository were not an issue for the git-specific bash prompt before commit efaa0c1532 (bash prompt: combine 'git rev-parse' executions in the main code path, 2013-06-17), because the path returned by 'git rev-parse --git-dir' was directly stored in a variable, and this variable was later always accessed inside double quotes. Newlines are not an issue after commit efaa0c1532 either, but it's more subtle. Since efaa0c1532 we use the following single 'git rev-parse' execution to query various info about the repository: git rev-parse --git-dir --is-inside-git-dir \ --is-bare-repository --is-inside-work-tree The results to these queries are separated by a newline character in the output, e.g.: /home/szeder/src/git/.git false false true A newline in the path to the git repository could potentially break the parsing of these results and ultimately the bash prompt, unless the parsing is done right. Commit efaa0c1532 got it right, as I consciously started parsing 'git rev-parse's output from the end, where each record is a single line containing either 'true' or 'false' or, after e3e0b9378b (bash prompt: combine 'git rev-parse' for detached head, 2013-06-24), the abbreviated commit object name, and all what remains at the beginning is the path to the git repository, no matter how many lines it is. This subtlety really warrants its own test, especially since I didn't explain it in the log message or in an in-code comment back then, so add a test to excercise the prompt with newline characters in the path to the repository. Guard this test with the FUNNYNAMES prerequisite, because not all filesystems support newlines in filenames. Note that 'git rev-parse --git-dir' prints '.git' or '.' when at the top of the worktree or the repository, respectively, and only prints the full path to the repository when in a subdirectory, hence the need for changing into a subdir in the test. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-08-17 13:01:58 +04:00
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 " (main)" >expected &&
bash prompt: test the prompt with newline in repository path Newlines in the path to a git repository were not an issue for the git-specific bash prompt before commit efaa0c1532 (bash prompt: combine 'git rev-parse' executions in the main code path, 2013-06-17), because the path returned by 'git rev-parse --git-dir' was directly stored in a variable, and this variable was later always accessed inside double quotes. Newlines are not an issue after commit efaa0c1532 either, but it's more subtle. Since efaa0c1532 we use the following single 'git rev-parse' execution to query various info about the repository: git rev-parse --git-dir --is-inside-git-dir \ --is-bare-repository --is-inside-work-tree The results to these queries are separated by a newline character in the output, e.g.: /home/szeder/src/git/.git false false true A newline in the path to the git repository could potentially break the parsing of these results and ultimately the bash prompt, unless the parsing is done right. Commit efaa0c1532 got it right, as I consciously started parsing 'git rev-parse's output from the end, where each record is a single line containing either 'true' or 'false' or, after e3e0b9378b (bash prompt: combine 'git rev-parse' for detached head, 2013-06-24), the abbreviated commit object name, and all what remains at the beginning is the path to the git repository, no matter how many lines it is. This subtlety really warrants its own test, especially since I didn't explain it in the log message or in an in-code comment back then, so add a test to excercise the prompt with newline characters in the path to the repository. Guard this test with the FUNNYNAMES prerequisite, because not all filesystems support newlines in filenames. Note that 'git rev-parse --git-dir' prints '.git' or '.' when at the top of the worktree or the repository, respectively, and only prints the full path to the repository when in a subdirectory, hence the need for changing into a subdir in the test. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-08-17 13:01:58 +04:00
git init "$repo_with_newline" &&
test_when_finished "rm -rf \"$repo_with_newline\"" &&
mkdir "$repo_with_newline"/subdir &&
(
cd "$repo_with_newline/subdir" &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - detached head' '
printf " ((%s...))" $(git log -1 --format="%h" --abbrev=13 b1^) >expected &&
test_config core.abbrev 13 &&
git checkout b1^ &&
test_when_finished "git checkout main" &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - describe detached head - contains' '
printf " ((t2~1))" >expected &&
git checkout b1^ &&
test_when_finished "git checkout main" &&
(
GIT_PS1_DESCRIBE_STYLE=contains &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - describe detached head - branch' '
printf " ((tags/t2~1))" >expected &&
git checkout b1^ &&
test_when_finished "git checkout main" &&
(
GIT_PS1_DESCRIBE_STYLE=branch &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - describe detached head - describe' '
printf " ((t1-1-g%s))" $(git log -1 --format="%h" b1^) >expected &&
git checkout b1^ &&
test_when_finished "git checkout main" &&
(
GIT_PS1_DESCRIBE_STYLE=describe &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - describe detached head - default' '
printf " ((t2))" >expected &&
git checkout --detach b1 &&
test_when_finished "git checkout main" &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - inside .git directory' '
printf " (GIT_DIR!)" >expected &&
(
cd .git &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - deep inside .git directory' '
printf " (GIT_DIR!)" >expected &&
(
cd .git/objects &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - inside bare repository' '
printf " (BARE:main)" >expected &&
git init --bare bare.git &&
test_when_finished "rm -rf bare.git" &&
(
cd bare.git &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - interactive rebase' '
git-prompt: change the prompt for interactive-based rebases In the past, we had different prompts for different types of rebases: REBASE: for am-based rebases REBASE-m: for merge-based rebases REBASE-i: for interactive-based rebases It's not clear why this distinction was necessary or helpful; when the prompt was added in commit e75201963f67 ("Improve bash prompt to detect various states like an unfinished merge", 2007-09-30), it simply added these three different types. Perhaps there was a useful purpose back then, but there have been some changes: * The merge backend was deleted after being implemented on top of the interactive backend, causing the prompt for merge-based rebases to change from REBASE-m to REBASE-i. * The interactive backend is used for multiple different types of non-interactive rebases, so the "-i" part of the prompt doesn't really mean what it used to. * Rebase backends have gained more abilities and have a great deal of overlap, sometimes making it hard to distinguish them. * Behavioral differences between the backends have also been ironed out. * We want to change the default backend from am to interactive, which means people would get "REBASE-i" by default if we didn't change the prompt, and only if they specified --am or --whitespace or -C would they get the "REBASE" prompt. * In the future, we plan to have "--whitespace", "-C", and even "--am" run the interactive backend once it can handle everything the am-backend can. For all these reasons, make the prompt for any type of rebase just be "REBASE". Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-16 00:36:35 +03:00
printf " (b1|REBASE 2/3)" >expected &&
write_script fake_editor.sh <<-\EOF &&
echo "exec echo" >"$1"
echo "edit $(git log -1 --format="%h")" >>"$1"
echo "exec echo" >>"$1"
EOF
test_when_finished "rm -f fake_editor.sh" &&
test_set_editor "$TRASH_DIRECTORY/fake_editor.sh" &&
git checkout b1 &&
test_when_finished "git checkout main" &&
git rebase -i HEAD^ &&
test_when_finished "git rebase --abort" &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - rebase merge' '
git-prompt: change the prompt for interactive-based rebases In the past, we had different prompts for different types of rebases: REBASE: for am-based rebases REBASE-m: for merge-based rebases REBASE-i: for interactive-based rebases It's not clear why this distinction was necessary or helpful; when the prompt was added in commit e75201963f67 ("Improve bash prompt to detect various states like an unfinished merge", 2007-09-30), it simply added these three different types. Perhaps there was a useful purpose back then, but there have been some changes: * The merge backend was deleted after being implemented on top of the interactive backend, causing the prompt for merge-based rebases to change from REBASE-m to REBASE-i. * The interactive backend is used for multiple different types of non-interactive rebases, so the "-i" part of the prompt doesn't really mean what it used to. * Rebase backends have gained more abilities and have a great deal of overlap, sometimes making it hard to distinguish them. * Behavioral differences between the backends have also been ironed out. * We want to change the default backend from am to interactive, which means people would get "REBASE-i" by default if we didn't change the prompt, and only if they specified --am or --whitespace or -C would they get the "REBASE" prompt. * In the future, we plan to have "--whitespace", "-C", and even "--am" run the interactive backend once it can handle everything the am-backend can. For all these reasons, make the prompt for any type of rebase just be "REBASE". Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-16 00:36:35 +03:00
printf " (b2|REBASE 1/3)" >expected &&
git checkout b2 &&
test_when_finished "git checkout main" &&
test_must_fail git rebase --merge b1 b2 &&
test_when_finished "git rebase --abort" &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'
git-prompt: change the prompt for interactive-based rebases In the past, we had different prompts for different types of rebases: REBASE: for am-based rebases REBASE-m: for merge-based rebases REBASE-i: for interactive-based rebases It's not clear why this distinction was necessary or helpful; when the prompt was added in commit e75201963f67 ("Improve bash prompt to detect various states like an unfinished merge", 2007-09-30), it simply added these three different types. Perhaps there was a useful purpose back then, but there have been some changes: * The merge backend was deleted after being implemented on top of the interactive backend, causing the prompt for merge-based rebases to change from REBASE-m to REBASE-i. * The interactive backend is used for multiple different types of non-interactive rebases, so the "-i" part of the prompt doesn't really mean what it used to. * Rebase backends have gained more abilities and have a great deal of overlap, sometimes making it hard to distinguish them. * Behavioral differences between the backends have also been ironed out. * We want to change the default backend from am to interactive, which means people would get "REBASE-i" by default if we didn't change the prompt, and only if they specified --am or --whitespace or -C would they get the "REBASE" prompt. * In the future, we plan to have "--whitespace", "-C", and even "--am" run the interactive backend once it can handle everything the am-backend can. For all these reasons, make the prompt for any type of rebase just be "REBASE". Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-16 00:36:35 +03:00
test_expect_success 'prompt - rebase am' '
printf " (b2|REBASE 1/3)" >expected &&
git checkout b2 &&
test_when_finished "git checkout main" &&
rebase: rename the two primary rebase backends Two related changes, with separate rationale for each: Rename the 'interactive' backend to 'merge' because: * 'interactive' as a name caused confusion; this backend has been used for many kinds of non-interactive rebases, and will probably be used in the future for more non-interactive rebases than interactive ones given that we are making it the default. * 'interactive' is not the underlying strategy; merging is. * the directory where state is stored is not called .git/rebase-interactive but .git/rebase-merge. Rename the 'am' backend to 'apply' because: * Few users are familiar with git-am as a reference point. * Related to the above, the name 'am' makes sentences in the documentation harder for users to read and comprehend (they may read it as the verb from "I am"); avoiding this difficult places a large burden on anyone writing documentation about this backend to be very careful with quoting and sentence structure and often forces annoying redundancy to try to avoid such problems. * Users stumble over pronunciation ("am" as in "I am a person not a backend" or "am" as in "the first and thirteenth letters in the alphabet in order are "A-M"); this may drive confusion when one user tries to explain to another what they are doing. * While "am" is the tool driving this backend, the tool driving git-am is git-apply, and since we are driving towards lower-level tools for the naming of the merge backend we may as well do so here too. * The directory where state is stored has never been called .git/rebase-am, it was always called .git/rebase-apply. For all the reasons listed above: * Modify the documentation to refer to the backends with the new names * Provide a brief note in the documentation connecting the new names to the old names in case users run across the old names anywhere (e.g. in old release notes or older versions of the documentation) * Change the (new) --am command line flag to --apply * Rename some enums, variables, and functions to reinforce the new backend names for us as well. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-16 00:36:41 +03:00
test_must_fail git rebase --apply b1 b2 &&
test_when_finished "git rebase --abort" &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - merge' '
printf " (b1|MERGING)" >expected &&
git checkout b1 &&
test_when_finished "git checkout main" &&
test_must_fail git merge b2 &&
test_when_finished "git reset --hard" &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - cherry-pick' '
printf " (main|CHERRY-PICKING)" >expected &&
test_must_fail git cherry-pick b1 b1^ &&
test_when_finished "git cherry-pick --abort" &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual" &&
git reset --merge &&
test_must_fail git rev-parse CHERRY_PICK_HEAD &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - revert' '
printf " (main|REVERTING)" >expected &&
test_must_fail git revert b1^ b1 &&
test_when_finished "git revert --abort" &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual" &&
git reset --merge &&
test_must_fail git rev-parse REVERT_HEAD &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - bisect' '
printf " (main|BISECTING)" >expected &&
git bisect start &&
test_when_finished "git bisect reset" &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - dirty status indicator - clean' '
printf " (main)" >expected &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - dirty status indicator - dirty worktree' '
printf " (main *)" >expected &&
echo "dirty" >file &&
test_when_finished "git reset --hard" &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - dirty status indicator - dirty index' '
printf " (main +)" >expected &&
echo "dirty" >file &&
test_when_finished "git reset --hard" &&
git add -u &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - dirty status indicator - dirty index and worktree' '
printf " (main *+)" >expected &&
echo "dirty index" >file &&
test_when_finished "git reset --hard" &&
git add -u &&
echo "dirty worktree" >file &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - dirty status indicator - orphan branch - clean' '
printf " (orphan #)" >expected &&
test_when_finished "git checkout main" &&
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 main" &&
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 main" &&
git checkout --orphan orphan &&
>file &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - dirty status indicator - shell variable unset with config disabled' '
printf " (main)" >expected &&
echo "dirty" >file &&
test_when_finished "git reset --hard" &&
test_config bash.showDirtyState false &&
(
sane_unset GIT_PS1_SHOWDIRTYSTATE &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - dirty status indicator - shell variable unset with config enabled' '
printf " (main)" >expected &&
echo "dirty" >file &&
test_when_finished "git reset --hard" &&
test_config bash.showDirtyState true &&
(
sane_unset GIT_PS1_SHOWDIRTYSTATE &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - dirty status indicator - shell variable set with config disabled' '
printf " (main)" >expected &&
echo "dirty" >file &&
test_when_finished "git reset --hard" &&
test_config bash.showDirtyState false &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - dirty status indicator - shell variable set with config enabled' '
printf " (main *)" >expected &&
echo "dirty" >file &&
test_when_finished "git reset --hard" &&
test_config bash.showDirtyState true &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - dirty status indicator - not shown inside .git directory' '
printf " (GIT_DIR!)" >expected &&
echo "dirty" >file &&
test_when_finished "git reset --hard" &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
cd .git &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - stash status indicator - no stash' '
printf " (main)" >expected &&
(
GIT_PS1_SHOWSTASHSTATE=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - stash status indicator - stash' '
printf " (main $)" >expected &&
echo 2 >file &&
git stash &&
test_when_finished "git stash drop" &&
git pack-refs --all &&
(
GIT_PS1_SHOWSTASHSTATE=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - stash status indicator - not shown inside .git directory' '
printf " (GIT_DIR!)" >expected &&
echo 2 >file &&
git stash &&
test_when_finished "git stash drop" &&
(
GIT_PS1_SHOWSTASHSTATE=y &&
cd .git &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - untracked files status indicator - no untracked files' '
printf " (main)" >expected &&
(
GIT_PS1_SHOWUNTRACKEDFILES=y &&
cd otherrepo &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - untracked files status indicator - untracked files' '
printf " (main %%)" >expected &&
(
GIT_PS1_SHOWUNTRACKEDFILES=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - untracked files status indicator - empty untracked dir' '
printf " (main)" >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 " (main %%)" >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 " (main %%)" >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 " (main)" >expected &&
test_config bash.showUntrackedFiles false &&
(
sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - untracked files status indicator - shell variable unset with config enabled' '
printf " (main)" >expected &&
test_config bash.showUntrackedFiles true &&
(
sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - untracked files status indicator - shell variable set with config disabled' '
printf " (main)" >expected &&
test_config bash.showUntrackedFiles false &&
(
GIT_PS1_SHOWUNTRACKEDFILES=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - untracked files status indicator - shell variable set with config enabled' '
printf " (main %%)" >expected &&
test_config bash.showUntrackedFiles true &&
(
GIT_PS1_SHOWUNTRACKEDFILES=y &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - untracked files status indicator - not shown inside .git directory' '
printf " (GIT_DIR!)" >expected &&
(
GIT_PS1_SHOWUNTRACKEDFILES=y &&
cd .git &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - format string starting with dash' '
printf -- "-main" >expected &&
__git_ps1 "-%s" >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - pc mode' '
printf "BEFORE: (\${__git_ps1_branch_name}):AFTER\\nmain" >expected &&
(
__git_ps1 "BEFORE:" ":AFTER" >"$actual" &&
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>' Using 'test_must_be_empty' is shorter and more idiomatic than >empty && test_cmp empty out as it saves the creation of an empty file. Furthermore, sometimes the expected empty file doesn't have such a descriptive name like 'empty', and its creation is far away from the place where it's finally used for comparison (e.g. in 't7600-merge.sh', where two expected empty files are created in the 'setup' test, but are used only about 500 lines later). These cases were found by instrumenting 'test_cmp' to error out the test script when it's used to compare empty files, and then converted manually. Note that even after this patch there still remain a lot of cases where we use 'test_cmp' to check empty files: - Sometimes the expected output is not hard-coded in the test, but 'test_cmp' is used to ensure that two similar git commands produce the same output, and that output happens to be empty, e.g. the test 'submodule update --merge - ignores --merge for new submodules' in 't7406-submodule-update.sh'. - Repetitive common tasks, including preparing the expected results and running 'test_cmp', are often extracted into a helper function, and some of this helper's callsites expect no output. - For the same reason as above, the whole 'test_expect_success' block is within a helper function, e.g. in 't3070-wildmatch.sh'. - Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update (-p)' in 't9400-git-cvsserver-server.sh'. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-20 00:57:25 +03:00
test_must_be_empty "$actual" &&
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - bash color pc mode - branch name' '
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nmain" >expected &&
(
GIT_PS1_SHOWCOLORHINTS=y &&
__git_ps1 "BEFORE:" ":AFTER" >"$actual" &&
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - bash color pc mode - detached head' '
printf "BEFORE: (${c_red}\${__git_ps1_branch_name}${c_clear}):AFTER\\n(%s...)" $(git log -1 --format="%h" b1^) >expected &&
git checkout b1^ &&
test_when_finished "git checkout main" &&
(
GIT_PS1_SHOWCOLORHINTS=y &&
__git_ps1 "BEFORE:" ":AFTER" &&
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\nmain" >expected &&
echo "dirty" >file &&
test_when_finished "git reset --hard" &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
GIT_PS1_SHOWCOLORHINTS=y &&
__git_ps1 "BEFORE:" ":AFTER" &&
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\nmain" >expected &&
echo "dirty" >file &&
test_when_finished "git reset --hard" &&
git add -u &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
GIT_PS1_SHOWCOLORHINTS=y &&
__git_ps1 "BEFORE:" ":AFTER" &&
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}${c_green}+${c_clear}):AFTER\\nmain" >expected &&
echo "dirty index" >file &&
test_when_finished "git reset --hard" &&
git add -u &&
echo "dirty worktree" >file &&
(
GIT_PS1_SHOWCOLORHINTS=y &&
GIT_PS1_SHOWDIRTYSTATE=y &&
__git_ps1 "BEFORE:" ":AFTER" &&
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\nmain" >expected &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
GIT_PS1_SHOWCOLORHINTS=y &&
cd otherrepo &&
__git_ps1 "BEFORE:" ":AFTER" &&
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - bash color pc mode - inside .git directory' '
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nGIT_DIR!" >expected &&
echo "dirty" >file &&
test_when_finished "git reset --hard" &&
(
GIT_PS1_SHOWDIRTYSTATE=y &&
GIT_PS1_SHOWCOLORHINTS=y &&
cd .git &&
__git_ps1 "BEFORE:" ":AFTER" &&
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - bash color pc mode - stash status indicator' '
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_lblue}\$${c_clear}):AFTER\\nmain" >expected &&
echo 2 >file &&
git stash &&
test_when_finished "git stash drop" &&
(
GIT_PS1_SHOWSTASHSTATE=y &&
GIT_PS1_SHOWCOLORHINTS=y &&
__git_ps1 "BEFORE:" ":AFTER" &&
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - bash color pc mode - untracked files status indicator' '
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\nmain" >expected &&
(
GIT_PS1_SHOWUNTRACKEDFILES=y &&
GIT_PS1_SHOWCOLORHINTS=y &&
__git_ps1 "BEFORE:" ":AFTER" &&
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - zsh color pc mode' '
printf "BEFORE: (%%F{green}main%%f):AFTER" >expected &&
(
ZSH_VERSION=5.0.0 &&
GIT_PS1_SHOWCOLORHINTS=y &&
__git_ps1 "BEFORE:" ":AFTER" &&
printf "%s" "$PS1" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled' '
printf " (main)" >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 " (main)" >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 " (main)" >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"
) &&
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>' Using 'test_must_be_empty' is shorter and more idiomatic than >empty && test_cmp empty out as it saves the creation of an empty file. Furthermore, sometimes the expected empty file doesn't have such a descriptive name like 'empty', and its creation is far away from the place where it's finally used for comparison (e.g. in 't7600-merge.sh', where two expected empty files are created in the 'setup' test, but are used only about 500 lines later). These cases were found by instrumenting 'test_cmp' to error out the test script when it's used to compare empty files, and then converted manually. Note that even after this patch there still remain a lot of cases where we use 'test_cmp' to check empty files: - Sometimes the expected output is not hard-coded in the test, but 'test_cmp' is used to ensure that two similar git commands produce the same output, and that output happens to be empty, e.g. the test 'submodule update --merge - ignores --merge for new submodules' in 't7406-submodule-update.sh'. - Repetitive common tasks, including preparing the expected results and running 'test_cmp', are often extracted into a helper function, and some of this helper's callsites expect no output. - For the same reason as above, the whole 'test_expect_success' block is within a helper function, e.g. in 't3070-wildmatch.sh'. - Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update (-p)' in 't9400-git-cvsserver-server.sh'. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-20 00:57:25 +03:00
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_expect_success 'prompt - conflict indicator' '
printf " (main|CONFLICT)" >expected &&
echo "stash" >file &&
git stash &&
test_when_finished "git stash drop" &&
echo "commit" >file &&
git commit -m "commit" file &&
test_when_finished "git reset --hard HEAD~" &&
test_must_fail git stash apply &&
(
GIT_PS1_SHOWCONFLICTSTATE="yes" &&
__git_ps1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_done