3 test_description='git-p4 tests'
7 ( p4 -h && p4d -h ) >/dev/null 2>&1 || {
8 skip_all='skipping git-p4 tests; no p4 or p4d'
12 GITP4=$GIT_BUILD_DIR/contrib/fast-import/git-p4
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 '
24 p4d -q -d -r "$db" -p $P4DPORT &&
27 export P4PORT=localhost:$P4DPORT
30 test_expect_success 'add p4 files' '
32 p4 client -i <<-EOF &&
36 View: //depot/... //client/...
38 export P4CLIENT=client &&
41 p4 submit -d "file1" &&
44 p4 submit -d "file2" &&
48 test_expect_success 'basic git-p4 clone' '
49 "$GITP4" clone --dest="$git" //depot &&
51 git log --oneline >lines &&
52 test_line_count = 1 lines &&
54 rm -rf "$git" && mkdir "$git"
57 test_expect_success 'git-p4 clone @all' '
58 "$GITP4" clone --dest="$git" //depot@all &&
60 git log --oneline >lines &&
61 test_line_count = 2 lines &&
63 rm -rf "$git" && mkdir "$git"
66 test_expect_success 'git-p4 sync uninitialized repo' '
67 test_create_repo "$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" &&
81 "$GITP4" sync --branch=refs/remotes/p4/depot //depot@all &&
82 git log --oneline p4/depot >lines &&
84 test_line_count = 2 lines &&
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 &&
96 chmod 755 "$badp4dir"/p4 &&
97 PATH="$badp4dir:$PATH" "$GITP4" clone --dest="$git" //depot >errs 2>&1 ; retval=$? &&
99 test_must_fail grep -q Traceback errs
102 test_expect_success 'add p4 files with wildcards in the names' '
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 &&
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 &&
128 bare=`git config --get core.bare` &&
129 test "$bare" = true &&
130 cd "$TRASH_DIRECTORY" &&
131 rm -rf "$git" && mkdir "$git"
137 p4 user -f -i <<EOF &&
139 Email: $name@localhost
142 p4 passwd -P secret $name
148 awk "{print}END{print \" admin user $name * //depot/...\"}" |\
152 p4_check_commit_author() {
155 if p4 changes -m 1 //depot/$file | grep $user > /dev/null ; then
158 echo "file $file not modified by user $user" 1>&2
163 # Test username support, submitting as user 'alice'
164 test_expect_success 'preserve users' '
165 p4_add_user alice Alice &&
166 p4_add_user bob Bob &&
167 p4_grant_admin alice &&
168 "$GITP4" clone --dest="$git" //depot &&
170 echo "username: a change by alice" >> file1 &&
171 echo "username: a change by bob" >> file2 &&
172 git commit --author "Alice <alice@localhost>" -m "a change by alice" file1 &&
173 git commit --author "Bob <bob@localhost>" -m "a change by bob" file2 &&
174 git config git-p4.skipSubmitEditCheck true &&
175 P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user &&
176 p4_check_commit_author file1 alice &&
177 p4_check_commit_author file2 bob &&
178 cd "$TRASH_DIRECTORY" &&
179 rm -rf "$git" && mkdir "$git"
182 # Test username support, submitting as bob, who lacks admin rights. Should
183 # not submit change to p4 (git diff should show deltas).
184 test_expect_success 'refuse to preserve users without perms' '
185 "$GITP4" clone --dest="$git" //depot &&
187 echo "username-noperms: a change by alice" >> file1 &&
188 git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 &&
189 ! P4EDITOR=touch P4USER=bob P4PASSWD=secret "$GITP4" commit --preserve-user &&
190 ! git diff --exit-code HEAD..p4/master > /dev/null &&
191 cd "$TRASH_DIRECTORY" &&
192 rm -rf "$git" && mkdir "$git"
195 # What happens with unknown author? Without allowMissingP4Users it should fail.
196 test_expect_success 'preserve user where author is unknown to p4' '
197 "$GITP4" clone --dest="$git" //depot &&
199 git config git-p4.skipSubmitEditCheck true
200 echo "username-bob: a change by bob" >> file1 &&
201 git commit --author "Bob <bob@localhost>" -m "preserve: a change by bob" file1 &&
202 echo "username-unknown: a change by charlie" >> file1 &&
203 git commit --author "Charlie <charlie@localhost>" -m "preserve: a change by charlie" file1 &&
204 ! P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user &&
205 ! git diff --exit-code HEAD..p4/master > /dev/null &&
206 echo "$0: repeat with allowMissingP4Users enabled" &&
207 git config git-p4.allowMissingP4Users true &&
208 git config git-p4.preserveUser true &&
209 P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit &&
210 git diff --exit-code HEAD..p4/master > /dev/null &&
211 p4_check_commit_author file1 alice &&
212 cd "$TRASH_DIRECTORY" &&
213 rm -rf "$git" && mkdir "$git"
216 test_expect_success 'shutdown' '
217 pid=`pgrep -f p4d` &&
219 test_debug "ps wl `echo $pid`" &&