Re: [PATCH 2/3] t7406: avoid having git commands upstream of a pipe
- From
SZEDER Gábor <szeder.dev@gmail.com>
- Date
- Aug 6, 2018, 15:48 UTC
- Message-ID
- <20180806154814.24585-1-szeder.dev@gmail.com>
- In-Reply-To
- <20180806152524.27516-3-newren@gmail.com>
Show 14 quoted lines
> When a git command is on the left side of a pipe, the pipe will swallow > its exit status, preventing us from detecting failures in said commands. > Restructure the tests to put the output in a temporary file to avoid > this problem. > > Signed-off-by: Elijah Newren <newren@gmail.com> > --- > t/t7406-submodule-update.sh | 24 +++++++++++++++--------- > 1 file changed, 15 insertions(+), 9 deletions(-) > > diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh > index e2405c96b5..c8971abd07 100755 > --- a/t/t7406-submodule-update.sh > +++ b/t/t7406-submodule-update.sh
Show 17 quoted lines
> @@ -922,7 +928,7 @@ test_expect_success 'submodule update clone shallow submodule' ' > sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp && > mv -f .gitmodules.tmp .gitmodules && > git submodule update --init --depth=$commit_count && > - test 1 = $(git -C submodule log --oneline | wc -l) > + test 1 = $(git -C submodule rev-list --count HEAD) > ) > ' > > @@ -938,7 +944,7 @@ test_expect_success 'submodule update clone shallow submodule outside of depth' > test_i18ngrep "Direct fetching of that commit failed." actual && > git -C ../submodule config uploadpack.allowReachableSHA1InWant true && > git submodule update --init --depth=1 >actual && > - test 1 = $(git -C submodule log --oneline | wc -l) > + test 1 = $(git -C submodule rev-list --count HEAD) > ) > '
These two hunks don't have the desired effect, because command substitutions used like this will hide the exit code anyway. I'd suggest
git -C submodule log --oneline >out && test_line_count = 1 out
instead, with the additional benefit of a nice error message on failure.