mirror of
https://github.com/git/git
synced 2024-10-30 03:13:24 +00:00
f0d4d398e2
Remove various redundant or obsolete code from the test_create_repo() function, and split up its use in test-lib.sh from what tests need from it. This leave us with a pass-through wrapper for "git init" in test-lib-functions.sh, in test-lib.sh we have the same, except for needing to redirect stdout/stderr, and emitting an error ourselves if it fails. We don't need to error() ourselves when test_create_repo() is invoked, as the invocation will be a part of a test's "&&"-chain. Everything below this paragraph is a detailed summary of the history of test_create_repo() explaining why it's safe to remove the various things it was doing: 1. "mkdir -p" isn't needed because "git init" itself will create leading directories if needed. 2. Since we're now a simple wrapper for "git init" we don't need to check that we have only one argument. If someone wants to run "test_create_repo --bare x" that's OK. 3. We won't ever hit that "Cannot setup test environment" error. Checking the test environment sanity when doing "git init" dates back toeea420693b
(t0000: catch trivial pilot errors., 2005-12-10) and2ccd2027b0
(trivial: check, if t/trash directory was successfully created, 2006-01-05). We can also see it in another form a bit later in my own0d314ce834
(test-lib: use subshell instead of cd $new && .. && cd $old, 2010-08-30). But since2006f0adae
(t/test-lib: make sure Git has already been built, 2012-09-17) we already check if we have a built git earlier. The one thing this was testing after that 2012 change was that we'd just built "git", but not "git-init", but since3af4c7156c
(tests: respect GIT_TEST_INSTALLED when initializing repositories, 2018-11-12) we invoke "git", not "git-init". So all of that's been checked already, and we don't need to re-check it here. 4. We don't need to move .git/hooks out of the way. That dates back toc09a69a83e
(Disable hooks during tests., 2005-10-16), since then hooks became disabled by default inf98f8cbac0
(Ship sample hooks with .sample suffix, 2008-06-24). So the hooks were already disabled by default, but as can be seen from "mkdir .git/hooks" changes various tests needed to re-setup that directory. Now they no longer do. This makes us implicitly depend on the default hooks being disabled, which is a good thing. If and when we'd have any on-by-default hooks (I see no reason we ever would) we'd want to see the subtle and not so subtle ways that would break the test suite. 5. We don't need to "cd" to the "$repo" directory at all anymore. In the code being removed here we both "cd"'d to the repository before calling "init", and did so in a subshell. It's not important to do either, so both of those can be removed. We cd'd because this code grew from test-lib.sh code where we'd have done so already, seeeedf8f97e5
(Abstract test_create_repo out for use in tests., 2006-02-17), and later "cd"'d inside a subshell since0d314ce834
to avoid having to keep track of an "old pwd" variable to cd back after the setup. Being in the repository directory made moving the hooks around easier (we wouldn't have to fully qualify the path). Since we're not moving the hooks per #4 above we don't need to "cd" for that reason either. 6. We can drop the --template argument and instead rely on the GIT_TEMPLATE_DIR set to the same path earlier in test-lib.sh. See8683a45d66
(Introduce GIT_TEMPLATE_DIR, 2006-12-19) 7. We only needed that ">&3 2>&4" redirection when invoked from test-lib.sh. We could still invoke test_create_repo() there, but as the invocation is now trivial and we don't have a good reason to use test_create_repo() elsewhere let's call "git init" there ourselves. 8. We didn't need to resolve "git" as "${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" in test_create_repo(), even for the use of test-lib.sh PATH is already set up in test-lib.sh to start with GIT_TEST_INSTALLED and/or GIT_EXEC_PATH before test_create_repo() (now "git init") is called.. So we can simply run "git" and rely on the PATH lookup choosing the right executable. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
101 lines
3.2 KiB
Bash
Executable file
101 lines
3.2 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='remote messages are colorized on the client'
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'setup' '
|
|
write_script .git/hooks/update <<-\EOF &&
|
|
echo error: error
|
|
echo ERROR: also highlighted
|
|
echo hint: hint
|
|
echo hinting: not highlighted
|
|
echo success: success
|
|
echo warning: warning
|
|
echo prefixerror: error
|
|
echo " " "error: leading space"
|
|
echo " "
|
|
echo Err
|
|
echo SUCCESS
|
|
exit 0
|
|
EOF
|
|
echo 1 >file &&
|
|
git add file &&
|
|
git commit -m 1 &&
|
|
git clone . child &&
|
|
(
|
|
cd child &&
|
|
test_commit message2 file content2
|
|
)
|
|
'
|
|
|
|
test_expect_success 'keywords' '
|
|
git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/keywords 2>output &&
|
|
test_decode_color <output >decoded &&
|
|
grep "<BOLD;RED>error<RESET>: error" decoded &&
|
|
grep "<YELLOW>hint<RESET>:" decoded &&
|
|
grep "<BOLD;GREEN>success<RESET>:" decoded &&
|
|
grep "<BOLD;GREEN>SUCCESS<RESET>" decoded &&
|
|
grep "<BOLD;YELLOW>warning<RESET>:" decoded
|
|
'
|
|
|
|
test_expect_success 'whole words at line start' '
|
|
git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/whole-words 2>output &&
|
|
test_decode_color <output >decoded &&
|
|
grep "<YELLOW>hint<RESET>:" decoded &&
|
|
grep "hinting: not highlighted" decoded &&
|
|
grep "prefixerror: error" decoded
|
|
'
|
|
|
|
test_expect_success 'short line' '
|
|
git -C child -c color.remote=always push -f origin HEAD:short-line 2>output &&
|
|
test_decode_color <output >decoded &&
|
|
grep "remote: Err" decoded
|
|
'
|
|
|
|
test_expect_success 'case-insensitive' '
|
|
git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/case-insensitive 2>output &&
|
|
test_decode_color <output >decoded &&
|
|
grep "<BOLD;RED>error<RESET>: error" decoded &&
|
|
grep "<BOLD;RED>ERROR<RESET>: also highlighted" decoded
|
|
'
|
|
|
|
test_expect_success 'leading space' '
|
|
git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/leading-space 2>output &&
|
|
test_decode_color <output >decoded &&
|
|
grep " <BOLD;RED>error<RESET>: leading space" decoded
|
|
'
|
|
|
|
test_expect_success 'spaces only' '
|
|
git -C child -c color.remote=always push -f origin HEAD:only-space 2>output &&
|
|
test_decode_color <output >decoded &&
|
|
grep "remote: " decoded
|
|
'
|
|
|
|
test_expect_success 'no coloring for redirected output' '
|
|
git --git-dir child/.git push -f origin HEAD:refs/heads/redirected-output 2>output &&
|
|
test_decode_color <output >decoded &&
|
|
grep "error: error" decoded
|
|
'
|
|
|
|
test_expect_success 'push with customized color' '
|
|
git --git-dir child/.git -c color.remote=always -c color.remote.error=blue push -f origin HEAD:refs/heads/customized-color 2>output &&
|
|
test_decode_color <output >decoded &&
|
|
grep "<BLUE>error<RESET>:" decoded &&
|
|
grep "<BOLD;GREEN>success<RESET>:" decoded
|
|
'
|
|
|
|
|
|
test_expect_success 'error in customized color' '
|
|
git --git-dir child/.git -c color.remote=always -c color.remote.error=i-am-not-a-color push -f origin HEAD:refs/heads/error-customized-color 2>output &&
|
|
test_decode_color <output >decoded &&
|
|
grep "<BOLD;GREEN>success<RESET>:" decoded
|
|
'
|
|
|
|
test_expect_success 'fallback to color.ui' '
|
|
git --git-dir child/.git -c color.ui=always push -f origin HEAD:refs/heads/fallback-color-ui 2>output &&
|
|
test_decode_color <output >decoded &&
|
|
grep "<BOLD;RED>error<RESET>: error" decoded
|
|
'
|
|
|
|
test_done
|