]> git.ipfire.org Git - thirdparty/git.git/blame - t/lib-git-p4.sh
Sync with 2.3.7
[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
0055b56e 50P4USER=author
0cf1b72a 51P4EDITOR=true
79946031 52unset P4CHARSET
0055b56e 53export P4PORT P4CLIENT P4USER P4EDITOR P4CHARSET
fc002330
PW
54
55db="$TRASH_DIRECTORY/db"
cfa96496 56cli="$TRASH_DIRECTORY/cli"
fc002330
PW
57git="$TRASH_DIRECTORY/git"
58pidfile="$TRASH_DIRECTORY/p4d.pid"
59
0cf1b72a
PW
60# git p4 submit generates a temp file, which will
61# not get cleaned up if the submission fails. Don't
62# clutter up /tmp on the test machine.
63TMPDIR="$TRASH_DIRECTORY"
64export TMPDIR
65
fc002330
PW
66start_p4d() {
67 mkdir -p "$db" "$cli" "$git" &&
f89f35a9 68 rm -f "$pidfile" &&
fc002330 69 (
6492a104
PW
70 cd "$db" &&
71 {
72 p4d -q -p $P4DPORT &
73 echo $! >"$pidfile"
74 }
fc002330 75 ) &&
f89f35a9
PW
76
77 # This gives p4d a long time to start up, as it can be
78 # quite slow depending on the machine. Set this environment
79 # variable to something smaller to fail faster in, say,
80 # an automated test setup. If the p4d process dies, that
81 # will be caught with the "kill -0" check below.
82 i=${P4D_START_PATIENCE:-300}
83 pid=$(cat "$pidfile")
84 ready=
85 while test $i -gt 0
86 do
87 # succeed when p4 client commands start to work
88 if p4 info >/dev/null 2>&1
89 then
90 ready=true
91 break
92 fi
93 # fail if p4d died
94 kill -0 $pid 2>/dev/null || break
95 echo waiting for p4d to start
fc002330 96 sleep 1
f89f35a9
PW
97 i=$(( $i - 1 ))
98 done
99
100 if test -z "$ready"
101 then
102 # p4d failed to start
103 return 1
104 fi
105
0055b56e
PW
106 # build a p4 user so author@example.com has an entry
107 p4_add_user author
108
f89f35a9 109 # build a client
daa38f4a
PW
110 client_view "//depot/... //client/..." &&
111
f89f35a9 112 return 0
fc002330
PW
113}
114
0055b56e
PW
115p4_add_user() {
116 name=$1 &&
117 p4 user -f -i <<-EOF
118 User: $name
119 Email: $name@example.com
120 FullName: Dr. $name
121 EOF
122}
123
fc002330
PW
124kill_p4d() {
125 pid=$(cat "$pidfile")
126 # it had better exist for the first kill
127 kill $pid &&
128 for i in 1 2 3 4 5 ; do
129 kill $pid >/dev/null 2>&1 || break
130 sleep 1
131 done &&
132 # complain if it would not die
133 test_must_fail kill $pid >/dev/null 2>&1 &&
134 rm -rf "$db" "$cli" "$pidfile"
135}
136
137cleanup_git() {
23a2666c
PW
138 rm -rf "$git" &&
139 mkdir "$git"
fc002330 140}
798d5980
PW
141
142marshal_dump() {
143 what=$1 &&
144 line=${2:-1} &&
145 cat >"$TRASH_DIRECTORY/marshal-dump.py" <<-EOF &&
146 import marshal
147 import sys
148 for i in range($line):
149 d = marshal.load(sys.stdin)
150 print d['$what']
151 EOF
152 "$PYTHON_PATH" "$TRASH_DIRECTORY/marshal-dump.py"
153}
d2018293
PW
154
155#
156# Construct a client with this list of View lines
157#
158client_view() {
159 (
160 cat <<-EOF &&
50038ba9
PW
161 Client: $P4CLIENT
162 Description: $P4CLIENT
d2018293 163 Root: $cli
cfa96496 164 AltRoots: $(native_path "$cli")
e93f8695 165 LineEnd: unix
d2018293
PW
166 View:
167 EOF
6112541b 168 printf "\t%s\n" "$@"
d2018293
PW
169 ) | p4 client -i
170}
e9df0f9c
PW
171
172is_cli_file_writeable() {
173 # cygwin version of p4 does not set read-only attr,
174 # will be marked 444 but -w is true
175 file="$1" &&
176 if test_have_prereq CYGWIN && p4 -V | grep -q CYGWIN
177 then
178 stat=$(stat --format=%a "$file") &&
179 test $stat = 644
180 else
181 test -w "$file"
182 fi
183}