Skip to content

Commit

Permalink
Merge branch 'js/mingw-tests'
Browse files Browse the repository at this point in the history
Test scripts have been updated to remove assumptions that are not
portable between Git for POSIX and Git for Windows, or to skip ones
with expectations that are not satisfiable on Git for Windows.

* js/mingw-tests: (21 commits)
  gitignore: ignore generated test-fake-ssh executable
  mingw: do not bother to test funny file names
  mingw: skip a test in t9130 that cannot pass on Windows
  mingw: handle the missing POSIXPERM prereq in t9124
  mingw: avoid illegal filename in t9118
  mingw: mark t9100's test cases with appropriate prereqs
  t0008: avoid absolute path
  mingw: work around pwd issues in the tests
  mingw: fix t9700's assumption about directory separators
  mingw: skip test in t1508 that fails due to path conversion
  tests: turn off git-daemon tests if FIFOs are not available
  mingw: disable mkfifo-based tests
  mingw: accomodate t0060-path-utils for MSYS2
  mingw: fix t5601-clone.sh
  mingw: let lstat() fail with errno == ENOTDIR when appropriate
  mingw: try to delete target directory before renaming
  mingw: prepare the TMPDIR environment variable for shell scripts
  mingw: factor out Windows specific environment setup
  Git.pm: stop assuming that absolute paths start with a slash
  mingw: do not trust MSYS2's MinGW gettext.sh
  ...
  • Loading branch information
Junio C Hamano committed Feb 17, 2016
2 parents 9f03176 + 80ce6c2 commit 4b589e5
Show file tree
Hide file tree
Showing 29 changed files with 197 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
/test-dump-cache-tree
/test-dump-split-index
/test-dump-untracked-cache
/test-fake-ssh
/test-scrap-cache-tree
/test-genrandom
/test-hashmap
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ TEST_PROGRAMS_NEED_X += test-delta
TEST_PROGRAMS_NEED_X += test-dump-cache-tree
TEST_PROGRAMS_NEED_X += test-dump-split-index
TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
TEST_PROGRAMS_NEED_X += test-fake-ssh
TEST_PROGRAMS_NEED_X += test-genrandom
TEST_PROGRAMS_NEED_X += test-hashmap
TEST_PROGRAMS_NEED_X += test-index-version
Expand Down
91 changes: 77 additions & 14 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,39 @@ static inline time_t filetime_to_time_t(const FILETIME *ft)
return (time_t)(filetime_to_hnsec(ft) / 10000000);
}

/**
* Verifies that safe_create_leading_directories() would succeed.
*/
static int has_valid_directory_prefix(wchar_t *wfilename)
{
int n = wcslen(wfilename);

while (n > 0) {
wchar_t c = wfilename[--n];
DWORD attributes;

if (!is_dir_sep(c))
continue;

wfilename[n] = L'\0';
attributes = GetFileAttributesW(wfilename);
wfilename[n] = c;
if (attributes == FILE_ATTRIBUTE_DIRECTORY ||
attributes == FILE_ATTRIBUTE_DEVICE)
return 1;
if (attributes == INVALID_FILE_ATTRIBUTES)
switch (GetLastError()) {
case ERROR_PATH_NOT_FOUND:
continue;
case ERROR_FILE_NOT_FOUND:
/* This implies parent directory exists. */
return 1;
}
return 0;
}
return 1;
}

/* We keep the do_lstat code in a separate function to avoid recursion.
* When a path ends with a slash, the stat will fail with ENOENT. In
* this case, we strip the trailing slashes and stat again.
Expand Down Expand Up @@ -514,6 +547,12 @@ static int do_lstat(int follow, const char *file_name, struct stat *buf)
case ERROR_NOT_ENOUGH_MEMORY:
errno = ENOMEM;
break;
case ERROR_PATH_NOT_FOUND:
if (!has_valid_directory_prefix(wfilename)) {
errno = ENOTDIR;
break;
}
/* fallthru */
default:
errno = ENOENT;
break;
Expand Down Expand Up @@ -1603,7 +1642,12 @@ int mingw_rename(const char *pold, const char *pnew)
if (gle == ERROR_ACCESS_DENIED &&
(attrs = GetFileAttributesW(wpnew)) != INVALID_FILE_ATTRIBUTES) {
if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
errno = EISDIR;
DWORD attrsold = GetFileAttributesW(wpold);
if (attrsold == INVALID_FILE_ATTRIBUTES ||
!(attrsold & FILE_ATTRIBUTE_DIRECTORY))
errno = EISDIR;
else if (!_wrmdir(wpnew))
goto repeat;
return -1;
}
if ((attrs & FILE_ATTRIBUTE_READONLY) &&
Expand Down Expand Up @@ -2047,6 +2091,37 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen)
return -1;
}

static void setup_windows_environment()
{
char *tmp = getenv("TMPDIR");

/* on Windows it is TMP and TEMP */
if (!tmp) {
if (!(tmp = getenv("TMP")))
tmp = getenv("TEMP");
if (tmp) {
setenv("TMPDIR", tmp, 1);
tmp = getenv("TMPDIR");
}
}

if (tmp) {
/*
* Convert all dir separators to forward slashes,
* to help shell commands called from the Git
* executable (by not mistaking the dir separators
* for escape characters).
*/
for (; *tmp; tmp++)
if (*tmp == '\\')
*tmp = '/';
}

/* simulate TERM to enable auto-color (see color.c) */
if (!getenv("TERM"))
setenv("TERM", "cygwin", 1);
}

/*
* Disable MSVCRT command line wildcard expansion (__getmainargs called from
* mingw startup code, see init.c in mingw runtime).
Expand Down Expand Up @@ -2125,19 +2200,7 @@ void mingw_startup()
qsort(environ, i, sizeof(char*), compareenv);

/* fix Windows specific environment settings */

/* on Windows it is TMP and TEMP */
if (!mingw_getenv("TMPDIR")) {
const char *tmp = mingw_getenv("TMP");
if (!tmp)
tmp = mingw_getenv("TEMP");
if (tmp)
setenv("TMPDIR", tmp, 1);
}

/* simulate TERM to enable auto-color (see color.c) */
if (!getenv("TERM"))
setenv("TERM", "cygwin", 1);
setup_windows_environment();

/* initialize critical section for waitpid pinfo_t list */
InitializeCriticalSection(&pinfo_cs);
Expand Down
3 changes: 2 additions & 1 deletion config.mak.uname
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ else
NO_R_TO_GCC_LINKER = YesPlease
INTERNAL_QSORT = YesPlease
HAVE_LIBCHARSET_H = YesPlease
NO_GETTEXT = YesPlease
NO_GETTEXT =
USE_GETTEXT_SCHEME = fallthrough
USE_LIBPCRE= YesPlease
NO_CURL =
USE_NED_ALLOCATOR = YesPlease
Expand Down
3 changes: 2 additions & 1 deletion perl/Git.pm
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ sub repository {
};

if ($dir) {
$dir =~ m#^/# or $dir = $opts{Directory} . '/' . $dir;
_verify_require();
File::Spec->file_name_is_absolute($dir) or $dir = $opts{Directory} . '/' . $dir;
$opts{Repository} = abs_path($dir);

# If --git-dir went ok, this shouldn't die either.
Expand Down
5 changes: 5 additions & 0 deletions t/lib-git-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ then
test_done
fi

if test_have_prereq !PIPE
then
test_skip_or_die $GIT_TEST_GIT_DAEMON "file system does not support FIFOs"
fi

LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-${this_test#t}}

GIT_DAEMON_PID=
Expand Down
2 changes: 1 addition & 1 deletion t/t0008-ignores.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test_description=check-ignore
. ./test-lib.sh

init_vars () {
global_excludes="$(pwd)/global-excludes"
global_excludes="global-excludes"
}

enable_global_excludes () {
Expand Down
9 changes: 9 additions & 0 deletions t/t0060-path-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,21 @@ if test $rootoff = 2; then
rootoff= # we are on Unix
else
rootoff=$(($rootoff-1))
# In MSYS2, the root directory "/" is translated into a Windows
# directory *with* trailing slash. Let's test for that and adjust
# our expected longest ancestor length accordingly.
case "$(test-path-utils print_path /)" in
*/) rootslash=1;;
*) rootslash=0;;
esac
fi

ancestor() {
# We do some math with the expected ancestor length.
expected=$3
if test -n "$rootoff" && test "x$expected" != x-1; then
expected=$(($expected-$rootslash))
test $expected -lt 0 ||
expected=$(($expected+$rootoff))
fi
test_expect_success "longest ancestor: $1 $2 => $expected" \
Expand Down
6 changes: 5 additions & 1 deletion t/t1508-at-combinations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ test_expect_success 'setup' '
git checkout -b upstream-branch &&
test_commit upstream-one &&
test_commit upstream-two &&
git checkout -b @/at-test &&
if test_have_prereq !MINGW
then
git checkout -b @/at-test
fi &&
git checkout -b @@/at-test &&
git checkout -b @at-test &&
git checkout -b old-branch &&
Expand Down Expand Up @@ -64,6 +67,7 @@ check "@{-1}@{u}@{1}" commit master-one
check "@" commit new-two
check "@@{u}" ref refs/heads/upstream-branch
check "@@/at-test" ref refs/heads/@@/at-test
test_have_prereq MINGW ||
check "@/at-test" ref refs/heads/@/at-test
check "@at-test" ref refs/heads/@at-test
nonsense "@{u}@{-1}"
Expand Down
1 change: 1 addition & 0 deletions t/t3300-funny-names.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tree, index, and tree objects.

HT=' '

test_have_prereq MINGW ||
echo 2>/dev/null > "Name with an${HT}HT"
if ! test -f "Name with an${HT}HT"
then
Expand Down
2 changes: 1 addition & 1 deletion t/t3600-rm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test_expect_success \
git add -- foo bar baz 'space embedded' -q &&
git commit -m 'add normal files'"

if touch -- 'tab embedded' 'newline
if test_have_prereq !MINGW && touch -- 'tab embedded' 'newline
embedded' 2>/dev/null
then
test_set_prereq FUNNYNAMES
Expand Down
2 changes: 1 addition & 1 deletion t/t3703-add-magic-pathspec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cat >expected <<EOF
add 'sub/foo'
EOF

if mkdir ":" 2>/dev/null
if test_have_prereq !MINGW && mkdir ":" 2>/dev/null
then
test_set_prereq COLON_DIR
fi
Expand Down
1 change: 1 addition & 0 deletions t/t3902-quoted.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ GN='純'
HT=' '
DQ='"'

test_have_prereq MINGW ||
echo foo 2>/dev/null > "Name and an${HT}HT"
if ! test -f "Name and an${HT}HT"
then
Expand Down
1 change: 1 addition & 0 deletions t/t4016-diff-quote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ P1='pathname with HT'
P2='pathname with SP'
P3='pathname
with LF'
test_have_prereq !MINGW &&
echo 2>/dev/null >"$P1" && test -f "$P1" && rm -f "$P1" || {
skip_all='Your filesystem does not allow tabs in filenames'
test_done
Expand Down
3 changes: 2 additions & 1 deletion t/t4135-apply-weird-filenames.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ test_expect_success 'setup' '
test_when_finished "rm -f \"tab embedded.txt\"" &&
test_when_finished "rm -f '\''\"quoteembedded\".txt'\''" &&
if touch -- "tab embedded.txt" '\''"quoteembedded".txt'\''
if test_have_prereq !MINGW &&
touch -- "tab embedded.txt" '\''"quoteembedded".txt'\''
then
test_set_prereq FUNNYNAMES
fi
Expand Down
18 changes: 8 additions & 10 deletions t/t5601-clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ test_description=clone

. ./test-lib.sh

X=
test_have_prereq !MINGW || X=.exe

test_expect_success setup '
rm -fr .git &&
Expand Down Expand Up @@ -305,23 +308,18 @@ test_expect_success 'clone checking out a tag' '

setup_ssh_wrapper () {
test_expect_success 'setup ssh wrapper' '
write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF &&
echo >>"$TRASH_DIRECTORY/ssh-output" "ssh: $*" &&
# throw away all but the last argument, which should be the
# command
while test $# -gt 1; do shift; done
eval "$1"
EOF
GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
cp "$GIT_BUILD_DIR/test-fake-ssh$X" \
"$TRASH_DIRECTORY/ssh-wrapper$X" &&
GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper$X" &&
export GIT_SSH &&
export TRASH_DIRECTORY &&
>"$TRASH_DIRECTORY"/ssh-output
'
}

copy_ssh_wrapper_as () {
cp "$TRASH_DIRECTORY/ssh-wrapper" "$1" &&
GIT_SSH="$1" &&
cp "$TRASH_DIRECTORY/ssh-wrapper$X" "${1%$X}$X" &&
GIT_SSH="${1%$X}$X" &&
export GIT_SSH
}

Expand Down
14 changes: 7 additions & 7 deletions t/t7800-difftool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,11 @@ EOF
test_expect_success PERL,SYMLINKS 'difftool --dir-diff --symlink without unstaged changes' '
cat >expect <<-EOF &&
file
$(pwd)/file
$PWD/file
file2
$(pwd)/file2
$PWD/file2
sub/sub
$(pwd)/sub/sub
$PWD/sub/sub
EOF
git difftool --dir-diff --symlink \
--extcmd "./.git/CHECK_SYMLINKS" branch HEAD &&
Expand All @@ -448,14 +448,14 @@ EOF
run_dir_diff_test 'difftool --dir-diff syncs worktree with unstaged change' '
test_when_finished git reset --hard &&
echo "orig content" >file &&
git difftool -d $symlinks --extcmd "$(pwd)/modify-right-file" branch &&
git difftool -d $symlinks --extcmd "$PWD/modify-right-file" branch &&
echo "new content" >expect &&
test_cmp expect file
'

run_dir_diff_test 'difftool --dir-diff syncs worktree without unstaged change' '
test_when_finished git reset --hard &&
git difftool -d $symlinks --extcmd "$(pwd)/modify-right-file" branch &&
git difftool -d $symlinks --extcmd "$PWD/modify-right-file" branch &&
echo "new content" >expect &&
test_cmp expect file
'
Expand All @@ -466,7 +466,7 @@ EOF

test_expect_success PERL 'difftool --no-symlinks does not overwrite working tree file ' '
echo "orig content" >file &&
git difftool --dir-diff --no-symlinks --extcmd "$(pwd)/modify-file" branch &&
git difftool --dir-diff --no-symlinks --extcmd "$PWD/modify-file" branch &&
echo "new content" >expect &&
test_cmp expect file
'
Expand All @@ -482,7 +482,7 @@ test_expect_success PERL 'difftool --no-symlinks detects conflict ' '
TMPDIR=$TRASH_DIRECTORY &&
export TMPDIR &&
echo "orig content" >file &&
test_must_fail git difftool --dir-diff --no-symlinks --extcmd "$(pwd)/modify-both-files" branch &&
test_must_fail git difftool --dir-diff --no-symlinks --extcmd "$PWD/modify-both-files" branch &&
echo "wt content" >expect &&
test_cmp expect file &&
echo "tmp content" >expect &&
Expand Down
Loading

0 comments on commit 4b589e5

Please sign in to comment.