revert: Introduce --continue to continue the operation
[git/mingw.git] / t / t9800-git-p4.sh
blob33b0127651da0c4c178e62c269179b641e15f9f6
1 #!/bin/sh
3 test_description='git-p4 tests'
5 . ./test-lib.sh
7 ( p4 -h && p4d -h ) >/dev/null 2>&1 || {
8 skip_all='skipping git-p4 tests; no p4 or p4d'
9 test_done
12 GITP4=$GIT_BUILD_DIR/contrib/fast-import/git-p4
13 P4DPORT=10669
15 export P4PORT=localhost:$P4DPORT
17 db="$TRASH_DIRECTORY/db"
18 cli="$TRASH_DIRECTORY/cli"
19 git="$TRASH_DIRECTORY/git"
21 test_debug 'echo p4d -q -d -r "$db" -p $P4DPORT'
22 test_expect_success setup '
23 mkdir -p "$db" &&
24 p4d -q -d -r "$db" -p $P4DPORT &&
25 mkdir -p "$cli" &&
26 mkdir -p "$git" &&
27 export P4PORT=localhost:$P4DPORT
30 test_expect_success 'add p4 files' '
31 cd "$cli" &&
32 p4 client -i <<-EOF &&
33 Client: client
34 Description: client
35 Root: $cli
36 View: //depot/... //client/...
37 EOF
38 export P4CLIENT=client &&
39 echo file1 >file1 &&
40 p4 add file1 &&
41 p4 submit -d "file1" &&
42 echo file2 >file2 &&
43 p4 add file2 &&
44 p4 submit -d "file2" &&
45 cd "$TRASH_DIRECTORY"
48 test_expect_success 'basic git-p4 clone' '
49 "$GITP4" clone --dest="$git" //depot &&
50 cd "$git" &&
51 git log --oneline >lines &&
52 test_line_count = 1 lines &&
53 cd .. &&
54 rm -rf "$git" && mkdir "$git"
57 test_expect_success 'git-p4 clone @all' '
58 "$GITP4" clone --dest="$git" //depot@all &&
59 cd "$git" &&
60 git log --oneline >lines &&
61 test_line_count = 2 lines &&
62 cd .. &&
63 rm -rf "$git" && mkdir "$git"
66 test_expect_success 'git-p4 sync uninitialized repo' '
67 test_create_repo "$git" &&
68 cd "$git" &&
69 test_must_fail "$GITP4" sync &&
70 rm -rf "$git" && mkdir "$git"
74 # Create a git repo by hand. Add a commit so that HEAD is valid.
75 # Test imports a new p4 repository into a new git branch.
77 test_expect_success 'git-p4 sync new branch' '
78 test_create_repo "$git" &&
79 cd "$git" &&
80 test_commit head &&
81 "$GITP4" sync --branch=refs/remotes/p4/depot //depot@all &&
82 git log --oneline p4/depot >lines &&
83 cat lines &&
84 test_line_count = 2 lines &&
85 cd .. &&
86 rm -rf "$git" && mkdir "$git"
89 test_expect_success 'exit when p4 fails to produce marshaled output' '
90 badp4dir="$TRASH_DIRECTORY/badp4dir" &&
91 mkdir -p "$badp4dir" &&
92 cat >"$badp4dir"/p4 <<-EOF &&
93 #!$SHELL_PATH
94 exit 1
95 EOF
96 chmod 755 "$badp4dir"/p4 &&
97 PATH="$badp4dir:$PATH" "$GITP4" clone --dest="$git" //depot >errs 2>&1 ; retval=$? &&
98 test $retval -eq 1 &&
99 test_must_fail grep -q Traceback errs
102 test_expect_success 'add p4 files with wildcards in the names' '
103 cd "$cli" &&
104 echo file-wild-hash >file-wild#hash &&
105 echo file-wild-star >file-wild\*star &&
106 echo file-wild-at >file-wild@at &&
107 echo file-wild-percent >file-wild%percent &&
108 p4 add -f file-wild* &&
109 p4 submit -d "file wildcards" &&
110 cd "$TRASH_DIRECTORY"
113 test_expect_success 'wildcard files git-p4 clone' '
114 "$GITP4" clone --dest="$git" //depot &&
115 cd "$git" &&
116 test -f file-wild#hash &&
117 test -f file-wild\*star &&
118 test -f file-wild@at &&
119 test -f file-wild%percent &&
120 cd "$TRASH_DIRECTORY" &&
121 rm -rf "$git" && mkdir "$git"
124 test_expect_success 'clone bare' '
125 "$GITP4" clone --dest="$git" --bare //depot &&
126 cd "$git" &&
127 test ! -d .git &&
128 bare=`git config --get core.bare` &&
129 test "$bare" = true &&
130 cd "$TRASH_DIRECTORY" &&
131 rm -rf "$git" && mkdir "$git"
134 p4_add_user() {
135 name=$1
136 fullname=$2
137 p4 user -f -i <<EOF &&
138 User: $name
139 Email: $name@localhost
140 FullName: $fullname
142 p4 passwd -P secret $name
145 p4_grant_admin() {
146 name=$1
147 p4 protect -o |\
148 awk "{print}END{print \" admin user $name * //depot/...\"}" |\
149 p4 protect -i
152 p4_check_commit_author() {
153 file=$1
154 user=$2
155 if p4 changes -m 1 //depot/$file | grep $user > /dev/null ; then
156 return 0
157 else
158 echo "file $file not modified by user $user" 1>&2
159 return 1
163 make_change_by_user() {
164 file=$1 name=$2 email=$3 &&
165 echo "username: a change by $name" >>"$file" &&
166 git add "$file" &&
167 git commit --author "$name <$email>" -m "a change by $name"
170 # Test username support, submitting as user 'alice'
171 test_expect_success 'preserve users' '
172 p4_add_user alice Alice &&
173 p4_add_user bob Bob &&
174 p4_grant_admin alice &&
175 "$GITP4" clone --dest="$git" //depot &&
176 cd "$git" &&
177 echo "username: a change by alice" >> file1 &&
178 echo "username: a change by bob" >> file2 &&
179 git commit --author "Alice <alice@localhost>" -m "a change by alice" file1 &&
180 git commit --author "Bob <bob@localhost>" -m "a change by bob" file2 &&
181 git config git-p4.skipSubmitEditCheck true &&
182 P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user &&
183 p4_check_commit_author file1 alice &&
184 p4_check_commit_author file2 bob &&
185 cd "$TRASH_DIRECTORY" &&
186 rm -rf "$git" && mkdir "$git"
189 # Test username support, submitting as bob, who lacks admin rights. Should
190 # not submit change to p4 (git diff should show deltas).
191 test_expect_success 'refuse to preserve users without perms' '
192 "$GITP4" clone --dest="$git" //depot &&
193 cd "$git" &&
194 echo "username-noperms: a change by alice" >> file1 &&
195 git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 &&
196 ! P4EDITOR=touch P4USER=bob P4PASSWD=secret "$GITP4" commit --preserve-user &&
197 ! git diff --exit-code HEAD..p4/master > /dev/null &&
198 cd "$TRASH_DIRECTORY" &&
199 rm -rf "$git" && mkdir "$git"
202 # What happens with unknown author? Without allowMissingP4Users it should fail.
203 test_expect_success 'preserve user where author is unknown to p4' '
204 "$GITP4" clone --dest="$git" //depot &&
205 cd "$git" &&
206 git config git-p4.skipSubmitEditCheck true
207 echo "username-bob: a change by bob" >> file1 &&
208 git commit --author "Bob <bob@localhost>" -m "preserve: a change by bob" file1 &&
209 echo "username-unknown: a change by charlie" >> file1 &&
210 git commit --author "Charlie <charlie@localhost>" -m "preserve: a change by charlie" file1 &&
211 ! P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user &&
212 ! git diff --exit-code HEAD..p4/master > /dev/null &&
213 echo "$0: repeat with allowMissingP4Users enabled" &&
214 git config git-p4.allowMissingP4Users true &&
215 git config git-p4.preserveUser true &&
216 P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit &&
217 git diff --exit-code HEAD..p4/master > /dev/null &&
218 p4_check_commit_author file1 alice &&
219 cd "$TRASH_DIRECTORY" &&
220 rm -rf "$git" && mkdir "$git"
223 # If we're *not* using --preserve-user, git-p4 should warn if we're submitting
224 # changes that are not all ours.
225 # Test: user in p4 and user unknown to p4.
226 # Test: warning disabled and user is the same.
227 test_expect_success 'not preserving user with mixed authorship' '
228 "$GITP4" clone --dest="$git" //depot &&
230 cd "$git" &&
231 git config git-p4.skipSubmitEditCheck true &&
232 p4_add_user derek Derek &&
234 make_change_by_user usernamefile3 Derek derek@localhost &&
235 P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
236 grep "git author derek@localhost does not match" actual &&
238 make_change_by_user usernamefile3 Charlie charlie@localhost &&
239 P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
240 grep "git author charlie@localhost does not match" actual &&
242 make_change_by_user usernamefile3 alice alice@localhost &&
243 P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
244 ! grep "git author.*does not match" actual &&
246 git config git-p4.skipUserNameCheck true &&
247 make_change_by_user usernamefile3 Charlie charlie@localhost &&
248 P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
249 ! grep "git author.*does not match" actual &&
251 p4_check_commit_author usernamefile3 alice
252 ) &&
253 rm -rf "$git" && mkdir "$git"
257 test_expect_success 'shutdown' '
258 pid=`pgrep -f p4d` &&
259 test -n "$pid" &&
260 test_debug "ps wl `echo $pid`" &&
261 kill $pid
264 test_done