Skip to content

Commit 0055b56

Browse files
Pete Wyckoffgitster
authored andcommitted
git p4 test: run as user "author"
The tests use [email protected] as the canonical submitter, but he does not have an entry in the p4 users database. This causes the generated change description to complain that the git and p4 users disagree. The complaint message is still valid, but isn't useful in tests. It was introduced in 848de9c (git-p4: warn if git authorship won't be retained, 2011-05-13). Fix t9813 to use @example.com instead of @localhost due to change in p4_add_user(). Move the function into the git p4 test library so author can be added at initialization time. Signed-off-by: Pete Wyckoff <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0577849 commit 0055b56

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

t/lib-git-p4.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ P4DPORT=$((10669 + ($testid - $git_p4_test_start)))
4747

4848
P4PORT=localhost:$P4DPORT
4949
P4CLIENT=client
50+
P4USER=author
5051
P4EDITOR=:
5152
unset P4CHARSET
52-
export P4PORT P4CLIENT P4EDITOR P4CHARSET
53+
export P4PORT P4CLIENT P4USER P4EDITOR P4CHARSET
5354

5455
db="$TRASH_DIRECTORY/db"
5556
cli="$TRASH_DIRECTORY/cli"
@@ -96,12 +97,24 @@ start_p4d() {
9697
return 1
9798
fi
9899

100+
# build a p4 user so [email protected] has an entry
101+
p4_add_user author
102+
99103
# build a client
100104
client_view "//depot/... //client/..." &&
101105

102106
return 0
103107
}
104108

109+
p4_add_user() {
110+
name=$1 &&
111+
p4 user -f -i <<-EOF
112+
User: $name
113+
Email: $name@example.com
114+
FullName: Dr. $name
115+
EOF
116+
}
117+
105118
kill_p4d() {
106119
pid=$(cat "$pidfile")
107120
# it had better exist for the first kill

t/t9813-git-p4-preserve-users.sh

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ test_expect_success 'create files' '
1919
)
2020
'
2121

22-
p4_add_user() {
23-
name=$1 fullname=$2 &&
24-
p4 user -f -i <<-EOF &&
25-
User: $name
26-
Email: $name@localhost
27-
FullName: $fullname
28-
EOF
29-
p4 passwd -P secret $name
30-
}
31-
3222
p4_grant_admin() {
3323
name=$1 &&
3424
{
@@ -51,17 +41,17 @@ make_change_by_user() {
5141

5242
# Test username support, submitting as user 'alice'
5343
test_expect_success 'preserve users' '
54-
p4_add_user alice Alice &&
55-
p4_add_user bob Bob &&
44+
p4_add_user alice &&
45+
p4_add_user bob &&
5646
p4_grant_admin alice &&
5747
git p4 clone --dest="$git" //depot &&
5848
test_when_finished cleanup_git &&
5949
(
6050
cd "$git" &&
6151
echo "username: a change by alice" >>file1 &&
6252
echo "username: a change by bob" >>file2 &&
63-
git commit --author "Alice <alice@localhost>" -m "a change by alice" file1 &&
64-
git commit --author "Bob <bob@localhost>" -m "a change by bob" file2 &&
53+
git commit --author "Alice <alice@example.com>" -m "a change by alice" file1 &&
54+
git commit --author "Bob <bob@example.com>" -m "a change by bob" file2 &&
6555
git config git-p4.skipSubmitEditCheck true &&
6656
P4EDITOR=touch P4USER=alice P4PASSWD=secret git p4 commit --preserve-user &&
6757
p4_check_commit_author file1 alice &&
@@ -78,7 +68,7 @@ test_expect_success 'refuse to preserve users without perms' '
7868
cd "$git" &&
7969
git config git-p4.skipSubmitEditCheck true &&
8070
echo "username-noperms: a change by alice" >>file1 &&
81-
git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 &&
71+
git commit --author "Alice <alice@example.com>" -m "perms: a change by alice" file1 &&
8272
P4EDITOR=touch P4USER=bob P4PASSWD=secret &&
8373
export P4EDITOR P4USER P4PASSWD &&
8474
test_must_fail git p4 commit --preserve-user &&
@@ -94,9 +84,9 @@ test_expect_success 'preserve user where author is unknown to p4' '
9484
cd "$git" &&
9585
git config git-p4.skipSubmitEditCheck true &&
9686
echo "username-bob: a change by bob" >>file1 &&
97-
git commit --author "Bob <bob@localhost>" -m "preserve: a change by bob" file1 &&
87+
git commit --author "Bob <bob@example.com>" -m "preserve: a change by bob" file1 &&
9888
echo "username-unknown: a change by charlie" >>file1 &&
99-
git commit --author "Charlie <charlie@localhost>" -m "preserve: a change by charlie" file1 &&
89+
git commit --author "Charlie <charlie@example.com>" -m "preserve: a change by charlie" file1 &&
10090
P4EDITOR=touch P4USER=alice P4PASSWD=secret &&
10191
export P4EDITOR P4USER P4PASSWD &&
10292
test_must_fail git p4 commit --preserve-user &&
@@ -121,24 +111,24 @@ test_expect_success 'not preserving user with mixed authorship' '
121111
(
122112
cd "$git" &&
123113
git config git-p4.skipSubmitEditCheck true &&
124-
p4_add_user derek Derek &&
114+
p4_add_user derek &&
125115
126-
make_change_by_user usernamefile3 Derek derek@localhost &&
116+
make_change_by_user usernamefile3 Derek derek@example.com &&
127117
P4EDITOR=cat P4USER=alice P4PASSWD=secret &&
128118
export P4EDITOR P4USER P4PASSWD &&
129119
git p4 commit |\
130-
grep "git author derek@localhost does not match" &&
120+
grep "git author derek@example.com does not match" &&
131121
132-
make_change_by_user usernamefile3 Charlie charlie@localhost &&
122+
make_change_by_user usernamefile3 Charlie charlie@example.com &&
133123
git p4 commit |\
134-
grep "git author charlie@localhost does not match" &&
124+
grep "git author charlie@example.com does not match" &&
135125
136-
make_change_by_user usernamefile3 alice alice@localhost &&
126+
make_change_by_user usernamefile3 alice alice@example.com &&
137127
git p4 commit |\
138128
test_must_fail grep "git author.*does not match" &&
139129
140130
git config git-p4.skipUserNameCheck true &&
141-
make_change_by_user usernamefile3 Charlie charlie@localhost &&
131+
make_change_by_user usernamefile3 Charlie charlie@example.com &&
142132
git p4 commit |\
143133
test_must_fail grep "git author.*does not match" &&
144134

0 commit comments

Comments
 (0)