3 test_description
='git p4 preserve users'
7 test_expect_success
'start p4d' '
11 test_expect_success
'create files' '
14 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
18 p4 submit -d "add files"
23 name
=$1 fullname
=$2 &&
24 p4 user
-f -i <<-EOF &&
26 Email: $name@localhost
29 p4 passwd
-P secret
$name
36 echo " admin user $name * //depot/..."
40 p4_check_commit_author
() {
42 p4 changes
-m 1 //depot
/$file |
grep -q $user
45 make_change_by_user
() {
46 file=$1 name
=$2 email
=$3 &&
47 echo "username: a change by $name" >>"$file" &&
49 git commit
--author "$name <$email>" -m "a change by $name"
52 # Test username support, submitting as user 'alice'
53 test_expect_success
'preserve users' '
54 p4_add_user alice Alice &&
55 p4_add_user bob Bob &&
56 p4_grant_admin alice &&
57 git p4 clone --dest="$git" //depot &&
58 test_when_finished cleanup_git &&
61 echo "username: a change by alice" >>file1 &&
62 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 &&
65 git config git-p4.skipSubmitEditCheck true &&
66 P4EDITOR=touch P4USER=alice P4PASSWD=secret git p4 commit --preserve-user &&
67 p4_check_commit_author file1 alice &&
68 p4_check_commit_author file2 bob
72 # Test username support, submitting as bob, who lacks admin rights. Should
73 # not submit change to p4 (git diff should show deltas).
74 test_expect_success
'refuse to preserve users without perms' '
75 git p4 clone --dest="$git" //depot &&
76 test_when_finished cleanup_git &&
79 git config git-p4.skipSubmitEditCheck true &&
80 echo "username-noperms: a change by alice" >>file1 &&
81 git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 &&
82 P4EDITOR=touch P4USER=bob P4PASSWD=secret &&
83 export P4EDITOR P4USER P4PASSWD &&
84 test_must_fail git p4 commit --preserve-user &&
85 ! git diff --exit-code HEAD..p4/master
89 # What happens with unknown author? Without allowMissingP4Users it should fail.
90 test_expect_success
'preserve user where author is unknown to p4' '
91 git p4 clone --dest="$git" //depot &&
92 test_when_finished cleanup_git &&
95 git config git-p4.skipSubmitEditCheck true &&
96 echo "username-bob: a change by bob" >>file1 &&
97 git commit --author "Bob <bob@localhost>" -m "preserve: a change by bob" file1 &&
98 echo "username-unknown: a change by charlie" >>file1 &&
99 git commit --author "Charlie <charlie@localhost>" -m "preserve: a change by charlie" file1 &&
100 P4EDITOR=touch P4USER=alice P4PASSWD=secret &&
101 export P4EDITOR P4USER P4PASSWD &&
102 test_must_fail git p4 commit --preserve-user &&
103 ! git diff --exit-code HEAD..p4/master &&
105 echo "$0: repeat with allowMissingP4Users enabled" &&
106 git config git-p4.allowMissingP4Users true &&
107 git config git-p4.preserveUser true &&
109 git diff --exit-code HEAD..p4/master &&
110 p4_check_commit_author file1 alice
114 # If we're *not* using --preserve-user, git-p4 should warn if we're submitting
115 # changes that are not all ours.
116 # Test: user in p4 and user unknown to p4.
117 # Test: warning disabled and user is the same.
118 test_expect_success
'not preserving user with mixed authorship' '
119 git p4 clone --dest="$git" //depot &&
120 test_when_finished cleanup_git &&
123 git config git-p4.skipSubmitEditCheck true &&
124 p4_add_user derek Derek &&
126 make_change_by_user usernamefile3 Derek derek@localhost &&
127 P4EDITOR=cat P4USER=alice P4PASSWD=secret &&
128 export P4EDITOR P4USER P4PASSWD &&
130 grep "git author derek@localhost does not match" &&
132 make_change_by_user usernamefile3 Charlie charlie@localhost &&
134 grep "git author charlie@localhost does not match" &&
136 make_change_by_user usernamefile3 alice alice@localhost &&
138 test_must_fail grep "git author.*does not match" &&
140 git config git-p4.skipUserNameCheck true &&
141 make_change_by_user usernamefile3 Charlie charlie@localhost &&
143 test_must_fail grep "git author.*does not match" &&
145 p4_check_commit_author usernamefile3 alice
149 test_expect_success
'kill p4d' '