]> git.ipfire.org Git - thirdparty/git.git/blame - t/lib-git-p4.sh
branch.c: Relax unnecessary requirement on upstream's remote ref name
[thirdparty/git.git] / t / lib-git-p4.sh
CommitLineData
fc002330 1#
6ab1d76c 2# Library code for git p4 tests
fc002330
PW
3#
4
c88015a4
PW
5# p4 tests never use the top-level repo; always build/clone into
6# a subdirectory called "$git"
7TEST_NO_CREATE_REPO=NoThanks
8
fc002330
PW
9. ./test-lib.sh
10
cfa96496
PW
11if ! test_have_prereq PYTHON
12then
6ab1d76c 13 skip_all='skipping git p4 tests; python not available'
fc002330
PW
14 test_done
15fi
16( p4 -h && p4d -h ) >/dev/null 2>&1 || {
6ab1d76c 17 skip_all='skipping git p4 tests; no p4 or p4d'
fc002330
PW
18 test_done
19}
20
cfa96496
PW
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.
28native_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
fc002330
PW
39# Try to pick a unique port: guess a large number, then hope
40# no more than one of each test is running.
41#
42# This does not handle the case where somebody else is running the
43# same tests and has chosen the same ports.
44testid=${this_test#t}
45git_p4_test_start=9800
46P4DPORT=$((10669 + ($testid - $git_p4_test_start)))
47
8c291350
PW
48P4PORT=localhost:$P4DPORT
49P4CLIENT=client
50P4EDITOR=:
51export P4PORT P4CLIENT P4EDITOR
fc002330
PW
52
53db="$TRASH_DIRECTORY/db"
cfa96496 54cli="$TRASH_DIRECTORY/cli"
fc002330
PW
55git="$TRASH_DIRECTORY/git"
56pidfile="$TRASH_DIRECTORY/p4d.pid"
57
58start_p4d() {
59 mkdir -p "$db" "$cli" "$git" &&
f89f35a9 60 rm -f "$pidfile" &&
fc002330 61 (
6492a104
PW
62 cd "$db" &&
63 {
64 p4d -q -p $P4DPORT &
65 echo $! >"$pidfile"
66 }
fc002330 67 ) &&
f89f35a9
PW
68
69 # This gives p4d a long time to start up, as it can be
70 # quite slow depending on the machine. Set this environment
71 # variable to something smaller to fail faster in, say,
72 # an automated test setup. If the p4d process dies, that
73 # will be caught with the "kill -0" check below.
74 i=${P4D_START_PATIENCE:-300}
75 pid=$(cat "$pidfile")
76 ready=
77 while test $i -gt 0
78 do
79 # succeed when p4 client commands start to work
80 if p4 info >/dev/null 2>&1
81 then
82 ready=true
83 break
84 fi
85 # fail if p4d died
86 kill -0 $pid 2>/dev/null || break
87 echo waiting for p4d to start
fc002330 88 sleep 1
f89f35a9
PW
89 i=$(( $i - 1 ))
90 done
91
92 if test -z "$ready"
93 then
94 # p4d failed to start
95 return 1
96 fi
97
98 # build a client
daa38f4a
PW
99 client_view "//depot/... //client/..." &&
100
f89f35a9 101 return 0
fc002330
PW
102}
103
104kill_p4d() {
105 pid=$(cat "$pidfile")
106 # it had better exist for the first kill
107 kill $pid &&
108 for i in 1 2 3 4 5 ; do
109 kill $pid >/dev/null 2>&1 || break
110 sleep 1
111 done &&
112 # complain if it would not die
113 test_must_fail kill $pid >/dev/null 2>&1 &&
114 rm -rf "$db" "$cli" "$pidfile"
115}
116
117cleanup_git() {
23a2666c
PW
118 rm -rf "$git" &&
119 mkdir "$git"
fc002330 120}
798d5980
PW
121
122marshal_dump() {
123 what=$1 &&
124 line=${2:-1} &&
125 cat >"$TRASH_DIRECTORY/marshal-dump.py" <<-EOF &&
126 import marshal
127 import sys
128 for i in range($line):
129 d = marshal.load(sys.stdin)
130 print d['$what']
131 EOF
132 "$PYTHON_PATH" "$TRASH_DIRECTORY/marshal-dump.py"
133}
d2018293
PW
134
135#
136# Construct a client with this list of View lines
137#
138client_view() {
139 (
140 cat <<-EOF &&
50038ba9
PW
141 Client: $P4CLIENT
142 Description: $P4CLIENT
d2018293 143 Root: $cli
cfa96496 144 AltRoots: $(native_path "$cli")
e93f8695 145 LineEnd: unix
d2018293
PW
146 View:
147 EOF
6112541b 148 printf "\t%s\n" "$@"
d2018293
PW
149 ) | p4 client -i
150}
e9df0f9c
PW
151
152is_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}