@@ -45,29 +45,33 @@ test_expect_success 'add p4 files' '
45
45
cd "$TRASH_DIRECTORY"
46
46
'
47
47
48
+ cleanup_git () {
49
+ cd " $TRASH_DIRECTORY " &&
50
+ rm -rf " $git " &&
51
+ mkdir " $git "
52
+ }
53
+
48
54
test_expect_success ' basic git-p4 clone' '
49
55
"$GITP4" clone --dest="$git" //depot &&
56
+ test_when_finished cleanup_git &&
50
57
cd "$git" &&
51
58
git log --oneline >lines &&
52
- test_line_count = 1 lines &&
53
- cd .. &&
54
- rm -rf "$git" && mkdir "$git"
59
+ test_line_count = 1 lines
55
60
'
56
61
57
62
test_expect_success ' git-p4 clone @all' '
58
63
"$GITP4" clone --dest="$git" //depot@all &&
64
+ test_when_finished cleanup_git &&
59
65
cd "$git" &&
60
66
git log --oneline >lines &&
61
- test_line_count = 2 lines &&
62
- cd .. &&
63
- rm -rf "$git" && mkdir "$git"
67
+ test_line_count = 2 lines
64
68
'
65
69
66
70
test_expect_success ' git-p4 sync uninitialized repo' '
67
71
test_create_repo "$git" &&
72
+ test_when_finished cleanup_git &&
68
73
cd "$git" &&
69
- test_must_fail "$GITP4" sync &&
70
- rm -rf "$git" && mkdir "$git"
74
+ test_must_fail "$GITP4" sync
71
75
'
72
76
73
77
#
@@ -76,19 +80,18 @@ test_expect_success 'git-p4 sync uninitialized repo' '
76
80
#
77
81
test_expect_success ' git-p4 sync new branch' '
78
82
test_create_repo "$git" &&
83
+ test_when_finished cleanup_git &&
79
84
cd "$git" &&
80
85
test_commit head &&
81
86
"$GITP4" sync --branch=refs/remotes/p4/depot //depot@all &&
82
87
git log --oneline p4/depot >lines &&
83
- cat lines &&
84
- test_line_count = 2 lines &&
85
- cd .. &&
86
- rm -rf "$git" && mkdir "$git"
88
+ test_line_count = 2 lines
87
89
'
88
90
89
91
test_expect_success ' exit when p4 fails to produce marshaled output' '
90
92
badp4dir="$TRASH_DIRECTORY/badp4dir" &&
91
93
mkdir -p "$badp4dir" &&
94
+ test_when_finished "rm -rf $badp4dir" &&
92
95
cat >"$badp4dir"/p4 <<-EOF &&
93
96
#!$SHELL_PATH
94
97
exit 1
@@ -106,29 +109,26 @@ test_expect_success 'add p4 files with wildcards in the names' '
106
109
echo file-wild-at >file-wild@at &&
107
110
echo file-wild-percent >file-wild%percent &&
108
111
p4 add -f file-wild* &&
109
- p4 submit -d "file wildcards" &&
110
- cd "$TRASH_DIRECTORY"
112
+ p4 submit -d "file wildcards"
111
113
'
112
114
113
115
test_expect_success ' wildcard files git-p4 clone' '
114
116
"$GITP4" clone --dest="$git" //depot &&
117
+ test_when_finished cleanup_git &&
115
118
cd "$git" &&
116
119
test -f file-wild#hash &&
117
120
test -f file-wild\*star &&
118
121
test -f file-wild@at &&
119
- test -f file-wild%percent &&
120
- cd "$TRASH_DIRECTORY" &&
121
- rm -rf "$git" && mkdir "$git"
122
+ test -f file-wild%percent
122
123
'
123
124
124
125
test_expect_success ' clone bare' '
125
126
"$GITP4" clone --dest="$git" --bare //depot &&
127
+ test_when_finished cleanup_git &&
126
128
cd "$git" &&
127
129
test ! -d .git &&
128
130
bare=`git config --get core.bare` &&
129
- test "$bare" = true &&
130
- cd "$TRASH_DIRECTORY" &&
131
- rm -rf "$git" && mkdir "$git"
131
+ test "$bare" = true
132
132
'
133
133
134
134
p4_add_user () {
@@ -173,6 +173,7 @@ test_expect_success 'preserve users' '
173
173
p4_add_user bob Bob &&
174
174
p4_grant_admin alice &&
175
175
"$GITP4" clone --dest="$git" //depot &&
176
+ test_when_finished cleanup_git &&
176
177
cd "$git" &&
177
178
echo "username: a change by alice" >> file1 &&
178
179
echo "username: a change by bob" >> file2 &&
@@ -181,27 +182,25 @@ test_expect_success 'preserve users' '
181
182
git config git-p4.skipSubmitEditCheck true &&
182
183
P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user &&
183
184
p4_check_commit_author file1 alice &&
184
- p4_check_commit_author file2 bob &&
185
- cd "$TRASH_DIRECTORY" &&
186
- rm -rf "$git" && mkdir "$git"
185
+ p4_check_commit_author file2 bob
187
186
'
188
187
189
188
# Test username support, submitting as bob, who lacks admin rights. Should
190
189
# not submit change to p4 (git diff should show deltas).
191
190
test_expect_success ' refuse to preserve users without perms' '
192
191
"$GITP4" clone --dest="$git" //depot &&
192
+ test_when_finished cleanup_git &&
193
193
cd "$git" &&
194
194
echo "username-noperms: a change by alice" >> file1 &&
195
195
git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 &&
196
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"
197
+ ! git diff --exit-code HEAD..p4/master > /dev/null
200
198
'
201
199
202
200
# What happens with unknown author? Without allowMissingP4Users it should fail.
203
201
test_expect_success ' preserve user where author is unknown to p4' '
204
202
"$GITP4" clone --dest="$git" //depot &&
203
+ test_when_finished cleanup_git &&
205
204
cd "$git" &&
206
205
git config git-p4.skipSubmitEditCheck true
207
206
echo "username-bob: a change by bob" >> file1 &&
@@ -215,9 +214,7 @@ test_expect_success 'preserve user where author is unknown to p4' '
215
214
git config git-p4.preserveUser true &&
216
215
P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit &&
217
216
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"
217
+ p4_check_commit_author file1 alice
221
218
'
222
219
223
220
# If we're *not* using --preserve-user, git-p4 should warn if we're submitting
@@ -226,31 +223,29 @@ test_expect_success 'preserve user where author is unknown to p4' '
226
223
# Test: warning disabled and user is the same.
227
224
test_expect_success ' not preserving user with mixed authorship' '
228
225
"$GITP4" clone --dest="$git" //depot &&
229
- (
230
- cd "$git" &&
231
- git config git-p4.skipSubmitEditCheck true &&
232
- p4_add_user derek Derek &&
233
-
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 &&
237
-
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 &&
241
-
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 &&
245
-
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 &&
250
-
251
- p4_check_commit_author usernamefile3 alice
252
- ) &&
253
- rm -rf "$git" && mkdir "$git"
226
+ test_when_finished cleanup_git &&
227
+ cd "$git" &&
228
+ git config git-p4.skipSubmitEditCheck true &&
229
+ p4_add_user derek Derek &&
230
+
231
+ make_change_by_user usernamefile3 Derek derek@localhost &&
232
+ P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
233
+ grep "git author derek@localhost does not match" actual &&
234
+
235
+ make_change_by_user usernamefile3 Charlie charlie@localhost &&
236
+ P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
237
+ grep "git author charlie@localhost does not match" actual &&
238
+
239
+ make_change_by_user usernamefile3 alice alice@localhost &&
240
+ P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
241
+ ! grep "git author.*does not match" actual &&
242
+
243
+ git config git-p4.skipUserNameCheck true &&
244
+ make_change_by_user usernamefile3 Charlie charlie@localhost &&
245
+ P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual &&
246
+ ! grep "git author.*does not match" actual &&
247
+
248
+ p4_check_commit_author usernamefile3 alice
254
249
'
255
250
256
251
0 commit comments