Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git p4 preserve users' |
| 4 | |
| 5 | . ./lib-git-p4.sh |
| 6 | |
| 7 | test_expect_success 'start p4d' ' |
| 8 | start_p4d |
| 9 | ' |
| 10 | |
| 11 | test_expect_success 'create files' ' |
| 12 | ( |
| 13 | cd "$cli" && |
| 14 | p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i && |
| 15 | echo file1 >file1 && |
| 16 | echo file2 >file2 && |
| 17 | p4 add file1 file2 && |
| 18 | p4 submit -d "add files" |
| 19 | ) |
| 20 | ' |
| 21 | |
Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 22 | p4_grant_admin() { |
| 23 | name=$1 && |
| 24 | { |
| 25 | p4 protect -o && |
| 26 | echo " admin user $name * //depot/..." |
| 27 | } | p4 protect -i |
| 28 | } |
| 29 | |
| 30 | p4_check_commit_author() { |
| 31 | file=$1 user=$2 && |
| 32 | p4 changes -m 1 //depot/$file | grep -q $user |
| 33 | } |
| 34 | |
| 35 | make_change_by_user() { |
| 36 | file=$1 name=$2 email=$3 && |
| 37 | echo "username: a change by $name" >>"$file" && |
| 38 | git add "$file" && |
| 39 | git commit --author "$name <$email>" -m "a change by $name" |
| 40 | } |
| 41 | |
| 42 | # Test username support, submitting as user 'alice' |
| 43 | test_expect_success 'preserve users' ' |
Pete Wyckoff | 0055b56 | 2014-01-21 18:16:43 -0500 | [diff] [blame] | 44 | p4_add_user alice && |
| 45 | p4_add_user bob && |
Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 46 | p4_grant_admin alice && |
| 47 | git p4 clone --dest="$git" //depot && |
| 48 | test_when_finished cleanup_git && |
| 49 | ( |
| 50 | cd "$git" && |
| 51 | echo "username: a change by alice" >>file1 && |
| 52 | echo "username: a change by bob" >>file2 && |
Pete Wyckoff | 0055b56 | 2014-01-21 18:16:43 -0500 | [diff] [blame] | 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 && |
Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 55 | git config git-p4.skipSubmitEditCheck true && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 56 | P4EDITOR="test-tool chmtime +5" P4USER=alice P4PASSWD=secret && |
Luke Diamand | f3b5b07 | 2015-05-19 23:23:18 +0100 | [diff] [blame] | 57 | export P4EDITOR P4USER P4PASSWD && |
| 58 | git p4 commit --preserve-user && |
Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 59 | p4_check_commit_author file1 alice && |
| 60 | p4_check_commit_author file2 bob |
| 61 | ) |
| 62 | ' |
| 63 | |
| 64 | # Test username support, submitting as bob, who lacks admin rights. Should |
| 65 | # not submit change to p4 (git diff should show deltas). |
| 66 | test_expect_success 'refuse to preserve users without perms' ' |
| 67 | git p4 clone --dest="$git" //depot && |
| 68 | test_when_finished cleanup_git && |
| 69 | ( |
| 70 | cd "$git" && |
| 71 | git config git-p4.skipSubmitEditCheck true && |
| 72 | echo "username-noperms: a change by alice" >>file1 && |
Pete Wyckoff | 0055b56 | 2014-01-21 18:16:43 -0500 | [diff] [blame] | 73 | git commit --author "Alice <alice@example.com>" -m "perms: a change by alice" file1 && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 74 | P4EDITOR="test-tool chmtime +5" P4USER=bob P4PASSWD=secret && |
Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 75 | export P4EDITOR P4USER P4PASSWD && |
| 76 | test_must_fail git p4 commit --preserve-user && |
| 77 | ! git diff --exit-code HEAD..p4/master |
| 78 | ) |
| 79 | ' |
| 80 | |
| 81 | # What happens with unknown author? Without allowMissingP4Users it should fail. |
| 82 | test_expect_success 'preserve user where author is unknown to p4' ' |
| 83 | git p4 clone --dest="$git" //depot && |
| 84 | test_when_finished cleanup_git && |
| 85 | ( |
| 86 | cd "$git" && |
| 87 | git config git-p4.skipSubmitEditCheck true && |
| 88 | echo "username-bob: a change by bob" >>file1 && |
Pete Wyckoff | 0055b56 | 2014-01-21 18:16:43 -0500 | [diff] [blame] | 89 | git commit --author "Bob <bob@example.com>" -m "preserve: a change by bob" file1 && |
Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 90 | echo "username-unknown: a change by charlie" >>file1 && |
Pete Wyckoff | 0055b56 | 2014-01-21 18:16:43 -0500 | [diff] [blame] | 91 | git commit --author "Charlie <charlie@example.com>" -m "preserve: a change by charlie" file1 && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 92 | P4EDITOR="test-tool chmtime +5" P4USER=alice P4PASSWD=secret && |
Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 93 | export P4EDITOR P4USER P4PASSWD && |
| 94 | test_must_fail git p4 commit --preserve-user && |
| 95 | ! git diff --exit-code HEAD..p4/master && |
| 96 | |
| 97 | echo "$0: repeat with allowMissingP4Users enabled" && |
| 98 | git config git-p4.allowMissingP4Users true && |
| 99 | git config git-p4.preserveUser true && |
| 100 | git p4 commit && |
| 101 | git diff --exit-code HEAD..p4/master && |
| 102 | p4_check_commit_author file1 alice |
| 103 | ) |
| 104 | ' |
| 105 | |
| 106 | # If we're *not* using --preserve-user, git-p4 should warn if we're submitting |
| 107 | # changes that are not all ours. |
| 108 | # Test: user in p4 and user unknown to p4. |
| 109 | # Test: warning disabled and user is the same. |
| 110 | test_expect_success 'not preserving user with mixed authorship' ' |
| 111 | git p4 clone --dest="$git" //depot && |
| 112 | test_when_finished cleanup_git && |
| 113 | ( |
| 114 | cd "$git" && |
| 115 | git config git-p4.skipSubmitEditCheck true && |
Pete Wyckoff | 0055b56 | 2014-01-21 18:16:43 -0500 | [diff] [blame] | 116 | p4_add_user derek && |
Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 117 | |
Pete Wyckoff | 0055b56 | 2014-01-21 18:16:43 -0500 | [diff] [blame] | 118 | make_change_by_user usernamefile3 Derek derek@example.com && |
Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 119 | P4EDITOR=cat P4USER=alice P4PASSWD=secret && |
| 120 | export P4EDITOR P4USER P4PASSWD && |
Pranit Bauva | c6f44e1d | 2017-01-04 01:27:08 +0530 | [diff] [blame] | 121 | git p4 commit >actual && |
| 122 | grep "git author derek@example.com does not match" actual && |
Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 123 | |
Pete Wyckoff | 0055b56 | 2014-01-21 18:16:43 -0500 | [diff] [blame] | 124 | make_change_by_user usernamefile3 Charlie charlie@example.com && |
Pranit Bauva | c6f44e1d | 2017-01-04 01:27:08 +0530 | [diff] [blame] | 125 | git p4 commit >actual && |
| 126 | grep "git author charlie@example.com does not match" actual && |
Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 127 | |
Pete Wyckoff | 0055b56 | 2014-01-21 18:16:43 -0500 | [diff] [blame] | 128 | make_change_by_user usernamefile3 alice alice@example.com && |
Pranit Bauva | c7cf956 | 2017-01-04 01:27:07 +0530 | [diff] [blame] | 129 | git p4 commit >actual && |
| 130 | ! grep "git author.*does not match" actual && |
Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 131 | |
| 132 | git config git-p4.skipUserNameCheck true && |
Pete Wyckoff | 0055b56 | 2014-01-21 18:16:43 -0500 | [diff] [blame] | 133 | make_change_by_user usernamefile3 Charlie charlie@example.com && |
Pranit Bauva | c7cf956 | 2017-01-04 01:27:07 +0530 | [diff] [blame] | 134 | git p4 commit >actual && |
| 135 | ! grep "git author.*does not match" actual && |
Pete Wyckoff | 9b6513a | 2012-06-27 08:01:02 -0400 | [diff] [blame] | 136 | |
| 137 | p4_check_commit_author usernamefile3 alice |
| 138 | ) |
| 139 | ' |
| 140 | |
| 141 | test_expect_success 'kill p4d' ' |
| 142 | kill_p4d |
| 143 | ' |
| 144 | |
| 145 | test_done |