git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Elijah Newren <newren@gmail.com>,
	Fabian Stelzer <fs@gigacodes.de>,
	Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH v1.1 2/19] t1010: fix unnoticed failure on Windows
Date: Sat, 11 Dec 2021 04:58:37 -0500	[thread overview]
Message-ID: <20211211095837.26387-1-sunshine@sunshineco.com> (raw)
In-Reply-To: <20211209051115.52629-1-sunshine@sunshineco.com>

On Microsoft Windows, a directory name should never end with a period.
Quoting from Microsoft documentation[1]:

    Do not end a file or directory name with a space or a period.
    Although the underlying file system may support such names, the
    Windows shell and user interface does not.

Naming a directory with a trailing period is indeed perilous:

    % git init foo
    % cd foo
    % mkdir a.
    % git status
    warning: could not open directory 'a./': No such file or directory

The t1010 "setup" test:

    for d in a a. a0
    do
        mkdir "$d" && echo "$d/one" >"$d/one" &&
        git add "$d"
    done &&

runs afoul of this Windows limitation, as can be observed when running
the test verbosely:

    error: open("a./one"): No such file or directory
    error: unable to index file 'a./one'
    fatal: adding files failed

The reason this problem has gone unnoticed for so long is twofold.
First, the failed `git add` is swallowed silently because the loop is
not terminated explicitly by `|| return 1` to signal the failure.
Second, none of the tests in this script care about the literal
directory names ("a", "a.", "a0") or the specific number of tree
entries. They care instead about the order of entries in the tree, and
that the tree synthesized in the index and created by `git write-tree`
matches the tree created by the output of `git ls-tree` fed into `git
mktree`, thus the absence of "a./one" has no impact on the tests.

Skipping these tests on Windows by, for instance, checking the
FUNNYNAMES predicate would avoid the problem, however, the funny-looking
name is not what is being tested here. Rather, the tests are about
checking that `git mktree` produces stable results for various input
conditions, such as when the input order is not consistent or when an
object is missing.

Therefore, resolve the problem simply by using a directory name which is
legal on Windows and sorts the same as "a.". While at it, add the
missing `|| return 1` to the loop body in order to catch this sort of
problem in the future.

[1]: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
---

This is a re-roll of patch 2/19 of es/test-chain-lint[1] to improve the
commit message in response to Elijah's review comments[2,3] since the v1
commit message was perhaps a bit too subtle[4].

Rather than spamming the list with a full v2 re-roll, I decided to
re-roll just this one patch with its minor commit message rewrite since
it was the only change requested, thus should be less of a burden on
reviewers, though perhaps a bit more burden on Junio (but it's such a
minor change that the original commit message is probably good enough
should Junio not pick up this single-patch re-roll).

[1]: https://lore.kernel.org/git/20211209051115.52629-1-sunshine@sunshineco.com/
[2]: https://lore.kernel.org/git/CABPp-BGBZ6_CqbUg3=sK2b4yELC5NHHyH68_df22n=t=hARH_g@mail.gmail.com/
[3]: https://lore.kernel.org/git/CABPp-BFM5ZbFAzVfvDE3=zm6Q4LN2fWthPP8WH5kbgVPSxomtA@mail.gmail.com/
[4]: https://lore.kernel.org/git/CAPig+cR0eKhz+ncWb4v9dSY0A03P+K0+WT90J2cBKvLqT8DXrA@mail.gmail.com/

Range-diff against v1:
1:  4e7d8e8c7e ! 1:  95d419ed90 t1010: fix unnoticed failure on Windows
    @@ Commit message
         The reason this problem has gone unnoticed for so long is twofold.
         First, the failed `git add` is swallowed silently because the loop is
         not terminated explicitly by `|| return 1` to signal the failure.
    -    Second, none of the tests in this script care about the actual directory
    -    names or even the number of tree entries. They care only that the tree
    -    synthesized in the index and created by `git write-tree` matches the
    -    tree created by the output of `git ls-tree` fed into `git mktree`, and
    -    the failure of `git add "a./one"` doesn't change that outcome.
    +    Second, none of the tests in this script care about the literal
    +    directory names ("a", "a.", "a0") or the specific number of tree
    +    entries. They care instead about the order of entries in the tree, and
    +    that the tree synthesized in the index and created by `git write-tree`
    +    matches the tree created by the output of `git ls-tree` fed into `git
    +    mktree`, thus the absence of "a./one" has no impact on the tests.
     
         Skipping these tests on Windows by, for instance, checking the
         FUNNYNAMES predicate would avoid the problem, however, the funny-looking
    @@ Commit message
         object is missing.
     
         Therefore, resolve the problem simply by using a directory name which is
    -    legal on Windows (i.e. "a-" rather than "a."). While at it, add the
    +    legal on Windows and sorts the same as "a.". While at it, add the
         missing `|| return 1` to the loop body in order to catch this sort of
         problem in the future.
     
         [1]: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
     
         Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
    +    Reviewed-by: Elijah Newren <newren@gmail.com>
     
      ## t/t1010-mktree.sh ##
     @@ t/t1010-mktree.sh: TEST_PASSES_SANITIZE_LEAK=true

 t/t1010-mktree.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t1010-mktree.sh b/t/t1010-mktree.sh
index 48bfad07ab..3c08194526 100755
--- a/t/t1010-mktree.sh
+++ b/t/t1010-mktree.sh
@@ -6,10 +6,10 @@ TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success setup '
-	for d in a a. a0
+	for d in a a- a0
 	do
 		mkdir "$d" && echo "$d/one" >"$d/one" &&
-		git add "$d"
+		git add "$d" || return 1
 	done &&
 	echo zero >one &&
 	git update-index --add --info-only one &&
-- 
2.34.1.397.gfae76fe5da


      parent reply	other threads:[~2021-12-11 10:00 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-09  5:10 [PATCH 00/19] tests: fix broken &&-chains & abort loops on error Eric Sunshine
2021-12-09  5:10 ` [PATCH 01/19] t/lib-pager: use sane_unset() to avoid breaking &&-chain Eric Sunshine
2021-12-09  5:10 ` [PATCH 02/19] t1010: fix unnoticed failure on Windows Eric Sunshine
2021-12-09 16:27   ` Elijah Newren
2021-12-09 16:45     ` Eric Sunshine
2021-12-09  5:10 ` [PATCH 03/19] t1020: avoid aborting entire test script when one test fails Eric Sunshine
2021-12-09  5:11 ` [PATCH 04/19] t4202: clarify intent by creating expected content less cleverly Eric Sunshine
2021-12-10  9:09   ` Jeff King
2021-12-09  5:11 ` [PATCH 05/19] t5516: drop unnecessary subshell and command invocation Eric Sunshine
2021-12-10  9:10   ` Jeff King
2021-12-09  5:11 ` [PATCH 06/19] t6300: make `%(raw:size) --shell` test more robust Eric Sunshine
2021-12-10  9:14   ` Jeff King
2021-12-09  5:11 ` [PATCH 07/19] t9107: use shell parameter expansion to avoid breaking &&-chain Eric Sunshine
2021-12-09  5:11 ` [PATCH 08/19] tests: simplify construction of large blocks of text Eric Sunshine
2021-12-09  5:11 ` [PATCH 09/19] tests: use test_write_lines() to generate line-oriented output Eric Sunshine
2021-12-10  9:22   ` Jeff King
2021-12-11  6:59     ` Eric Sunshine
2021-12-09  5:11 ` [PATCH 10/19] tests: fix broken &&-chains in compound statements Eric Sunshine
2021-12-09  5:11 ` [PATCH 11/19] tests: fix broken &&-chains in `$(...)` command substitutions Eric Sunshine
2021-12-09 16:44   ` Elijah Newren
2021-12-09 16:53     ` Eric Sunshine
2021-12-09 16:57       ` Elijah Newren
2021-12-10  9:27       ` Jeff King
2021-12-09  5:11 ` [PATCH 12/19] tests: fix broken &&-chains in `{...}` groups Eric Sunshine
2021-12-10  9:29   ` Jeff King
2021-12-11  7:14     ` Eric Sunshine
2021-12-10  9:38   ` Fabian Stelzer
2021-12-11  7:32     ` Eric Sunshine
2021-12-09  5:11 ` [PATCH 13/19] tests: apply modern idiom for signaling test failure Eric Sunshine
2021-12-10  9:32   ` Jeff King
2021-12-11  7:47     ` Eric Sunshine
2021-12-09  5:11 ` [PATCH 14/19] tests: apply modern idiom for exiting loop upon failure Eric Sunshine
2021-12-10  9:36   ` Jeff King
2021-12-09  5:11 ` [PATCH 15/19] tests: simplify by dropping unnecessary `for` loops Eric Sunshine
2021-12-09 16:50   ` Elijah Newren
2021-12-09  5:11 ` [PATCH 16/19] t0000-t3999: detect and signal failure within loop Eric Sunshine
2021-12-09  5:11 ` [PATCH 17/19] t4000-t4999: " Eric Sunshine
2021-12-10  9:53   ` Fabian Stelzer
2021-12-11  8:06     ` Eric Sunshine
2021-12-09  5:11 ` [PATCH 18/19] t5000-t5999: " Eric Sunshine
2021-12-09  5:11 ` [PATCH 19/19] t6000-t9999: " Eric Sunshine
2021-12-09 17:02 ` [PATCH 00/19] tests: fix broken &&-chains & abort loops on error Elijah Newren
2021-12-09 19:17   ` Eric Sunshine
2021-12-10  9:38     ` Jeff King
2021-12-10  9:57       ` Fabian Stelzer
2021-12-11  8:16         ` Eric Sunshine
2021-12-11  9:58 ` Eric Sunshine [this message]

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

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

  git send-email \
    --in-reply-to=20211211095837.26387-1-sunshine@sunshineco.com \
    --to=sunshine@sunshineco.com \
    --cc=fs@gigacodes.de \
    --cc=git@vger.kernel.org \
    --cc=newren@gmail.com \
    --cc=peff@peff.net \
    /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.
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 NNTP newsgroup(s).