git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] t7400: add BSLASHPSPEC prerequisite to 'add with \\ in path'

From
Johannes Sixt <j6t@kdbg.org>
Date
Apr 29, 2017, 06:46 UTC
Message-ID
<f9dfd9b4-e753-1a53-175e-8f20fe904501@kdbg.org>
In-Reply-To
<a575542a-e5b6-389f-e240-d5ac5a4b4107@ramsayjones.plus.com>
Am 29.04.2017 um 02:15 schrieb Ramsay Jones:
Show 30 quoted lines
>
>
> On 28/04/17 20:54, Johannes Sixt wrote:
>> Am 28.04.2017 um 05:09 schrieb Junio C Hamano:
>>> Ramsay Jones <ramsay@ramsayjones.plus.com> writes:
>>>
>>>> Commit cf9e55f494 ("submodule: prevent backslash expantion in submodule
>>>> names", 07-04-2017) added a test which creates a git repository with
>>>> some backslash characters in the name. This test cannot work on windows,
>>>> since the backslash is used as the directory separator. In order to
>>>> suppress this test on cygwin, MinGW and Git for Windows, we add the
>>>> BSLASHPSPEC prerequisite. (see also commits 6fd1106aa4 and c51c0da222).
>>
>> First, let me say that meaning of BSLASHPSPEC was
>> "keeps backslaches in pathspec arguments" originally,
>> but it apparently changed meaning since then.
>
> Indeed. I started to give some of the history in the commit message, but
> it was nearly 3am, so I punted with the 'see also commits 6fd1106aa4 and
> c51c0da222' ... ;-)
>
>> t7400.20 does not fail for the MinGW port because the
>> test case only operates on the file system, but never
>> checks whether an entry 'sub\with\backslash' is present
>> in the index.
>
> Ah, OK. I only looked at my (64-bit) MSYS2 build, which fails
> exactly the same as cygwin. Hmm, wait, let me just rebuild on
> MinGW64 ... indeed it passes (well it passes t7400.20, but it
> fails on t7400.11, 61, 63, 87 and 89)!

I don't observe these failures. Are you using a vanila MSYS2 environment? The exact failure modes would be interesting, if you want to hear "Ah, Git for Windows does this and that to make this work". ;)

Show 50 quoted lines
>> I assume the test fails right at 'git init' under Cygwin?
>
> Indeed. Also on MSYS2 (exactly as on cygwin):
>
> ramsay@satellite  MSYS $ ./t7400-submodule-basic.sh -i -v
>
> ...
>
> ok 19 - submodule add with ./, /.. and // in path
>
> expecting success:
>         test_when_finished "rm -rf parent sub\\with\\backslash" &&
>
>         # Initialize a repo with a backslash in its name
>         git init sub\\with\\backslash &&
>         touch sub\\with\\backslash/empty.file &&
>         git -C sub\\with\\backslash add empty.file &&
>         git -C sub\\with\\backslash commit -m "Added empty.file" &&
>
>         # Add that repository as a submodule
>         git init parent &&
>         git -C parent submodule add ../sub\\with\\backslash
>
> fatal: cannot mkdir sub\with\backslash: No such file or directory
> not ok 20 - submodule add with \\ in path
> #
> #               test_when_finished "rm -rf parent sub\\with\\backslash" &&
> #
> #               # Initialize a repo with a backslash in its name
> #               git init sub\\with\\backslash &&
> #               touch sub\\with\\backslash/empty.file &&
> #               git -C sub\\with\\backslash add empty.file &&
> #               git -C sub\\with\\backslash commit -m "Added empty.file" &&
> #
> #               # Add that repository as a submodule
> #               git init parent &&
> #               git -C parent submodule add ../sub\\with\\backslash
> #
> ramsay@satellite  MSYS $
>
> ramsay@satellite  MSYS $ cd trash\ directory.t7400-submodule-basic/
>
> ramsay@satellite  MSYS $ ls
> a       addtest/         empty   expect-head   head   head-sha1  untracked
> actual  addtest-ignore/  expect  expect-heads  heads  t          z
>
> ramsay@satellite  MSYS $ git init sub\\with\\backslash
> fatal: cannot mkdir sub\with\backslash: No such file or directory
>
> ramsay@satellite  MSYS $ mkdir -p sub\\with
OK: git init calls mkdir("sub\\with\\backslash"), which does not create 
the missing directories automatically. Therefore, this mkdir helps. In 
the next call, the OS functions behind mkdir simply take the backslashes 
as directory separators:
Show 18 quoted lines
>
> ramsay@satellite  MSYS $ git init sub\\with\\backslash
> Initialized empty Git repository in /home/ramsay/git/t/trash directory.t7400-submodule-basic/sub/with/backslash/.git/
>
> ramsay@satellite  MSYS $ touch sub\\with\\backslash/empty.file
> ramsay@satellite  MSYS $ git -C sub\\with\\backslash add empty.file
> ramsay@satellite  MSYS $ git -C sub\\with\\backslash commit -m "Added empty.file"
> [master (root-commit) 6fde90b] Added empty.file
>  1 file changed, 0 insertions(+), 0 deletions(-)
>  create mode 100644 empty.file
>
> ramsay@satellite  MSYS $ git init parent
> Initialized empty Git repository in /home/ramsay/git/t/trash directory.t7400-submodule-basic/parent/.git/
>
> ramsay@satellite  MSYS $ git -C parent submodule add ../sub\\with\\backslash
> Cloning into '/home/ramsay/git/t/trash directory.t7400-submodule-basic/parent/sub/with/backslash'...
> done.
> fatal: Not a git repository: /home/ramsay/git/t/trash directory.t7400-submodule-basic/parent/sub\with\backslash/../.git/modules/sub/with/backslash

MSYS git does not know that the backslash is a directory separator. Hence, it constructs a path with only a single .. component thinking that this walks above sub\with\backslash to end up in parent/; but the underlying OS operation interprets the backslashes as directory separator and ends up in parent/sub\with\. Of coures, no .git directory is at this point, hence the failure.

MinGW git, however, knows about the backslash's meaning and constructs a path containing ../../.. to walk sufficiently high up in the hierarchy and finds the .git directory.

-- Hannes
Previous: Ramsay JonesNext: Johannes Schindelin
Message 5 of 9 in “t7400: add BSLASHPSPEC prerequisite to 'add with \\ in path'”
  1. t7400: add BSLASHPSPEC prerequisite to 'add with \\ in path'Ramsay Jones, Apr 28, 2017
  2. Junio C HamanoApr 28, 2017
  3. Johannes SixtApr 28, 2017
  4. Ramsay JonesApr 29, 2017
  5. Johannes SixtApr 29, 2017
  6. Johannes SchindelinApr 29, 2017
  7. Ramsay JonesApr 30, 2017
  8. Johannes SchindelinMay 1, 2017
  9. Ramsay JonesApr 30, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.