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>

Pete Wyckoff committed Jan 26, 2013 at 22:11 UTC cfa96496bd9e7828c5626e2cd1353e9fb7d3d0c7
3 files changed +26 -3
t/lib-git-p4.sh
+22 -2
@@ -8,7 +8,8 @@ TEST_NO_CREATE_REPO=NoThanks
8
9 . ./test-lib.sh
10
11 -if ! test_have_prereq PYTHON; then
11 +if ! test_have_prereq PYTHON
12 +then
13 skip_all='skipping git p4 tests; python not available'
14 test_done
15 fi
@@ -17,6 +18,24 @@ fi
18 test_done
19 }
20
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 +
39 # Try to pick a unique port: guess a large number, then hope
40 # no more than one of each test is running.
41 #
@@ -32,7 +51,7 @@ P4EDITOR=:
51 export P4PORT P4CLIENT P4EDITOR
52
53 db="$TRASH_DIRECTORY/db"
35 -cli=$(test-path-utils real_path "$TRASH_DIRECTORY/cli")
54 +cli="$TRASH_DIRECTORY/cli"
55 git="$TRASH_DIRECTORY/git"
56 pidfile="$TRASH_DIRECTORY/p4d.pid"
57
@@ -122,6 +141,7 @@ client_view() {
141 Client: $P4CLIENT
142 Description: $P4CLIENT
143 Root: $cli
144 + AltRoots: $(native_path "$cli")
145 View:
146 EOF
147 printf "\t%s\n" "$@"
t/t9806-git-p4-options.sh
+1 -1
@@ -215,7 +215,7 @@ test_expect_success 'clone --use-client-spec' '
215 test_must_fail git p4 clone --dest="$git" --use-client-spec
216 ) &&
217 # build a different client
218 - cli2=$(test-path-utils real_path "$TRASH_DIRECTORY/cli2") &&
218 + cli2="$TRASH_DIRECTORY/cli2" &&
219 mkdir -p "$cli2" &&
220 test_when_finished "rmdir \"$cli2\"" &&
221 test_when_finished cleanup_git &&
t/test-lib.sh
+3
@@ -666,12 +666,14 @@ case $(uname -s) in
666 # backslashes in pathspec are converted to '/'
667 # exec does not inherit the PID
668 test_set_prereq MINGW
669 + test_set_prereq NOT_CYGWIN
670 test_set_prereq SED_STRIPS_CR
671 ;;
672 *CYGWIN*)
673 test_set_prereq POSIXPERM
674 test_set_prereq EXECKEEPSPID
675 test_set_prereq NOT_MINGW
676 + test_set_prereq CYGWIN
677 test_set_prereq SED_STRIPS_CR
678 ;;
679 *)
@@ -679,6 +681,7 @@ case $(uname -s) in
681 test_set_prereq BSLASHPSPEC
682 test_set_prereq EXECKEEPSPID
683 test_set_prereq NOT_MINGW
684 + test_set_prereq NOT_CYGWIN
685 ;;
686 esac
687