tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2012 SZEDER Gábor
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='test git-specific bash prompt functions'
|
|
|
|
|
|
|
|
. ./lib-bash.sh
|
|
|
|
|
2012-05-22 20:46:40 +00:00
|
|
|
. "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
|
|
|
|
actual="$TRASH_DIRECTORY/actual"
|
2013-06-26 03:05:13 +00:00
|
|
|
c_red='\\[\\e[31m\\]'
|
|
|
|
c_green='\\[\\e[32m\\]'
|
|
|
|
c_lblue='\\[\\e[1;34m\\]'
|
|
|
|
c_clear='\\[\\e[0m\\]'
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
|
|
|
|
test_expect_success 'setup for prompt tests' '
|
|
|
|
git init otherrepo &&
|
2013-06-17 20:34:16 +00:00
|
|
|
echo 1 >file &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git add file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m initial &&
|
|
|
|
git tag -a -m msg1 t1 &&
|
|
|
|
git checkout -b b1 &&
|
2013-06-17 20:34:16 +00:00
|
|
|
echo 2 >file &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git commit -m "second b1" file &&
|
2013-06-17 20:34:16 +00:00
|
|
|
echo 3 >file &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git commit -m "third b1" file &&
|
|
|
|
git tag -a -m msg2 t2 &&
|
|
|
|
git checkout -b b2 master &&
|
2013-06-17 20:34:16 +00:00
|
|
|
echo 0 >file &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git commit -m "second b2" file &&
|
2013-06-17 20:34:16 +00:00
|
|
|
echo 00 >file &&
|
2013-04-25 09:28:54 +00:00
|
|
|
git commit -m "another b2" file &&
|
2013-06-17 20:34:16 +00:00
|
|
|
echo 000 >file &&
|
2013-04-25 09:28:54 +00:00
|
|
|
git commit -m "yet another b2" file &&
|
2015-01-07 01:22:27 +00:00
|
|
|
mkdir ignored_dir &&
|
|
|
|
echo "ignored_dir/" >>.gitignore &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git checkout master
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - branch name' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master)" >expected &&
|
|
|
|
__git_ps1 >"$actual" &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
2012-08-24 17:52:48 +00:00
|
|
|
test_expect_success SYMLINKS 'prompt - branch name - symlink symref' '
|
|
|
|
printf " (master)" >expected &&
|
|
|
|
test_when_finished "git checkout master" &&
|
|
|
|
test_config core.preferSymlinkRefs true &&
|
|
|
|
git checkout master &&
|
|
|
|
__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 00:16:02 +00:00
|
|
|
test_expect_success 'prompt - unborn branch' '
|
|
|
|
printf " (unborn)" >expected &&
|
|
|
|
git checkout --orphan unborn &&
|
|
|
|
test_when_finished "git checkout master" &&
|
|
|
|
__git_ps1 >"$actual" &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
t: factor out FUNNYNAMES as shared lazy prereq
A fair number of tests need to check that the filesystem supports file
names including "funny" characters, like newline, tab, and double-quote.
Jonathan Nieder suggested that this be extracted into a lazy prereq in
the top-level `test-lib.sh`. This patch effects that change.
The FUNNYNAMES prereq now uniformly requires support for newlines, tabs,
and double-quotes in filenames. This very slightly decreases the power
of some tests, which might have run previously on a system that supports
(e.g.) newlines and tabs but not double-quotes, but now will not. This
seems to me like an acceptable tradeoff for consistency.
One test (`t/t9902-completion.sh`) defined FUNNYNAMES to further require
the separators \034 through \037, the test for which was implemented
using the Bash-specific $'\034' syntax. I've elected to leave this one
as is, renaming it to FUNNIERNAMES.
After this patch, `git grep 'test_\(set\|lazy\)_prereq.*FUNNYNAMES'` has
only one result.
Signed-off-by: William Chargin <wchargin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-06 18:35:08 +00:00
|
|
|
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 09:01:58 +00:00
|
|
|
say 'Your filesystem does not allow newlines in filenames.'
|
|
|
|
fi
|
|
|
|
|
|
|
|
test_expect_success FUNNYNAMES 'prompt - with newline in path' '
|
t: factor out FUNNYNAMES as shared lazy prereq
A fair number of tests need to check that the filesystem supports file
names including "funny" characters, like newline, tab, and double-quote.
Jonathan Nieder suggested that this be extracted into a lazy prereq in
the top-level `test-lib.sh`. This patch effects that change.
The FUNNYNAMES prereq now uniformly requires support for newlines, tabs,
and double-quotes in filenames. This very slightly decreases the power
of some tests, which might have run previously on a system that supports
(e.g.) newlines and tabs but not double-quotes, but now will not. This
seems to me like an acceptable tradeoff for consistency.
One test (`t/t9902-completion.sh`) defined FUNNYNAMES to further require
the separators \034 through \037, the test for which was implemented
using the Bash-specific $'\034' syntax. I've elected to leave this one
as is, renaming it to FUNNIERNAMES.
After this patch, `git grep 'test_\(set\|lazy\)_prereq.*FUNNYNAMES'` has
only one result.
Signed-off-by: William Chargin <wchargin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-06 18:35:08 +00:00
|
|
|
repo_with_newline="repo
|
|
|
|
with
|
|
|
|
newline" &&
|
|
|
|
mkdir "$repo_with_newline" &&
|
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 09:01:58 +00:00
|
|
|
printf " (master)" >expected &&
|
|
|
|
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"
|
|
|
|
'
|
|
|
|
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_expect_success 'prompt - detached head' '
|
2013-06-23 23:55:42 +00:00
|
|
|
printf " ((%s...))" $(git log -1 --format="%h" --abbrev=13 b1^) >expected &&
|
|
|
|
test_config core.abbrev 13 &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git checkout b1^ &&
|
|
|
|
test_when_finished "git checkout master" &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual" &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - describe detached head - contains' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " ((t2~1))" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git checkout b1^ &&
|
|
|
|
test_when_finished "git checkout master" &&
|
|
|
|
(
|
|
|
|
GIT_PS1_DESCRIBE_STYLE=contains &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - describe detached head - branch' '
|
2016-04-22 13:39:01 +00:00
|
|
|
printf " ((tags/t2~1))" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git checkout b1^ &&
|
|
|
|
test_when_finished "git checkout master" &&
|
|
|
|
(
|
|
|
|
GIT_PS1_DESCRIBE_STYLE=branch &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - describe detached head - describe' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " ((t1-1-g%s))" $(git log -1 --format="%h" b1^) >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git checkout b1^ &&
|
|
|
|
test_when_finished "git checkout master" &&
|
|
|
|
(
|
|
|
|
GIT_PS1_DESCRIBE_STYLE=describe &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - describe detached head - default' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " ((t2))" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git checkout --detach b1 &&
|
|
|
|
test_when_finished "git checkout master" &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual" &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - inside .git directory' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (GIT_DIR!)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
(
|
|
|
|
cd .git &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - deep inside .git directory' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (GIT_DIR!)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
(
|
2018-05-26 06:47:45 +00:00
|
|
|
cd .git/objects &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - inside bare repository' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (BARE:master)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git init --bare bare.git &&
|
|
|
|
test_when_finished "rm -rf bare.git" &&
|
|
|
|
(
|
|
|
|
cd bare.git &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - interactive rebase' '
|
2015-03-20 10:07:15 +00:00
|
|
|
printf " (b1|REBASE-i 2/3)" >expected &&
|
2012-08-24 18:03:58 +00:00
|
|
|
write_script fake_editor.sh <<-\EOF &&
|
|
|
|
echo "exec echo" >"$1"
|
|
|
|
echo "edit $(git log -1 --format="%h")" >>"$1"
|
|
|
|
echo "exec echo" >>"$1"
|
|
|
|
EOF
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_when_finished "rm -f fake_editor.sh" &&
|
|
|
|
test_set_editor "$TRASH_DIRECTORY/fake_editor.sh" &&
|
|
|
|
git checkout b1 &&
|
|
|
|
test_when_finished "git checkout master" &&
|
|
|
|
git rebase -i HEAD^ &&
|
2016-09-05 19:00:47 +00:00
|
|
|
test_when_finished "git rebase --abort" &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual" &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - rebase merge' '
|
rebase: implement --merge via the interactive machinery
As part of an ongoing effort to make rebase have more uniform behavior,
modify the merge backend to behave like the interactive one, by
re-implementing it on top of the latter.
Interactive rebases are implemented in terms of cherry-pick rather than
the merge-recursive builtin, but cherry-pick also calls into the
recursive merge machinery by default and can accept special merge
strategies and/or special strategy options. As such, there really is
not any need for having both git-rebase--merge and
git-rebase--interactive anymore. Delete git-rebase--merge.sh and
instead implement it in builtin/rebase.c.
This results in a few deliberate but small user-visible changes:
* The progress output is modified (see t3406 and t3420 for examples)
* A few known test failures are now fixed (see t3421)
* bash-prompt during a rebase --merge is now REBASE-i instead of
REBASE-m. Reason: The prompt is a reflection of the backend in use;
this allows users to report an issue to the git mailing list with
the appropriate backend information, and allows advanced users to
know where to search for relevant control files. (see t9903)
testcase modification notes:
t3406: --interactive and --merge had slightly different progress output
while running; adjust a test to match the new expectation
t3420: these test precise output while running, but rebase--am,
rebase--merge, and rebase--interactive all were built on very
different commands (am, merge-recursive, cherry-pick), so the
tests expected different output for each type. Now we expect
--merge and --interactive to have the same output.
t3421: --interactive fixes some bugs in --merge! Wahoo!
t9903: --merge uses the interactive backend so the prompt expected is
now REBASE-i.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-12-11 16:11:39 +00:00
|
|
|
printf " (b2|REBASE-i 1/3)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git checkout b2 &&
|
|
|
|
test_when_finished "git checkout master" &&
|
|
|
|
test_must_fail git rebase --merge b1 b2 &&
|
|
|
|
test_when_finished "git rebase --abort" &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual" &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - rebase' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (b2|REBASE 1/3)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git checkout b2 &&
|
|
|
|
test_when_finished "git checkout master" &&
|
|
|
|
test_must_fail git rebase b1 b2 &&
|
|
|
|
test_when_finished "git rebase --abort" &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual" &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - merge' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (b1|MERGING)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git checkout b1 &&
|
|
|
|
test_when_finished "git checkout master" &&
|
|
|
|
test_must_fail git merge b2 &&
|
|
|
|
test_when_finished "git reset --hard" &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual" &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - cherry-pick' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master|CHERRY-PICKING)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_must_fail git cherry-pick b1 &&
|
|
|
|
test_when_finished "git reset --hard" &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual" &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - bisect' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master|BISECTING)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
git bisect start &&
|
|
|
|
test_when_finished "git bisect reset" &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual" &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - dirty status indicator - clean' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - dirty status indicator - dirty worktree' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master *)" >expected &&
|
|
|
|
echo "dirty" >file &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_when_finished "git reset --hard" &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - dirty status indicator - dirty index' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master +)" >expected &&
|
|
|
|
echo "dirty" >file &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_when_finished "git reset --hard" &&
|
|
|
|
git add -u &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - dirty status indicator - dirty index and worktree' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master *+)" >expected &&
|
|
|
|
echo "dirty index" >file &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_when_finished "git reset --hard" &&
|
|
|
|
git add -u &&
|
2013-06-17 20:34:16 +00:00
|
|
|
echo "dirty worktree" >file &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
2015-11-21 11:30:07 +00:00
|
|
|
test_expect_success 'prompt - dirty status indicator - orphan branch - clean' '
|
|
|
|
printf " (orphan #)" >expected &&
|
|
|
|
test_when_finished "git checkout master" &&
|
|
|
|
git checkout --orphan orphan &&
|
|
|
|
git reset --hard &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
|
|
|
__git_ps1 >"$actual"
|
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
2015-11-21 11:30:09 +00:00
|
|
|
test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index' '
|
2015-11-21 11:30:07 +00:00
|
|
|
printf " (orphan +)" >expected &&
|
|
|
|
test_when_finished "git checkout master" &&
|
|
|
|
git checkout --orphan orphan &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
|
|
|
__git_ps1 >"$actual"
|
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
2015-11-21 11:30:09 +00:00
|
|
|
test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index and worktree' '
|
2015-11-21 11:30:07 +00:00
|
|
|
printf " (orphan *+)" >expected &&
|
|
|
|
test_when_finished "git checkout master" &&
|
|
|
|
git checkout --orphan orphan &&
|
|
|
|
>file &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
2013-02-13 20:58:19 +00:00
|
|
|
test_expect_success 'prompt - dirty status indicator - shell variable unset with config disabled' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master)" >expected &&
|
|
|
|
echo "dirty" >file &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_when_finished "git reset --hard" &&
|
|
|
|
test_config bash.showDirtyState false &&
|
2013-02-13 20:58:19 +00:00
|
|
|
(
|
|
|
|
sane_unset GIT_PS1_SHOWDIRTYSTATE &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
2013-02-13 20:58:19 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - dirty status indicator - shell variable unset with config enabled' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master)" >expected &&
|
|
|
|
echo "dirty" >file &&
|
2013-02-13 20:58:19 +00:00
|
|
|
test_when_finished "git reset --hard" &&
|
|
|
|
test_config bash.showDirtyState true &&
|
|
|
|
(
|
|
|
|
sane_unset GIT_PS1_SHOWDIRTYSTATE &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
2013-02-13 20:58:19 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - dirty status indicator - shell variable set with config disabled' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master)" >expected &&
|
|
|
|
echo "dirty" >file &&
|
2013-02-13 20:58:19 +00:00
|
|
|
test_when_finished "git reset --hard" &&
|
|
|
|
test_config bash.showDirtyState false &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
2013-02-13 20:58:19 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - dirty status indicator - shell variable set with config enabled' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master *)" >expected &&
|
|
|
|
echo "dirty" >file &&
|
2013-02-13 20:58:19 +00:00
|
|
|
test_when_finished "git reset --hard" &&
|
|
|
|
test_config bash.showDirtyState true &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - dirty status indicator - not shown inside .git directory' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (GIT_DIR!)" >expected &&
|
|
|
|
echo "dirty" >file &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_when_finished "git reset --hard" &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
|
|
|
cd .git &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - stash status indicator - no stash' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
(
|
|
|
|
GIT_PS1_SHOWSTASHSTATE=y &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - stash status indicator - stash' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master $)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
echo 2 >file &&
|
|
|
|
git stash &&
|
|
|
|
test_when_finished "git stash drop" &&
|
2011-04-01 15:47:37 +00:00
|
|
|
git pack-refs --all &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
(
|
|
|
|
GIT_PS1_SHOWSTASHSTATE=y &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - stash status indicator - not shown inside .git directory' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (GIT_DIR!)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
echo 2 >file &&
|
|
|
|
git stash &&
|
|
|
|
test_when_finished "git stash drop" &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWSTASHSTATE=y &&
|
|
|
|
cd .git &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - untracked files status indicator - no untracked files' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
(
|
|
|
|
GIT_PS1_SHOWUNTRACKEDFILES=y &&
|
|
|
|
cd otherrepo &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - untracked files status indicator - untracked files' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master %%)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
(
|
|
|
|
GIT_PS1_SHOWUNTRACKEDFILES=y &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
2015-07-19 11:28:05 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - untracked files status indicator - empty untracked dir' '
|
|
|
|
printf " (master)" >expected &&
|
|
|
|
mkdir otherrepo/untracked-dir &&
|
|
|
|
test_when_finished "rm -rf otherrepo/untracked-dir" &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWUNTRACKEDFILES=y &&
|
|
|
|
cd otherrepo &&
|
|
|
|
__git_ps1 >"$actual"
|
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - untracked files status indicator - non-empty untracked dir' '
|
|
|
|
printf " (master %%)" >expected &&
|
|
|
|
mkdir otherrepo/untracked-dir &&
|
|
|
|
test_when_finished "rm -rf otherrepo/untracked-dir" &&
|
|
|
|
>otherrepo/untracked-dir/untracked-file &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWUNTRACKEDFILES=y &&
|
|
|
|
cd otherrepo &&
|
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
2015-03-13 02:24:50 +00:00
|
|
|
test_expect_success 'prompt - untracked files status indicator - untracked files outside cwd' '
|
|
|
|
printf " (master %%)" >expected &&
|
|
|
|
(
|
|
|
|
mkdir -p ignored_dir &&
|
|
|
|
cd ignored_dir &&
|
|
|
|
GIT_PS1_SHOWUNTRACKEDFILES=y &&
|
|
|
|
__git_ps1 >"$actual"
|
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
2013-02-13 20:58:18 +00:00
|
|
|
test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master)" >expected &&
|
2013-02-13 20:58:18 +00:00
|
|
|
test_config bash.showUntrackedFiles false &&
|
|
|
|
(
|
|
|
|
sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
2013-02-13 20:58:18 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - untracked files status indicator - shell variable unset with config enabled' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master)" >expected &&
|
2013-02-13 20:58:18 +00:00
|
|
|
test_config bash.showUntrackedFiles true &&
|
|
|
|
(
|
|
|
|
sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
2013-02-13 20:58:18 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - untracked files status indicator - shell variable set with config disabled' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master)" >expected &&
|
2013-02-13 20:58:18 +00:00
|
|
|
test_config bash.showUntrackedFiles false &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWUNTRACKEDFILES=y &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
2013-02-13 20:58:18 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - untracked files status indicator - shell variable set with config enabled' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (master %%)" >expected &&
|
2013-02-13 20:58:18 +00:00
|
|
|
test_config bash.showUntrackedFiles true &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWUNTRACKEDFILES=y &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
2013-02-13 20:58:18 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_expect_success 'prompt - untracked files status indicator - not shown inside .git directory' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf " (GIT_DIR!)" >expected &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
(
|
|
|
|
GIT_PS1_SHOWUNTRACKEDFILES=y &&
|
|
|
|
cd .git &&
|
2013-06-17 20:34:16 +00:00
|
|
|
__git_ps1 >"$actual"
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - format string starting with dash' '
|
2013-06-17 20:34:16 +00:00
|
|
|
printf -- "-master" >expected &&
|
|
|
|
__git_ps1 "-%s" >"$actual" &&
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
2013-06-26 03:05:13 +00:00
|
|
|
test_expect_success 'prompt - pc mode' '
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "BEFORE: (\${__git_ps1_branch_name}):AFTER\\nmaster" >expected &&
|
2013-06-26 03:05:13 +00:00
|
|
|
(
|
|
|
|
__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-19 21:57:25 +00:00
|
|
|
test_must_be_empty "$actual" &&
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
|
2013-06-26 03:05:13 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - bash color pc mode - branch name' '
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nmaster" >expected &&
|
2013-06-26 03:05:13 +00:00
|
|
|
(
|
|
|
|
GIT_PS1_SHOWCOLORHINTS=y &&
|
2018-07-02 00:24:04 +00:00
|
|
|
__git_ps1 "BEFORE:" ":AFTER" >"$actual" &&
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
|
2013-06-26 03:05:13 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - bash color pc mode - detached head' '
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "BEFORE: (${c_red}\${__git_ps1_branch_name}${c_clear}):AFTER\\n(%s...)" $(git log -1 --format="%h" b1^) >expected &&
|
2013-06-26 03:05:13 +00:00
|
|
|
git checkout b1^ &&
|
|
|
|
test_when_finished "git checkout master" &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWCOLORHINTS=y &&
|
|
|
|
__git_ps1 "BEFORE:" ":AFTER" &&
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
|
2013-06-26 03:05:13 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\nmaster" >expected &&
|
2013-06-26 03:05:13 +00:00
|
|
|
echo "dirty" >file &&
|
|
|
|
test_when_finished "git reset --hard" &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
|
|
|
GIT_PS1_SHOWCOLORHINTS=y &&
|
|
|
|
__git_ps1 "BEFORE:" ":AFTER" &&
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
|
2013-06-26 03:05:13 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\nmaster" >expected &&
|
2013-06-26 03:05:13 +00:00
|
|
|
echo "dirty" >file &&
|
|
|
|
test_when_finished "git reset --hard" &&
|
|
|
|
git add -u &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
|
|
|
GIT_PS1_SHOWCOLORHINTS=y &&
|
|
|
|
__git_ps1 "BEFORE:" ":AFTER" &&
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
|
2013-06-26 03:05:13 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\nmaster" >expected &&
|
2013-06-26 03:05:13 +00:00
|
|
|
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" &&
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
|
2013-06-26 03:05:13 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\nmaster" >expected &&
|
2013-06-26 03:05:13 +00:00
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
|
|
|
GIT_PS1_SHOWCOLORHINTS=y &&
|
|
|
|
cd otherrepo &&
|
|
|
|
__git_ps1 "BEFORE:" ":AFTER" &&
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
|
2013-06-26 03:05:13 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - bash color pc mode - inside .git directory' '
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nGIT_DIR!" >expected &&
|
2013-06-26 03:05:13 +00:00
|
|
|
echo "dirty" >file &&
|
|
|
|
test_when_finished "git reset --hard" &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWDIRTYSTATE=y &&
|
|
|
|
GIT_PS1_SHOWCOLORHINTS=y &&
|
|
|
|
cd .git &&
|
|
|
|
__git_ps1 "BEFORE:" ":AFTER" &&
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
|
2013-06-26 03:05:13 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - bash color pc mode - stash status indicator' '
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_lblue}\$${c_clear}):AFTER\\nmaster" >expected &&
|
2013-06-26 03:05:13 +00:00
|
|
|
echo 2 >file &&
|
|
|
|
git stash &&
|
|
|
|
test_when_finished "git stash drop" &&
|
|
|
|
(
|
|
|
|
GIT_PS1_SHOWSTASHSTATE=y &&
|
|
|
|
GIT_PS1_SHOWCOLORHINTS=y &&
|
|
|
|
__git_ps1 "BEFORE:" ":AFTER" &&
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
|
2013-06-26 03:05:13 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - bash color pc mode - untracked files status indicator' '
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\nmaster" >expected &&
|
2013-06-26 03:05:13 +00:00
|
|
|
(
|
|
|
|
GIT_PS1_SHOWUNTRACKEDFILES=y &&
|
|
|
|
GIT_PS1_SHOWCOLORHINTS=y &&
|
|
|
|
__git_ps1 "BEFORE:" ":AFTER" &&
|
2014-04-21 23:53:09 +00:00
|
|
|
printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
|
2013-06-26 03:05:13 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
2013-06-26 03:05:15 +00:00
|
|
|
test_expect_success 'prompt - zsh color pc mode' '
|
2014-05-19 22:55:37 +00:00
|
|
|
printf "BEFORE: (%%F{green}master%%f):AFTER" >expected &&
|
2013-06-26 03:05:13 +00:00
|
|
|
(
|
|
|
|
ZSH_VERSION=5.0.0 &&
|
|
|
|
GIT_PS1_SHOWCOLORHINTS=y &&
|
2014-05-19 22:55:37 +00:00
|
|
|
__git_ps1 "BEFORE:" ":AFTER" &&
|
|
|
|
printf "%s" "$PS1" >"$actual"
|
2013-06-26 03:05:13 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
2015-01-07 01:22:27 +00:00
|
|
|
test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled' '
|
|
|
|
printf " (master)" >expected &&
|
|
|
|
test_config bash.hideIfPwdIgnored false &&
|
|
|
|
(
|
|
|
|
cd ignored_dir &&
|
|
|
|
__git_ps1 >"$actual"
|
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled, pc mode' '
|
|
|
|
printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
|
|
|
|
test_config bash.hideIfPwdIgnored false &&
|
|
|
|
(
|
|
|
|
cd ignored_dir &&
|
|
|
|
__git_ps1 "BEFORE:" ":AFTER" &&
|
|
|
|
printf "%s" "$PS1" >"$actual"
|
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset' '
|
|
|
|
printf " (master)" >expected &&
|
|
|
|
(
|
|
|
|
cd ignored_dir &&
|
|
|
|
__git_ps1 >"$actual"
|
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset, pc mode' '
|
|
|
|
printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
|
|
|
|
(
|
|
|
|
cd ignored_dir &&
|
|
|
|
__git_ps1 "BEFORE:" ":AFTER" &&
|
|
|
|
printf "%s" "$PS1" >"$actual"
|
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled' '
|
|
|
|
printf " (master)" >expected &&
|
|
|
|
test_config bash.hideIfPwdIgnored false &&
|
|
|
|
(
|
|
|
|
cd ignored_dir &&
|
|
|
|
GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
|
|
|
|
__git_ps1 >"$actual"
|
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled, pc mode' '
|
|
|
|
printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
|
|
|
|
test_config bash.hideIfPwdIgnored false &&
|
|
|
|
(
|
|
|
|
cd ignored_dir &&
|
|
|
|
GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
|
|
|
|
__git_ps1 "BEFORE:" ":AFTER" &&
|
|
|
|
printf "%s" "$PS1" >"$actual"
|
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prompt - hide if pwd ignored - env var set, config unset' '
|
|
|
|
(
|
|
|
|
cd ignored_dir &&
|
|
|
|
GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
|
|
|
|
__git_ps1 >"$actual"
|
|
|
|
) &&
|
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-19 21:57:25 +00:00
|
|
|
test_must_be_empty "$actual"
|
2015-01-07 01:22:27 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
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"
|
|
|
|
'
|
|
|
|
|
2018-02-23 23:39:48 +00:00
|
|
|
test_expect_success 'prompt - hide if pwd ignored - inside gitdir' '
|
2015-01-07 01:22:27 +00:00
|
|
|
printf " (GIT_DIR!)" >expected &&
|
|
|
|
(
|
|
|
|
GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
|
|
|
|
cd .git &&
|
2018-02-23 23:39:48 +00:00
|
|
|
__git_ps1 >"$actual"
|
2015-01-07 01:22:27 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expected "$actual"
|
|
|
|
'
|
|
|
|
|
tests: add tests for the bash prompt functions in the completion script
The tests cover the discovery of the '.git' directory in the
__gitdir() function in different scenarios, and the prompt itself,
i.e. branch name, detached heads, operations (rebase, merge,
cherry-pick, bisect), and status indicators (dirty, stash, untracked
files; but not the upstream status).
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09 00:44:33 +00:00
|
|
|
test_done
|