git p4: cygwin p4 client does not mark read-only

There are some old versions of p4, compiled for cygwin, that treat read-only files differently. Normally, a file that is not open is read-only, meaning that "test -w" on the file is false. This works on unix, and it works on windows using the NT version of p4. The cygwin version of p4, though, changes the permissions, but does not set the windows read-only attribute, so "test -w" returns false. Notice this oddity and make the tests work, even on cygiwn. 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 e9df0f9c7a7fbaed924273d0a9b502171ed23b7c
3 files changed +27 -4
t/lib-git-p4.sh
+13
@@ -148,3 +148,16 @@ client_view() {
148 printf "\t%s\n" "$@"
149 ) | p4 client -i
150 }
151 +
152 +is_cli_file_writeable() {
153 + # cygwin version of p4 does not set read-only attr,
154 + # will be marked 444 but -w is true
155 + file="$1" &&
156 + if test_have_prereq CYGWIN && p4 -V | grep -q CYGWIN
157 + then
158 + stat=$(stat --format=%a "$file") &&
159 + test $stat = 644
160 + else
161 + test -w "$file"
162 + fi
163 +}
t/t9807-git-p4-submit.sh
+12 -2
@@ -17,6 +17,16 @@ test_expect_success 'init depot' '
17 )
18 '
19
20 +test_expect_failure 'is_cli_file_writeable function' '
21 + (
22 + cd "$cli" &&
23 + echo a >a &&
24 + is_cli_file_writeable a &&
25 + ! is_cli_file_writeable file1 &&
26 + rm a
27 + )
28 +'
29 +
30 test_expect_success 'submit with no client dir' '
31 test_when_finished cleanup_git &&
32 git p4 clone --dest="$git" //depot &&
@@ -200,7 +210,7 @@ test_expect_success 'submit copy' '
210 (
211 cd "$cli" &&
212 test_path_is_file file5.ta &&
203 - test ! -w file5.ta
213 + ! is_cli_file_writeable file5.ta
214 )
215 '
216
@@ -219,7 +229,7 @@ test_expect_success 'submit rename' '
229 cd "$cli" &&
230 test_path_is_missing file6.t &&
231 test_path_is_file file6.ta &&
222 - test ! -w file6.ta
232 + ! is_cli_file_writeable file6.ta
233 )
234 '
235
t/t9809-git-p4-client-view.sh
+2 -2
@@ -333,7 +333,7 @@ test_expect_success 'subdir clone, submit copy' '
333 (
334 cd "$cli" &&
335 test_path_is_file dir1/file11a &&
336 - test ! -w dir1/file11a
336 + ! is_cli_file_writeable dir1/file11a
337 )
338 '
339
@@ -353,7 +353,7 @@ test_expect_success 'subdir clone, submit rename' '
353 cd "$cli" &&
354 test_path_is_missing dir1/file13 &&
355 test_path_is_file dir1/file13a &&
356 - test ! -w dir1/file13a
356 + ! is_cli_file_writeable dir1/file13a
357 )
358 '
359