diff mbox series

GSoC 2024 [PATCH v2] Fix Git command exit code suppression in test script t2104-update-index-skip-worktree.sh

Message ID CAHCXyj1hUVNNuCOgsNv4GJUi79_o9iWZDvV8Ocz3DodreYoL7g@mail.gmail.com (mailing list archive)
State New
Headers show
Series GSoC 2024 [PATCH v2] Fix Git command exit code suppression in test script t2104-update-index-skip-worktree.sh | expand

Commit Message

Aishwarya Narayanan March 28, 2024, 6:47 p.m. UTC
This commit addresses an issue in the `test_expect_success 'setup'` test
where the exit code of `git ls-files -t` was being suppressed. This could
lead to the test passing even if the Git command failed.
The change ensures the output is captured and the exit code is checked
correctly.
Additionally, the commit message follows recommended coding guidelines
by using `test` instead of `[]` for conditionals and proper indentation.
Signed-off-by: Aishwarya Narayanan <aishnana.03@gmail.com>
---

Dear Git Maintainers,

I'm writing to submit a patch that addresses an issue in the test
script t2104-update-index-skip-worktree.sh. The issue involves the
inadvertent suppression of exit codes from Git commands when used in
pipelines. This could potentially lead to false positives in test
results, masking actual bugs or regressions.

This patch modifies instances of git ls-files -t and similar Git
commands used in pipelines to ensure their exit codes are correctly
evaluated. It achieves this by:
Capturing the command output in a variable.
Applying checks for the exit code immediately after command execution.
Adjusting related test cases to work with the new method of capturing
and evaluating Git command outputs.

I've carefully reviewed the Documentation/SubmittingPatches document
and ensured the patch adheres to the recommended guidelines. The patch
file itself is attached to this email.

Thank you for your time and consideration. I welcome any feedback or
questions you may have.

 t/t2104-update-index-skip-worktree.sh | 98 ++++++++++++++-------------
 1 file changed, 52 insertions(+), 46 deletions(-)

+
+test_done

Comments

Patrick Steinhardt April 2, 2024, 11:06 a.m. UTC | #1
On Fri, Mar 29, 2024 at 12:17:25AM +0530, Aishwarya Narayanan wrote:

The subject of this mail is not in line with how we typically write
commit subjects. For one it is overly long, we typically don't want them
to be longer than 72 characters. Second, commit subjects are expected to
start with a scope.

> This commit addresses an issue in the `test_expect_success 'setup'` test
> where the exit code of `git ls-files -t` was being suppressed. This could
> lead to the test passing even if the Git command failed.
> The change ensures the output is captured and the exit code is checked
> correctly.
> Additionally, the commit message follows recommended coding guidelines
> by using `test` instead of `[]` for conditionals and proper indentation.

We typically don't say things like "This commit", but rather use an
imperative style ("Address this issue..."). Also, we typically start
with the problem description before we say how the problem is being
adddressed.

> Signed-off-by: Aishwarya Narayanan <aishnana.03@gmail.com>

Paragraphs should be separated by an empty line. Most importantly, the
trailer lines need to be split from the remainder of the body or
otherwise they won't even be recognized as such.

> ---
> 
> Dear Git Maintainers,
> 
> I'm writing to submit a patch that addresses an issue in the test
> script t2104-update-index-skip-worktree.sh. The issue involves the
> inadvertent suppression of exit codes from Git commands when used in
> pipelines. This could potentially lead to false positives in test
> results, masking actual bugs or regressions.
> 
> This patch modifies instances of git ls-files -t and similar Git
> commands used in pipelines to ensure their exit codes are correctly
> evaluated. It achieves this by:
> Capturing the command output in a variable.
> Applying checks for the exit code immediately after command execution.
> Adjusting related test cases to work with the new method of capturing
> and evaluating Git command outputs.
> 
> I've carefully reviewed the Documentation/SubmittingPatches document
> and ensured the patch adheres to the recommended guidelines. The patch
> file itself is attached to this email.
> 
> Thank you for your time and consideration. I welcome any feedback or
> questions you may have.
> 
>  t/t2104-update-index-skip-worktree.sh | 98 ++++++++++++++-------------
>  1 file changed, 52 insertions(+), 46 deletions(-)
> 
> diff --git a/t/t2104-update-index-skip-worktree.sh
> b/t/t2104-update-index-skip-worktree.sh
> index 674d7de3d3..8fdf0e0d82 100755
> --- a/t/t2104-update-index-skip-worktree.sh
> +++ b/t/t2104-update-index-skip-worktree.sh
> @@ -2,67 +2,73 @@
>  #
>  # Copyright (c) 2008 Nguyễn Thái Ngọc Duy
>  #
> -test_description='skip-worktree bit test'
> 
> -TEST_PASSES_SANITIZE_LEAK=true
> -. ./test-lib.sh
> +test_description='skip-worktree bit test'
> 
> -sane_unset GIT_TEST_SPLIT_INDEX
> +TEST_PASSES_SANITIZE_LEAK=true
> +. ./test-lib.sh
> 
> -test_set_index_version () {
> -    GIT_INDEX_VERSION="$1"
> -    export GIT_INDEX_VERSION
> -}
> +sane_unset GIT_TEST_SPLIT_INDEX
> 
> -test_set_index_version 3
> +test_set_index_version () {
> +  GIT_INDEX_VERSION="$1"
> +  export GIT_INDEX_VERSION
> +}

Sorry, but this patch seems to be completely broken and rewrites almost
the whole file. It's basically impossible for a reviewer to figure out
what exactly has changed.

I assume two things happened:

  - Your patch may have changed line endings. Please make sure that your
    editor writes Unix-style line endings ("\n"), only.

  - You seem to have changed indentation from four spaces to two spaces.

It would be great to pay more attention to such details and review your
own patches before sending them out to the mailing list.

Patrick

> -cat >expect.full <<EOF
> -H 1
> -H 2
> -H sub/1
> -H sub/2
> -EOF
> +test_set_index_version 3
> 
> -cat >expect.skip <<EOF
> -S 1
> -H 2
> -S sub/1
> -H sub/2
> -EOF
> +cat >expect.full <<EOF
> +H 1
> +H 2
> +H sub/1
> +H sub/2
> +EOF
> +cat >expect.skip <<EOF
> +S 1
> +H 2
> +S sub/1
> +H sub/2
> +EOF
> 
> +# Good: capture output and check exit code
>  test_expect_success 'setup' '
> -   mkdir sub &&
> -   touch ./1 ./2 sub/1 sub/2 &&
> -   git add 1 2 sub/1 sub/2 &&
> -   output=$(git ls-files -t)
> -   echo "$output" | test_cmp expect.full -
> -   if [ $? -ne 0 ]; then
> -       exit 1
> -   fi
> +  mkdir sub &&
> +  touch ./1 ./2 sub/1 sub/2 &&
> +  git add 1 2 sub/1 sub/2 &&
> +  git ls-files -t >actual &&
> +  test_cmp expect.full actual
>  '
> 
> +test_expect_success 'index is at version 2' '
> +  test "$(git update-index --show-index-version)" = 2
> +'
> +
> +# Good: pipe only after Git command
>  test_expect_success 'update-index --skip-worktree' '
> -   git update-index --skip-worktree 1 sub/1 &&
> -   output=$(git ls-files -t)
> -   echo "$output" | test_cmp expect.skip -
> -   if [ $? -ne 0 ]; then
> -       exit 1
> -   fi
> +  git update-index --skip-worktree 1 sub/1 &&
> +  git ls-files -t | test_cmp expect.skip -
> +'
> +
> +test_expect_success 'index is at version 3 after having some
> skip-worktree entries' '
> +  test "$(git update-index --show-index-version)" = 3
>  '
> 
>  test_expect_success 'ls-files -t' '
> -   output=$(git ls-files -t)
> -   echo "$output" | test_cmp expect.skip -
> -   if [ $? -ne 0 ]; then
> -       exit 1
> -   fi
> +  git ls-files -t | test_cmp expect.skip -
>  '
> 
> +# Good: separate command for exit code check
>  test_expect_success 'update-index --no-skip-worktree' '
> -   git update-index --no-skip-worktree 1 sub/1 &&
> -   output=$(git ls-files -t)
> -   echo "$output" | test_cmp expect.full -
> -   if [ $? -ne 0 ]; then
> -       exit 1
> -   fi
> +  git update-index --no-skip-worktree 1 sub/1
> +  if [ $? -ne 0 ]; then
> +    echo "Failed to update-index --no-skip-worktree"
> +    exit 1
> +  fi
> +  git ls-files -t | test_cmp expect.full -
>  '
> +
> +test_expect_success 'index version is back to 2 when there is no
> skip-worktree entry' '
> +  test "$(git update-index --show-index-version)" = 2
> +'
> +
> +test_done
> -- 
> Sincerely,
> Aishwarya Narayanan
>
Aishwarya Narayanan April 2, 2024, 11:56 a.m. UTC | #2
Dear Git maintainers,

I apologize for the previous patch for
t2104-update-index-skip-worktree.sh. It was overly verbose in the
subject line and rewrote significant portions of the file, making
review difficult. I'm still learning how to write clear and concise
commit messages and reviewing patches effectively.

>We typically don't say things like "This commit", but rather use an
>imperative style ("Address this issue..."). Also, we typically start
>with the problem description before we say how the problem is being
>adddressed.

New Commit Message:
Fix suppressed exit code in t2104-update-index-skip-worktree.sh

This patch addresses an issue in the `test_expect_success 'setup'` test
where the exit code of `git ls-files -t` was being suppressed. This could
lead to the test passing even if the Git command failed.

The change ensures the output is captured in a variable (`actual`) and
the exit code is checked using a separate `if` statement.
Signed-off-by: Aishwarya Narayanan <aishnana.03@gmail.com>

>I assume two things happened:
>- Your patch may have changed line endings. Please make sure that your
>editor writes Unix-style line endings ("\n"), only.
> - You seem to have changed indentation from four spaces to two spaces.

Here's a revised version of the patch that addresses the original issue:
Captures the output of git ls-files -t in a variable (actual) for
proper exit code checking.
Uses test instead of [] for conditionals and maintains consistent
indentation (two spaces) for better readability.
This patch ensures the test correctly verifies the functionality of
git ls-files -t and prevents false positives.
I'm working on improving my patch creation and review skills. Please
let me know if you have any suggestions or require further
clarification.

Thanks,
Aishwarya Narayanan

On Tue, 2 Apr 2024 at 16:36, Patrick Steinhardt <ps@pks.im> wrote:
>
> On Fri, Mar 29, 2024 at 12:17:25AM +0530, Aishwarya Narayanan wrote:
>
> The subject of this mail is not in line with how we typically write
> commit subjects. For one it is overly long, we typically don't want them
> to be longer than 72 characters. Second, commit subjects are expected to
> start with a scope.
>
> > This commit addresses an issue in the `test_expect_success 'setup'` test
> > where the exit code of `git ls-files -t` was being suppressed. This could
> > lead to the test passing even if the Git command failed.
> > The change ensures the output is captured and the exit code is checked
> > correctly.
> > Additionally, the commit message follows recommended coding guidelines
> > by using `test` instead of `[]` for conditionals and proper indentation.
>
> We typically don't say things like "This commit", but rather use an
> imperative style ("Address this issue..."). Also, we typically start
> with the problem description before we say how the problem is being
> adddressed.
>
> > Signed-off-by: Aishwarya Narayanan <aishnana.03@gmail.com>
>
> Paragraphs should be separated by an empty line. Most importantly, the
> trailer lines need to be split from the remainder of the body or
> otherwise they won't even be recognized as such.
>
> > ---
> >
> > Dear Git Maintainers,
> >
> > I'm writing to submit a patch that addresses an issue in the test
> > script t2104-update-index-skip-worktree.sh. The issue involves the
> > inadvertent suppression of exit codes from Git commands when used in
> > pipelines. This could potentially lead to false positives in test
> > results, masking actual bugs or regressions.
> >
> > This patch modifies instances of git ls-files -t and similar Git
> > commands used in pipelines to ensure their exit codes are correctly
> > evaluated. It achieves this by:
> > Capturing the command output in a variable.
> > Applying checks for the exit code immediately after command execution.
> > Adjusting related test cases to work with the new method of capturing
> > and evaluating Git command outputs.
> >
> > I've carefully reviewed the Documentation/SubmittingPatches document
> > and ensured the patch adheres to the recommended guidelines. The patch
> > file itself is attached to this email.
> >
> > Thank you for your time and consideration. I welcome any feedback or
> > questions you may have.
> >
> >  t/t2104-update-index-skip-worktree.sh | 98 ++++++++++++++-------------
> >  1 file changed, 52 insertions(+), 46 deletions(-)
> >
> > diff --git a/t/t2104-update-index-skip-worktree.sh
> > b/t/t2104-update-index-skip-worktree.sh
> > index 674d7de3d3..8fdf0e0d82 100755
> > --- a/t/t2104-update-index-skip-worktree.sh
> > +++ b/t/t2104-update-index-skip-worktree.sh
> > @@ -2,67 +2,73 @@
> >  #
> >  # Copyright (c) 2008 Nguyễn Thái Ngọc Duy
> >  #
> > -test_description='skip-worktree bit test'
> >
> > -TEST_PASSES_SANITIZE_LEAK=true
> > -. ./test-lib.sh
> > +test_description='skip-worktree bit test'
> >
> > -sane_unset GIT_TEST_SPLIT_INDEX
> > +TEST_PASSES_SANITIZE_LEAK=true
> > +. ./test-lib.sh
> >
> > -test_set_index_version () {
> > -    GIT_INDEX_VERSION="$1"
> > -    export GIT_INDEX_VERSION
> > -}
> > +sane_unset GIT_TEST_SPLIT_INDEX
> >
> > -test_set_index_version 3
> > +test_set_index_version () {
> > +  GIT_INDEX_VERSION="$1"
> > +  export GIT_INDEX_VERSION
> > +}
>
> Sorry, but this patch seems to be completely broken and rewrites almost
> the whole file. It's basically impossible for a reviewer to figure out
> what exactly has changed.
>
> I assume two things happened:
>
>   - Your patch may have changed line endings. Please make sure that your
>     editor writes Unix-style line endings ("\n"), only.
>
>   - You seem to have changed indentation from four spaces to two spaces.
>
> It would be great to pay more attention to such details and review your
> own patches before sending them out to the mailing list.
>
> Patrick
>
> > -cat >expect.full <<EOF
> > -H 1
> > -H 2
> > -H sub/1
> > -H sub/2
> > -EOF
> > +test_set_index_version 3
> >
> > -cat >expect.skip <<EOF
> > -S 1
> > -H 2
> > -S sub/1
> > -H sub/2
> > -EOF
> > +cat >expect.full <<EOF
> > +H 1
> > +H 2
> > +H sub/1
> > +H sub/2
> > +EOF
> > +cat >expect.skip <<EOF
> > +S 1
> > +H 2
> > +S sub/1
> > +H sub/2
> > +EOF
> >
> > +# Good: capture output and check exit code
> >  test_expect_success 'setup' '
> > -   mkdir sub &&
> > -   touch ./1 ./2 sub/1 sub/2 &&
> > -   git add 1 2 sub/1 sub/2 &&
> > -   output=$(git ls-files -t)
> > -   echo "$output" | test_cmp expect.full -
> > -   if [ $? -ne 0 ]; then
> > -       exit 1
> > -   fi
> > +  mkdir sub &&
> > +  touch ./1 ./2 sub/1 sub/2 &&
> > +  git add 1 2 sub/1 sub/2 &&
> > +  git ls-files -t >actual &&
> > +  test_cmp expect.full actual
> >  '
> >
> > +test_expect_success 'index is at version 2' '
> > +  test "$(git update-index --show-index-version)" = 2
> > +'
> > +
> > +# Good: pipe only after Git command
> >  test_expect_success 'update-index --skip-worktree' '
> > -   git update-index --skip-worktree 1 sub/1 &&
> > -   output=$(git ls-files -t)
> > -   echo "$output" | test_cmp expect.skip -
> > -   if [ $? -ne 0 ]; then
> > -       exit 1
> > -   fi
> > +  git update-index --skip-worktree 1 sub/1 &&
> > +  git ls-files -t | test_cmp expect.skip -
> > +'
> > +
> > +test_expect_success 'index is at version 3 after having some
> > skip-worktree entries' '
> > +  test "$(git update-index --show-index-version)" = 3
> >  '
> >
> >  test_expect_success 'ls-files -t' '
> > -   output=$(git ls-files -t)
> > -   echo "$output" | test_cmp expect.skip -
> > -   if [ $? -ne 0 ]; then
> > -       exit 1
> > -   fi
> > +  git ls-files -t | test_cmp expect.skip -
> >  '
> >
> > +# Good: separate command for exit code check
> >  test_expect_success 'update-index --no-skip-worktree' '
> > -   git update-index --no-skip-worktree 1 sub/1 &&
> > -   output=$(git ls-files -t)
> > -   echo "$output" | test_cmp expect.full -
> > -   if [ $? -ne 0 ]; then
> > -       exit 1
> > -   fi
> > +  git update-index --no-skip-worktree 1 sub/1
> > +  if [ $? -ne 0 ]; then
> > +    echo "Failed to update-index --no-skip-worktree"
> > +    exit 1
> > +  fi
> > +  git ls-files -t | test_cmp expect.full -
> >  '
> > +
> > +test_expect_success 'index version is back to 2 when there is no
> > skip-worktree entry' '
> > +  test "$(git update-index --show-index-version)" = 2
> > +'
> > +
> > +test_done
> > --
> > Sincerely,
> > Aishwarya Narayanan
> >
Eric Sunshine April 2, 2024, 5:20 p.m. UTC | #3
On Tue, Apr 2, 2024 at 7:06 AM Patrick Steinhardt <ps@pks.im> wrote:
> I assume two things happened:
>
>   - Your patch may have changed line endings. Please make sure that your
>     editor writes Unix-style line endings ("\n"), only.
>
>   - You seem to have changed indentation from four spaces to two spaces.

Micro correction: Documentation/CodingGuidelines says this:

    We use tabs to indent, and interpret tabs as taking up
    to 8 spaces.
Patrick Steinhardt April 2, 2024, 5:23 p.m. UTC | #4
On Tue, Apr 02, 2024 at 01:20:53PM -0400, Eric Sunshine wrote:
> On Tue, Apr 2, 2024 at 7:06 AM Patrick Steinhardt <ps@pks.im> wrote:
> > I assume two things happened:
> >
> >   - Your patch may have changed line endings. Please make sure that your
> >     editor writes Unix-style line endings ("\n"), only.
> >
> >   - You seem to have changed indentation from four spaces to two spaces.
> 
> Micro correction: Documentation/CodingGuidelines says this:
> 
>     We use tabs to indent, and interpret tabs as taking up
>     to 8 spaces.

Huh, that's even weirder. The diff changes indentation from four spaces
to two spaces for me.

Patrick
Junio C Hamano April 2, 2024, 6:41 p.m. UTC | #5
Patrick Steinhardt <ps@pks.im> writes:

>> Micro correction: Documentation/CodingGuidelines says this:
>> 
>>     We use tabs to indent, and interpret tabs as taking up
>>     to 8 spaces.
>
> Huh, that's even weirder. The diff changes indentation from four spaces
> to two spaces for me.

Indeed, the original is already flawed.

----- >8 --------- >8 --------- >8 --------- >8 ----
Subject: t2104: style fixes

We use tabs to indent, not two or four spaces.  

These days, even the test fixture preparation should be done inside
test_expect_success block.

Address these two style violations in this test.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/t2104-update-index-skip-worktree.sh | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git c/t/t2104-update-index-skip-worktree.sh w/t/t2104-update-index-skip-worktree.sh
index 0bab134d71..7ec7f30b44 100755
--- c/t/t2104-update-index-skip-worktree.sh
+++ w/t/t2104-update-index-skip-worktree.sh
@@ -11,27 +11,27 @@ TEST_PASSES_SANITIZE_LEAK=true
 sane_unset GIT_TEST_SPLIT_INDEX
 
 test_set_index_version () {
-    GIT_INDEX_VERSION="$1"
-    export GIT_INDEX_VERSION
+	GIT_INDEX_VERSION="$1"
+	export GIT_INDEX_VERSION
 }
 
 test_set_index_version 3
 
-cat >expect.full <<EOF
-H 1
-H 2
-H sub/1
-H sub/2
-EOF
+test_expect_success 'setup' '
+	cat >expect.full <<-\EOF &&
+	H 1
+	H 2
+	H sub/1
+	H sub/2
+	EOF
 
-cat >expect.skip <<EOF
-S 1
-H 2
-S sub/1
-H sub/2
-EOF
+	cat >expect.skip <<-\EOF &&
+	S 1
+	H 2
+	S sub/1
+	H sub/2
+	EOF
 
-test_expect_success 'setup' '
 	mkdir sub &&
 	touch ./1 ./2 sub/1 sub/2 &&
 	git add 1 2 sub/1 sub/2 &&
diff mbox series

Patch

diff --git a/t/t2104-update-index-skip-worktree.sh
b/t/t2104-update-index-skip-worktree.sh
index 674d7de3d3..8fdf0e0d82 100755
--- a/t/t2104-update-index-skip-worktree.sh
+++ b/t/t2104-update-index-skip-worktree.sh
@@ -2,67 +2,73 @@ 
 #
 # Copyright (c) 2008 Nguyễn Thái Ngọc Duy
 #
-test_description='skip-worktree bit test'

-TEST_PASSES_SANITIZE_LEAK=true
-. ./test-lib.sh
+test_description='skip-worktree bit test'

-sane_unset GIT_TEST_SPLIT_INDEX
+TEST_PASSES_SANITIZE_LEAK=true
+. ./test-lib.sh

-test_set_index_version () {
-    GIT_INDEX_VERSION="$1"
-    export GIT_INDEX_VERSION
-}
+sane_unset GIT_TEST_SPLIT_INDEX

-test_set_index_version 3
+test_set_index_version () {
+  GIT_INDEX_VERSION="$1"
+  export GIT_INDEX_VERSION
+}

-cat >expect.full <<EOF
-H 1
-H 2
-H sub/1
-H sub/2
-EOF
+test_set_index_version 3

-cat >expect.skip <<EOF
-S 1
-H 2
-S sub/1
-H sub/2
-EOF
+cat >expect.full <<EOF
+H 1
+H 2
+H sub/1
+H sub/2
+EOF
+cat >expect.skip <<EOF
+S 1
+H 2
+S sub/1
+H sub/2
+EOF

+# Good: capture output and check exit code
 test_expect_success 'setup' '
-   mkdir sub &&
-   touch ./1 ./2 sub/1 sub/2 &&
-   git add 1 2 sub/1 sub/2 &&
-   output=$(git ls-files -t)
-   echo "$output" | test_cmp expect.full -
-   if [ $? -ne 0 ]; then
-       exit 1
-   fi
+  mkdir sub &&
+  touch ./1 ./2 sub/1 sub/2 &&
+  git add 1 2 sub/1 sub/2 &&
+  git ls-files -t >actual &&
+  test_cmp expect.full actual
 '

+test_expect_success 'index is at version 2' '
+  test "$(git update-index --show-index-version)" = 2
+'
+
+# Good: pipe only after Git command
 test_expect_success 'update-index --skip-worktree' '
-   git update-index --skip-worktree 1 sub/1 &&
-   output=$(git ls-files -t)
-   echo "$output" | test_cmp expect.skip -
-   if [ $? -ne 0 ]; then
-       exit 1
-   fi
+  git update-index --skip-worktree 1 sub/1 &&
+  git ls-files -t | test_cmp expect.skip -
+'
+
+test_expect_success 'index is at version 3 after having some
skip-worktree entries' '
+  test "$(git update-index --show-index-version)" = 3
 '

 test_expect_success 'ls-files -t' '
-   output=$(git ls-files -t)
-   echo "$output" | test_cmp expect.skip -
-   if [ $? -ne 0 ]; then
-       exit 1
-   fi
+  git ls-files -t | test_cmp expect.skip -
 '

+# Good: separate command for exit code check
 test_expect_success 'update-index --no-skip-worktree' '
-   git update-index --no-skip-worktree 1 sub/1 &&
-   output=$(git ls-files -t)
-   echo "$output" | test_cmp expect.full -
-   if [ $? -ne 0 ]; then
-       exit 1
-   fi
+  git update-index --no-skip-worktree 1 sub/1
+  if [ $? -ne 0 ]; then
+    echo "Failed to update-index --no-skip-worktree"
+    exit 1
+  fi
+  git ls-files -t | test_cmp expect.full -
 '
+
+test_expect_success 'index version is back to 2 when there is no
skip-worktree entry' '
+  test "$(git update-index --show-index-version)" = 2
+'