1
0
mirror of https://github.com/git/git synced 2024-07-05 00:58:49 +00:00
git/t/t5580-clone-push-unc.sh

78 lines
1.7 KiB
Bash
Raw Normal View History

#!/bin/sh
test_description='various Windows-only path tests'
. ./test-lib.sh
if test_have_prereq CYGWIN
then
alias winpwd='cygpath -aw .'
elif test_have_prereq MINGW
then
alias winpwd=pwd
else
skip_all='skipping Windows-only path tests'
test_done
fi
UNCPATH="$(winpwd)"
case "$UNCPATH" in
[A-Z]:*)
# Use administrative share e.g. \\localhost\C$\git-sdk-64\usr\src\git
# (we use forward slashes here because MSYS2 and Git accept them, and
# they are easier on the eyes)
UNCPATH="//localhost/${UNCPATH%%:*}\$/${UNCPATH#?:}"
test -d "$UNCPATH" || {
skip_all='could not access administrative share; skipping'
test_done
}
;;
*)
skip_all='skipping UNC path tests, cannot determine current path as UNC'
test_done
;;
esac
test_expect_success setup '
test_commit initial
'
test_expect_success clone '
git clone "file://$UNCPATH" clone
'
mingw: special-case arguments to `sh` The MSYS2 runtime does its best to emulate the command-line wildcard expansion and de-quoting which would be performed by the calling Unix shell on Unix systems. Those Unix shell quoting rules differ from the quoting rules applying to Windows' cmd and Powershell, making it a little awkward to quote command-line parameters properly when spawning other processes. In particular, git.exe passes arguments to subprocesses that are *not* intended to be interpreted as wildcards, and if they contain backslashes, those are not to be interpreted as escape characters, e.g. when passing Windows paths. Note: this is only a problem when calling MSYS2 executables, not when calling MINGW executables such as git.exe. However, we do call MSYS2 executables frequently, most notably when setting the use_shell flag in the child_process structure. There is no elegant way to determine whether the .exe file to be executed is an MSYS2 program or a MINGW one. But since the use case of passing a command line through the shell is so prevalent, we need to work around this issue at least when executing sh.exe. Let's introduce an ugly, hard-coded test whether argv[0] is "sh", and whether it refers to the MSYS2 Bash, to determine whether we need to quote the arguments differently than usual. That still does not fix the issue completely, but at least it is something. Incidentally, this also fixes the problem where `git clone \\server\repo` failed due to incorrect handling of the backslashes when handing the path to the git-upload-pack process. Further, we need to take care to quote not only whitespace and backslashes, but also curly brackets. As aliases frequently go through the MSYS2 Bash, and as aliases frequently get parameters such as HEAD@{yesterday}, this is really important. As an early version of this patch broke this, let's make sure that this does not regress by adding a test case for that. Helped-by: Kim Gybels <kgybels@infogroep.be> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-17 20:14:48 +00:00
test_expect_success 'clone with backslashed path' '
BACKSLASHED="$(echo "$UNCPATH" | tr / \\\\)" &&
git clone "$BACKSLASHED" backslashed
'
test_expect_success push '
(
cd clone &&
git checkout -b to-push &&
test_commit to-push &&
git push origin HEAD
) &&
rev="$(git -C clone rev-parse --verify refs/heads/to-push)" &&
test "$rev" = "$(git rev-parse --verify refs/heads/to-push)"
'
test_expect_success MINGW 'remote nick cannot contain backslashes' '
BACKSLASHED="$(winpwd | tr / \\\\)" &&
git ls-remote "$BACKSLASHED" >out 2>err &&
test_i18ngrep ! "unable to access" err
'
test_expect_success 'unc alternates' '
tree="$(git rev-parse HEAD:)" &&
mkdir test-unc-alternate &&
(
cd test-unc-alternate &&
git init &&
test_must_fail git show $tree &&
echo "$UNCPATH/.git/objects" >.git/objects/info/alternates &&
git show $tree
)
'
test_done