The eleventh batch
[git/gitster.git] / t / t9813-git-p4-preserve-users.sh
blob0efea28da2cb9d6f09a024e174fc0ff50a303872
1 #!/bin/sh
3 test_description='git p4 preserve users'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./lib-git-p4.sh
8 test_expect_success 'start p4d' '
9 start_p4d
12 test_expect_success 'create files' '
14 cd "$cli" &&
15 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
16 echo file1 >file1 &&
17 echo file2 >file2 &&
18 p4 add file1 file2 &&
19 p4 submit -d "add files"
23 p4_grant_admin() {
24 name=$1 &&
26 p4 protect -o &&
27 echo " admin user $name * //depot/..."
28 } | p4 protect -i
31 p4_check_commit_author() {
32 file=$1 user=$2 &&
33 p4 changes -m 1 //depot/$file | grep -q $user
36 make_change_by_user() {
37 file=$1 name=$2 email=$3 &&
38 echo "username: a change by $name" >>"$file" &&
39 git add "$file" &&
40 git commit --author "$name <$email>" -m "a change by $name"
43 # Test username support, submitting as user 'alice'
44 test_expect_success 'preserve users' '
45 p4_add_user alice &&
46 p4_add_user bob &&
47 p4_grant_admin alice &&
48 git p4 clone --dest="$git" //depot &&
49 test_when_finished cleanup_git &&
51 cd "$git" &&
52 echo "username: a change by alice" >>file1 &&
53 echo "username: a change by bob" >>file2 &&
54 git commit --author "Alice <alice@example.com>" -m "a change by alice" file1 &&
55 git commit --author "Bob <bob@example.com>" -m "a change by bob" file2 &&
56 git config git-p4.skipSubmitEditCheck true &&
57 P4EDITOR="test-tool chmtime +5" P4USER=alice P4PASSWD=secret &&
58 export P4EDITOR P4USER P4PASSWD &&
59 git p4 commit --preserve-user &&
60 p4_check_commit_author file1 alice &&
61 p4_check_commit_author file2 bob
65 # Test username support, submitting as bob, who lacks admin rights. Should
66 # not submit change to p4 (git diff should show deltas).
67 test_expect_success 'refuse to preserve users without perms' '
68 git p4 clone --dest="$git" //depot &&
69 test_when_finished cleanup_git &&
71 cd "$git" &&
72 git config git-p4.skipSubmitEditCheck true &&
73 echo "username-noperms: a change by alice" >>file1 &&
74 git commit --author "Alice <alice@example.com>" -m "perms: a change by alice" file1 &&
75 P4EDITOR="test-tool chmtime +5" P4USER=bob P4PASSWD=secret &&
76 export P4EDITOR P4USER P4PASSWD &&
77 test_must_fail git p4 commit --preserve-user &&
78 ! git diff --exit-code HEAD..p4/master
82 # What happens with unknown author? Without allowMissingP4Users it should fail.
83 test_expect_success 'preserve user where author is unknown to p4' '
84 git p4 clone --dest="$git" //depot &&
85 test_when_finished cleanup_git &&
87 cd "$git" &&
88 git config git-p4.skipSubmitEditCheck true &&
89 echo "username-bob: a change by bob" >>file1 &&
90 git commit --author "Bob <bob@example.com>" -m "preserve: a change by bob" file1 &&
91 echo "username-unknown: a change by charlie" >>file1 &&
92 git commit --author "Charlie <charlie@example.com>" -m "preserve: a change by charlie" file1 &&
93 P4EDITOR="test-tool chmtime +5" P4USER=alice P4PASSWD=secret &&
94 export P4EDITOR P4USER P4PASSWD &&
95 test_must_fail git p4 commit --preserve-user &&
96 ! git diff --exit-code HEAD..p4/master &&
98 echo "$0: repeat with allowMissingP4Users enabled" &&
99 git config git-p4.allowMissingP4Users true &&
100 git config git-p4.preserveUser true &&
101 git p4 commit &&
102 git diff --exit-code HEAD..p4/master &&
103 p4_check_commit_author file1 alice
107 # If we're *not* using --preserve-user, git-p4 should warn if we're submitting
108 # changes that are not all ours.
109 # Test: user in p4 and user unknown to p4.
110 # Test: warning disabled and user is the same.
111 test_expect_success 'not preserving user with mixed authorship' '
112 git p4 clone --dest="$git" //depot &&
113 test_when_finished cleanup_git &&
115 cd "$git" &&
116 git config git-p4.skipSubmitEditCheck true &&
117 p4_add_user derek &&
119 make_change_by_user usernamefile3 Derek derek@example.com &&
120 P4EDITOR=cat P4USER=alice P4PASSWD=secret &&
121 export P4EDITOR P4USER P4PASSWD &&
122 git p4 commit >actual &&
123 grep "git author derek@example.com does not match" actual &&
125 make_change_by_user usernamefile3 Charlie charlie@example.com &&
126 git p4 commit >actual &&
127 grep "git author charlie@example.com does not match" actual &&
129 make_change_by_user usernamefile3 alice alice@example.com &&
130 git p4 commit >actual &&
131 ! grep "git author.*does not match" actual &&
133 git config git-p4.skipUserNameCheck true &&
134 make_change_by_user usernamefile3 Charlie charlie@example.com &&
135 git p4 commit >actual &&
136 ! grep "git author.*does not match" actual &&
138 p4_check_commit_author usernamefile3 alice
142 test_done