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
'author.name overrides user.name' '
79 test_config user.name user &&
80 test_config user.email user@example.com &&
81 test_config author.name author &&
82 test_commit author-name-override-user &&
83 echo author user@example.com > expected-author &&
84 echo user user@example.com > expected-committer &&
85 git log --format="%an %ae" -1 > actual-author &&
86 git log --format="%cn %ce" -1 > actual-committer &&
87 test_cmp expected-author actual-author &&
88 test_cmp expected-committer actual-committer
91 test_expect_success
'author.email overrides user.email' '
92 test_config user.name user &&
93 test_config user.email user@example.com &&
94 test_config author.email author@example.com &&
95 test_commit author-email-override-user &&
96 echo user author@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
'committer.name overrides user.name' '
105 test_config user.name user &&
106 test_config user.email user@example.com &&
107 test_config committer.name committer &&
108 test_commit committer-name-override-user &&
109 echo user user@example.com > expected-author &&
110 echo committer 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.email overrides user.email' '
118 test_config user.name user &&
119 test_config user.email user@example.com &&
120 test_config committer.email committer@example.com &&
121 test_commit committer-email-override-user &&
122 echo user user@example.com > expected-author &&
123 echo user committer@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
'author and committer environment variables override config settings' '
131 test_config user.name user &&
132 test_config user.email user@example.com &&
133 test_config author.name author &&
134 test_config author.email author@example.com &&
135 test_config committer.name committer &&
136 test_config committer.email committer@example.com &&
137 GIT_AUTHOR_NAME=env_author && export GIT_AUTHOR_NAME &&
138 GIT_AUTHOR_EMAIL=env_author@example.com && export GIT_AUTHOR_EMAIL &&
139 GIT_COMMITTER_NAME=env_commit && export GIT_COMMITTER_NAME &&
140 GIT_COMMITTER_EMAIL=env_commit@example.com && export GIT_COMMITTER_EMAIL &&
141 test_commit env-override-conf &&
142 echo env_author env_author@example.com > expected-author &&
143 echo env_commit env_commit@example.com > expected-committer &&
144 git log --format="%an %ae" -1 > actual-author &&
145 git log --format="%cn %ce" -1 > actual-committer &&
146 sane_unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL &&
147 sane_unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL &&
148 test_cmp expected-author actual-author &&
149 test_cmp expected-committer actual-committer