Skip to content

Commit e9df0f9

Browse files
Pete Wyckoffgitster
authored andcommitted
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>
1 parent 9d01ae9 commit e9df0f9

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

t/lib-git-p4.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,16 @@ client_view() {
148148
printf "\t%s\n" "$@"
149149
) | p4 client -i
150150
}
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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ test_expect_success 'init depot' '
1717
)
1818
'
1919

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+
2030
test_expect_success 'submit with no client dir' '
2131
test_when_finished cleanup_git &&
2232
git p4 clone --dest="$git" //depot &&
@@ -200,7 +210,7 @@ test_expect_success 'submit copy' '
200210
(
201211
cd "$cli" &&
202212
test_path_is_file file5.ta &&
203-
test ! -w file5.ta
213+
! is_cli_file_writeable file5.ta
204214
)
205215
'
206216

@@ -219,7 +229,7 @@ test_expect_success 'submit rename' '
219229
cd "$cli" &&
220230
test_path_is_missing file6.t &&
221231
test_path_is_file file6.ta &&
222-
test ! -w file6.ta
232+
! is_cli_file_writeable file6.ta
223233
)
224234
'
225235

t/t9809-git-p4-client-view.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ test_expect_success 'subdir clone, submit copy' '
333333
(
334334
cd "$cli" &&
335335
test_path_is_file dir1/file11a &&
336-
test ! -w dir1/file11a
336+
! is_cli_file_writeable dir1/file11a
337337
)
338338
'
339339

@@ -353,7 +353,7 @@ test_expect_success 'subdir clone, submit rename' '
353353
cd "$cli" &&
354354
test_path_is_missing dir1/file13 &&
355355
test_path_is_file dir1/file13a &&
356-
test ! -w dir1/file13a
356+
! is_cli_file_writeable dir1/file13a
357357
)
358358
'
359359

0 commit comments

Comments
 (0)