3 # Copyright (c) 2016 Dan Aloni
4 # Copyright (c) 2016 Jeff King
7 test_description
='per-repo forced setting of email address'
9 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
10 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
14 test_expect_success
'setup a likely user.useConfigOnly use case' '
15 # we want to make sure a reflog is written, since that needs
16 # a non-strict ident. So be sure we have an actual commit.
19 sane_unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL &&
20 sane_unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL &&
21 git config user.name "test" &&
22 git config --global user.useConfigOnly true
25 test_expect_success
'fails committing if clone email is not set' '
26 test_must_fail git commit --allow-empty -m msg
29 test_expect_success
'fails committing if clone email is not set, but EMAIL set' '
30 test_must_fail env EMAIL=test@fail.com git commit --allow-empty -m msg
33 test_expect_success
'succeeds committing if clone email is set' '
34 test_config user.email "test@ok.com" &&
35 git commit --allow-empty -m msg
38 test_expect_success
'succeeds cloning if global email is not set' '
42 test_expect_success
'set up rebase scenarios' '
43 # temporarily enable an actual ident for this setup
44 test_config user.email foo@example.com &&
46 git branch side-without-commit HEAD^ &&
47 git checkout -b side-with-commit HEAD^ &&
51 test_expect_success
'fast-forward rebase does not care about ident' '
52 git checkout -B tmp side-without-commit &&
56 test_expect_success
'non-fast-forward rebase refuses to write commits' '
57 test_when_finished "git rebase --abort || true" &&
58 git checkout -B tmp side-with-commit &&
59 test_must_fail git rebase main
62 test_expect_success
'fast-forward rebase does not care about ident (interactive)' '
63 git checkout -B tmp side-without-commit &&
67 test_expect_success
'non-fast-forward rebase refuses to write commits (interactive)' '
68 test_when_finished "git rebase --abort || true" &&
69 git checkout -B tmp side-with-commit &&
70 test_must_fail git rebase -i main
73 test_expect_success
'noop interactive rebase does not care about ident' '
74 git checkout -B tmp side-with-commit &&
78 test_expect_success REBASE_P \
79 'fast-forward rebase does not care about ident (preserve)' '
80 git checkout -B tmp side-without-commit &&
84 test_expect_success REBASE_P \
85 'non-fast-forward rebase refuses to write commits (preserve)' '
86 test_when_finished "git rebase --abort || true" &&
87 git checkout -B tmp side-with-commit &&
88 test_must_fail git rebase -p main
91 test_expect_success
'author.name overrides user.name' '
92 test_config user.name user &&
93 test_config user.email user@example.com &&
94 test_config author.name author &&
95 test_commit author-name-override-user &&
96 echo author user@example.com > expected-author &&
97 echo user user@example.com > expected-committer &&
98 git log --format="%an %ae" -1 > actual-author &&
99 git log --format="%cn %ce" -1 > actual-committer &&
100 test_cmp expected-author actual-author &&
101 test_cmp expected-committer actual-committer
104 test_expect_success
'author.email overrides user.email' '
105 test_config user.name user &&
106 test_config user.email user@example.com &&
107 test_config author.email author@example.com &&
108 test_commit author-email-override-user &&
109 echo user author@example.com > expected-author &&
110 echo user user@example.com > expected-committer &&
111 git log --format="%an %ae" -1 > actual-author &&
112 git log --format="%cn %ce" -1 > actual-committer &&
113 test_cmp expected-author actual-author &&
114 test_cmp expected-committer actual-committer
117 test_expect_success
'committer.name overrides user.name' '
118 test_config user.name user &&
119 test_config user.email user@example.com &&
120 test_config committer.name committer &&
121 test_commit committer-name-override-user &&
122 echo user user@example.com > expected-author &&
123 echo committer user@example.com > expected-committer &&
124 git log --format="%an %ae" -1 > actual-author &&
125 git log --format="%cn %ce" -1 > actual-committer &&
126 test_cmp expected-author actual-author &&
127 test_cmp expected-committer actual-committer
130 test_expect_success
'committer.email overrides user.email' '
131 test_config user.name user &&
132 test_config user.email user@example.com &&
133 test_config committer.email committer@example.com &&
134 test_commit committer-email-override-user &&
135 echo user user@example.com > expected-author &&
136 echo user committer@example.com > expected-committer &&
137 git log --format="%an %ae" -1 > actual-author &&
138 git log --format="%cn %ce" -1 > actual-committer &&
139 test_cmp expected-author actual-author &&
140 test_cmp expected-committer actual-committer
143 test_expect_success
'author and committer environment variables override config settings' '
144 test_config user.name user &&
145 test_config user.email user@example.com &&
146 test_config author.name author &&
147 test_config author.email author@example.com &&
148 test_config committer.name committer &&
149 test_config committer.email committer@example.com &&
150 GIT_AUTHOR_NAME=env_author && export GIT_AUTHOR_NAME &&
151 GIT_AUTHOR_EMAIL=env_author@example.com && export GIT_AUTHOR_EMAIL &&
152 GIT_COMMITTER_NAME=env_commit && export GIT_COMMITTER_NAME &&
153 GIT_COMMITTER_EMAIL=env_commit@example.com && export GIT_COMMITTER_EMAIL &&
154 test_commit env-override-conf &&
155 echo env_author env_author@example.com > expected-author &&
156 echo env_commit env_commit@example.com > expected-committer &&
157 git log --format="%an %ae" -1 > actual-author &&
158 git log --format="%cn %ce" -1 > actual-committer &&
159 sane_unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL &&
160 sane_unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL &&
161 test_cmp expected-author actual-author &&
162 test_cmp expected-committer actual-committer