git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Aishwarya Narayanan <aishnana.03@gmail.com>
To: git@vger.kernel.org
Subject: GSoC 2024 [PATCH v2] Fix Git command exit code suppression in test script t2104-update-index-skip-worktree.sh
Date: Fri, 29 Mar 2024 00:17:25 +0530	[thread overview]
Message-ID: <CAHCXyj1hUVNNuCOgsNv4GJUi79_o9iWZDvV8Ocz3DodreYoL7g@mail.gmail.com> (raw)

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(-)

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
+'
+
+test_done
-- 
Sincerely,
Aishwarya Narayanan


             reply	other threads:[~2024-03-28 18:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-28 18:47 Aishwarya Narayanan [this message]
2024-04-02 11:06 ` GSoC 2024 [PATCH v2] Fix Git command exit code suppression in test script t2104-update-index-skip-worktree.sh Patrick Steinhardt
2024-04-02 11:56   ` Aishwarya Narayanan
2024-04-02 17:20   ` Eric Sunshine
2024-04-02 17:23     ` Patrick Steinhardt
2024-04-02 18:41       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHCXyj1hUVNNuCOgsNv4GJUi79_o9iWZDvV8Ocz3DodreYoL7g@mail.gmail.com \
    --to=aishnana.03@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).