tests: don't lose exit status with "(cd ...; test <op> $(git ...))"

Rewrite tests that ran "git" inside command substitution and lost the
exit status of "git" so that we notice the failing "git".

Have them use modern patterns such as a "test_cmp" of the expected
outputs instead.

We'll fix more of these these in the subsequent commit, for now we're
only converting the cases where this loss of exit code was combined
with spawning a sub-shell.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason
2023-02-06 23:44:30 +01:00
committed by Junio C Hamano
parent 62f3a45bb4
commit 0cd1a8818d
6 changed files with 45 additions and 24 deletions

View File

@ -168,20 +168,16 @@ replace_gitfile_with_git_dir () {
# Note that this only supports submodules at the root level of the
# superproject, with the default name, i.e. same as its path.
test_git_directory_is_unchanged () {
(
cd ".git/modules/$1" &&
# does core.worktree point at the right place?
test "$(git config core.worktree)" = "../../../$1" &&
# remove it temporarily before comparing, as
# "$1/.git/config" lacks it...
git config --unset core.worktree
) &&
# does core.worktree point at the right place?
echo "../../../$1" >expect &&
git -C ".git/modules/$1" config core.worktree >actual &&
test_cmp expect actual &&
# remove it temporarily before comparing, as
# "$1/.git/config" lacks it...
git -C ".git/modules/$1" config --unset core.worktree &&
diff -r ".git/modules/$1" "$1/.git" &&
(
# ... and then restore.
cd ".git/modules/$1" &&
git config core.worktree "../../../$1"
)
# ... and then restore.
git -C ".git/modules/$1" config core.worktree "../../../$1"
}
test_git_directory_exists () {