Skip to content

Commit cfa9649

Browse files
Pete Wyckoffgitster
authored andcommitted
git p4 test: translate windows paths for cygwin
Native windows binaries do not understand posix-like path mapping offered by cygwin. Convert paths to native using "cygpath --windows" before presenting them to p4d. This is done using the AltRoots mechanism of p4. Both the posix and windows forms are put in the client specification, allowing p4 to find its location by native path even though the environment reports a different PWD. Shell operations in tests will use the normal form of $cli, which will look like a posix path in cygwin, while p4 will use AltRoots to match against the windows form of the working directory. This mechanism also handles the symlink issue that was fixed in 23bd0c9 (git p4 test: use real_path to resolve p4 client symlinks, 2012-06-27). Now that every p4 client view has an AltRoots with the real_path in it, explicitly calculating the real_path elsewhere is not necessary. Thanks-to: Sebastian Schuberth <sschuberth@gmail.com> Thanks-to: Johannes Sixt <j6t@kdbg.org> fixup! git p4 test: translate windows paths for cygwin Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6492a10 commit cfa9649

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

t/lib-git-p4.sh

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ TEST_NO_CREATE_REPO=NoThanks
88

99
. ./test-lib.sh
1010

11-
if ! test_have_prereq PYTHON; then
11+
if ! test_have_prereq PYTHON
12+
then
1213
skip_all='skipping git p4 tests; python not available'
1314
test_done
1415
fi
@@ -17,6 +18,24 @@ fi
1718
test_done
1819
}
1920

21+
# On cygwin, the NT version of Perforce can be used. When giving
22+
# it paths, either on the command-line or in client specifications,
23+
# be sure to use the native windows form.
24+
#
25+
# Older versions of perforce were available compiled natively for
26+
# cygwin. Those do not accept native windows paths, so make sure
27+
# not to convert for them.
28+
native_path() {
29+
path="$1" &&
30+
if test_have_prereq CYGWIN && ! p4 -V | grep -q CYGWIN
31+
then
32+
path=$(cygpath --windows "$path")
33+
else
34+
path=$(test-path-utils real_path "$path")
35+
fi &&
36+
echo "$path"
37+
}
38+
2039
# Try to pick a unique port: guess a large number, then hope
2140
# no more than one of each test is running.
2241
#
@@ -32,7 +51,7 @@ P4EDITOR=:
3251
export P4PORT P4CLIENT P4EDITOR
3352

3453
db="$TRASH_DIRECTORY/db"
35-
cli=$(test-path-utils real_path "$TRASH_DIRECTORY/cli")
54+
cli="$TRASH_DIRECTORY/cli"
3655
git="$TRASH_DIRECTORY/git"
3756
pidfile="$TRASH_DIRECTORY/p4d.pid"
3857

@@ -122,6 +141,7 @@ client_view() {
122141
Client: $P4CLIENT
123142
Description: $P4CLIENT
124143
Root: $cli
144+
AltRoots: $(native_path "$cli")
125145
View:
126146
EOF
127147
printf "\t%s\n" "$@"

t/t9806-git-p4-options.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ test_expect_success 'clone --use-client-spec' '
215215
test_must_fail git p4 clone --dest="$git" --use-client-spec
216216
) &&
217217
# build a different client
218-
cli2=$(test-path-utils real_path "$TRASH_DIRECTORY/cli2") &&
218+
cli2="$TRASH_DIRECTORY/cli2" &&
219219
mkdir -p "$cli2" &&
220220
test_when_finished "rmdir \"$cli2\"" &&
221221
test_when_finished cleanup_git &&

t/test-lib.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,19 +666,22 @@ case $(uname -s) in
666666
# backslashes in pathspec are converted to '/'
667667
# exec does not inherit the PID
668668
test_set_prereq MINGW
669+
test_set_prereq NOT_CYGWIN
669670
test_set_prereq SED_STRIPS_CR
670671
;;
671672
*CYGWIN*)
672673
test_set_prereq POSIXPERM
673674
test_set_prereq EXECKEEPSPID
674675
test_set_prereq NOT_MINGW
676+
test_set_prereq CYGWIN
675677
test_set_prereq SED_STRIPS_CR
676678
;;
677679
*)
678680
test_set_prereq POSIXPERM
679681
test_set_prereq BSLASHPSPEC
680682
test_set_prereq EXECKEEPSPID
681683
test_set_prereq NOT_MINGW
684+
test_set_prereq NOT_CYGWIN
682685
;;
683686
esac
684687

0 commit comments

Comments
 (0)