Skip to content

Commit 4b589e5

Browse files
committed
Merge branch 'js/mingw-tests'
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 ...
2 parents 9f03176 + 80ce6c2 commit 4b589e5

29 files changed

+197
-70
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
/test-dump-cache-tree
188188
/test-dump-split-index
189189
/test-dump-untracked-cache
190+
/test-fake-ssh
190191
/test-scrap-cache-tree
191192
/test-genrandom
192193
/test-hashmap

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ TEST_PROGRAMS_NEED_X += test-delta
583583
TEST_PROGRAMS_NEED_X += test-dump-cache-tree
584584
TEST_PROGRAMS_NEED_X += test-dump-split-index
585585
TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
586+
TEST_PROGRAMS_NEED_X += test-fake-ssh
586587
TEST_PROGRAMS_NEED_X += test-genrandom
587588
TEST_PROGRAMS_NEED_X += test-hashmap
588589
TEST_PROGRAMS_NEED_X += test-index-version

compat/mingw.c

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,39 @@ static inline time_t filetime_to_time_t(const FILETIME *ft)
454454
return (time_t)(filetime_to_hnsec(ft) / 10000000);
455455
}
456456

457+
/**
458+
* Verifies that safe_create_leading_directories() would succeed.
459+
*/
460+
static int has_valid_directory_prefix(wchar_t *wfilename)
461+
{
462+
int n = wcslen(wfilename);
463+
464+
while (n > 0) {
465+
wchar_t c = wfilename[--n];
466+
DWORD attributes;
467+
468+
if (!is_dir_sep(c))
469+
continue;
470+
471+
wfilename[n] = L'\0';
472+
attributes = GetFileAttributesW(wfilename);
473+
wfilename[n] = c;
474+
if (attributes == FILE_ATTRIBUTE_DIRECTORY ||
475+
attributes == FILE_ATTRIBUTE_DEVICE)
476+
return 1;
477+
if (attributes == INVALID_FILE_ATTRIBUTES)
478+
switch (GetLastError()) {
479+
case ERROR_PATH_NOT_FOUND:
480+
continue;
481+
case ERROR_FILE_NOT_FOUND:
482+
/* This implies parent directory exists. */
483+
return 1;
484+
}
485+
return 0;
486+
}
487+
return 1;
488+
}
489+
457490
/* We keep the do_lstat code in a separate function to avoid recursion.
458491
* When a path ends with a slash, the stat will fail with ENOENT. In
459492
* this case, we strip the trailing slashes and stat again.
@@ -514,6 +547,12 @@ static int do_lstat(int follow, const char *file_name, struct stat *buf)
514547
case ERROR_NOT_ENOUGH_MEMORY:
515548
errno = ENOMEM;
516549
break;
550+
case ERROR_PATH_NOT_FOUND:
551+
if (!has_valid_directory_prefix(wfilename)) {
552+
errno = ENOTDIR;
553+
break;
554+
}
555+
/* fallthru */
517556
default:
518557
errno = ENOENT;
519558
break;
@@ -1603,7 +1642,12 @@ int mingw_rename(const char *pold, const char *pnew)
16031642
if (gle == ERROR_ACCESS_DENIED &&
16041643
(attrs = GetFileAttributesW(wpnew)) != INVALID_FILE_ATTRIBUTES) {
16051644
if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
1606-
errno = EISDIR;
1645+
DWORD attrsold = GetFileAttributesW(wpold);
1646+
if (attrsold == INVALID_FILE_ATTRIBUTES ||
1647+
!(attrsold & FILE_ATTRIBUTE_DIRECTORY))
1648+
errno = EISDIR;
1649+
else if (!_wrmdir(wpnew))
1650+
goto repeat;
16071651
return -1;
16081652
}
16091653
if ((attrs & FILE_ATTRIBUTE_READONLY) &&
@@ -2047,6 +2091,37 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen)
20472091
return -1;
20482092
}
20492093

2094+
static void setup_windows_environment()
2095+
{
2096+
char *tmp = getenv("TMPDIR");
2097+
2098+
/* on Windows it is TMP and TEMP */
2099+
if (!tmp) {
2100+
if (!(tmp = getenv("TMP")))
2101+
tmp = getenv("TEMP");
2102+
if (tmp) {
2103+
setenv("TMPDIR", tmp, 1);
2104+
tmp = getenv("TMPDIR");
2105+
}
2106+
}
2107+
2108+
if (tmp) {
2109+
/*
2110+
* Convert all dir separators to forward slashes,
2111+
* to help shell commands called from the Git
2112+
* executable (by not mistaking the dir separators
2113+
* for escape characters).
2114+
*/
2115+
for (; *tmp; tmp++)
2116+
if (*tmp == '\\')
2117+
*tmp = '/';
2118+
}
2119+
2120+
/* simulate TERM to enable auto-color (see color.c) */
2121+
if (!getenv("TERM"))
2122+
setenv("TERM", "cygwin", 1);
2123+
}
2124+
20502125
/*
20512126
* Disable MSVCRT command line wildcard expansion (__getmainargs called from
20522127
* mingw startup code, see init.c in mingw runtime).
@@ -2125,19 +2200,7 @@ void mingw_startup()
21252200
qsort(environ, i, sizeof(char*), compareenv);
21262201

21272202
/* fix Windows specific environment settings */
2128-
2129-
/* on Windows it is TMP and TEMP */
2130-
if (!mingw_getenv("TMPDIR")) {
2131-
const char *tmp = mingw_getenv("TMP");
2132-
if (!tmp)
2133-
tmp = mingw_getenv("TEMP");
2134-
if (tmp)
2135-
setenv("TMPDIR", tmp, 1);
2136-
}
2137-
2138-
/* simulate TERM to enable auto-color (see color.c) */
2139-
if (!getenv("TERM"))
2140-
setenv("TERM", "cygwin", 1);
2203+
setup_windows_environment();
21412204

21422205
/* initialize critical section for waitpid pinfo_t list */
21432206
InitializeCriticalSection(&pinfo_cs);

config.mak.uname

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ else
560560
NO_R_TO_GCC_LINKER = YesPlease
561561
INTERNAL_QSORT = YesPlease
562562
HAVE_LIBCHARSET_H = YesPlease
563-
NO_GETTEXT = YesPlease
563+
NO_GETTEXT =
564+
USE_GETTEXT_SCHEME = fallthrough
564565
USE_LIBPCRE= YesPlease
565566
NO_CURL =
566567
USE_NED_ALLOCATOR = YesPlease

perl/Git.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ sub repository {
188188
};
189189

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

194195
# If --git-dir went ok, this shouldn't die either.

t/lib-git-daemon.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ then
2323
test_done
2424
fi
2525

26+
if test_have_prereq !PIPE
27+
then
28+
test_skip_or_die $GIT_TEST_GIT_DAEMON "file system does not support FIFOs"
29+
fi
30+
2631
LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-${this_test#t}}
2732

2833
GIT_DAEMON_PID=

t/t0008-ignores.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test_description=check-ignore
55
. ./test-lib.sh
66

77
init_vars () {
8-
global_excludes="$(pwd)/global-excludes"
8+
global_excludes="global-excludes"
99
}
1010

1111
enable_global_excludes () {

t/t0060-path-utils.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,21 @@ if test $rootoff = 2; then
3636
rootoff= # we are on Unix
3737
else
3838
rootoff=$(($rootoff-1))
39+
# In MSYS2, the root directory "/" is translated into a Windows
40+
# directory *with* trailing slash. Let's test for that and adjust
41+
# our expected longest ancestor length accordingly.
42+
case "$(test-path-utils print_path /)" in
43+
*/) rootslash=1;;
44+
*) rootslash=0;;
45+
esac
3946
fi
4047

4148
ancestor() {
4249
# We do some math with the expected ancestor length.
4350
expected=$3
4451
if test -n "$rootoff" && test "x$expected" != x-1; then
52+
expected=$(($expected-$rootslash))
53+
test $expected -lt 0 ||
4554
expected=$(($expected+$rootoff))
4655
fi
4756
test_expect_success "longest ancestor: $1 $2 => $expected" \

t/t1508-at-combinations.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ test_expect_success 'setup' '
3535
git checkout -b upstream-branch &&
3636
test_commit upstream-one &&
3737
test_commit upstream-two &&
38-
git checkout -b @/at-test &&
38+
if test_have_prereq !MINGW
39+
then
40+
git checkout -b @/at-test
41+
fi &&
3942
git checkout -b @@/at-test &&
4043
git checkout -b @at-test &&
4144
git checkout -b old-branch &&
@@ -64,6 +67,7 @@ check "@{-1}@{u}@{1}" commit master-one
6467
check "@" commit new-two
6568
check "@@{u}" ref refs/heads/upstream-branch
6669
check "@@/at-test" ref refs/heads/@@/at-test
70+
test_have_prereq MINGW ||
6771
check "@/at-test" ref refs/heads/@/at-test
6872
check "@at-test" ref refs/heads/@at-test
6973
nonsense "@{u}@{-1}"

t/t3300-funny-names.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tree, index, and tree objects.
1313

1414
HT=' '
1515

16+
test_have_prereq MINGW ||
1617
echo 2>/dev/null > "Name with an${HT}HT"
1718
if ! test -f "Name with an${HT}HT"
1819
then

0 commit comments

Comments
 (0)