]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7517-per-repo-email.sh
Merge branch 'pb/ci-matrix-wo-shortcut'
[thirdparty/git.git] / t / t7517-per-repo-email.sh
CommitLineData
4d5c2956
DA
1#!/bin/sh
2#
3# Copyright (c) 2016 Dan Aloni
4# Copyright (c) 2016 Jeff King
5#
6
7test_description='per-repo forced setting of email address'
8
1e2ae142 9GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
10export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11
4d5c2956
DA
12. ./test-lib.sh
13
14test_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.
17 test_commit foo &&
18
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
23'
24
25test_expect_success 'fails committing if clone email is not set' '
26 test_must_fail git commit --allow-empty -m msg
27'
28
29test_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
31'
32
33test_expect_success 'succeeds committing if clone email is set' '
34 test_config user.email "test@ok.com" &&
35 git commit --allow-empty -m msg
36'
37
38test_expect_success 'succeeds cloning if global email is not set' '
39 git clone . clone
40'
41
1e461c4f
JK
42test_expect_success 'set up rebase scenarios' '
43 # temporarily enable an actual ident for this setup
44 test_config user.email foo@example.com &&
45 test_commit new &&
46 git branch side-without-commit HEAD^ &&
47 git checkout -b side-with-commit HEAD^ &&
48 test_commit side
49'
50
51test_expect_success 'fast-forward rebase does not care about ident' '
52 git checkout -B tmp side-without-commit &&
1e2ae142 53 git rebase main
1e461c4f
JK
54'
55
56test_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 &&
1e2ae142 59 test_must_fail git rebase main
1e461c4f
JK
60'
61
62test_expect_success 'fast-forward rebase does not care about ident (interactive)' '
63 git checkout -B tmp side-without-commit &&
1e2ae142 64 git rebase -i main
1e461c4f
JK
65'
66
67test_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 &&
1e2ae142 70 test_must_fail git rebase -i main
1e461c4f
JK
71'
72
73test_expect_success 'noop interactive rebase does not care about ident' '
74 git checkout -B tmp side-with-commit &&
75 git rebase -i HEAD^
76'
77
11aad464
JS
78test_expect_success REBASE_P \
79 'fast-forward rebase does not care about ident (preserve)' '
1e461c4f 80 git checkout -B tmp side-without-commit &&
1e2ae142 81 git rebase -p main
1e461c4f
JK
82'
83
11aad464
JS
84test_expect_success REBASE_P \
85 'non-fast-forward rebase refuses to write commits (preserve)' '
1e461c4f
JK
86 test_when_finished "git rebase --abort || true" &&
87 git checkout -B tmp side-with-commit &&
1e2ae142 88 test_must_fail git rebase -p main
1e461c4f
JK
89'
90
39ab4d09
WH
91test_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
102'
103
104test_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
115'
116
117test_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
128'
129
130test_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
141'
142
143test_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
163'
164
4d5c2956 165test_done