]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7517-per-repo-email.sh
The third batch
[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
5ff6e8af 12TEST_PASSES_SANITIZE_LEAK=true
4d5c2956
DA
13. ./test-lib.sh
14
15test_expect_success 'setup a likely user.useConfigOnly use case' '
16 # we want to make sure a reflog is written, since that needs
17 # a non-strict ident. So be sure we have an actual commit.
18 test_commit foo &&
19
20 sane_unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL &&
21 sane_unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL &&
22 git config user.name "test" &&
23 git config --global user.useConfigOnly true
24'
25
26test_expect_success 'fails committing if clone email is not set' '
27 test_must_fail git commit --allow-empty -m msg
28'
29
30test_expect_success 'fails committing if clone email is not set, but EMAIL set' '
31 test_must_fail env EMAIL=test@fail.com git commit --allow-empty -m msg
32'
33
34test_expect_success 'succeeds committing if clone email is set' '
35 test_config user.email "test@ok.com" &&
36 git commit --allow-empty -m msg
37'
38
39test_expect_success 'succeeds cloning if global email is not set' '
40 git clone . clone
41'
42
1e461c4f
JK
43test_expect_success 'set up rebase scenarios' '
44 # temporarily enable an actual ident for this setup
45 test_config user.email foo@example.com &&
46 test_commit new &&
47 git branch side-without-commit HEAD^ &&
48 git checkout -b side-with-commit HEAD^ &&
49 test_commit side
50'
51
52test_expect_success 'fast-forward rebase does not care about ident' '
53 git checkout -B tmp side-without-commit &&
1e2ae142 54 git rebase main
1e461c4f
JK
55'
56
57test_expect_success 'non-fast-forward rebase refuses to write commits' '
58 test_when_finished "git rebase --abort || true" &&
59 git checkout -B tmp side-with-commit &&
1e2ae142 60 test_must_fail git rebase main
1e461c4f
JK
61'
62
63test_expect_success 'fast-forward rebase does not care about ident (interactive)' '
64 git checkout -B tmp side-without-commit &&
1e2ae142 65 git rebase -i main
1e461c4f
JK
66'
67
68test_expect_success 'non-fast-forward rebase refuses to write commits (interactive)' '
69 test_when_finished "git rebase --abort || true" &&
70 git checkout -B tmp side-with-commit &&
1e2ae142 71 test_must_fail git rebase -i main
1e461c4f
JK
72'
73
74test_expect_success 'noop interactive rebase does not care about ident' '
75 git checkout -B tmp side-with-commit &&
76 git rebase -i HEAD^
77'
78
39ab4d09
WH
79test_expect_success 'author.name overrides user.name' '
80 test_config user.name user &&
81 test_config user.email user@example.com &&
82 test_config author.name author &&
83 test_commit author-name-override-user &&
84 echo author user@example.com > expected-author &&
85 echo user user@example.com > expected-committer &&
86 git log --format="%an %ae" -1 > actual-author &&
87 git log --format="%cn %ce" -1 > actual-committer &&
88 test_cmp expected-author actual-author &&
89 test_cmp expected-committer actual-committer
90'
91
92test_expect_success 'author.email overrides user.email' '
93 test_config user.name user &&
94 test_config user.email user@example.com &&
95 test_config author.email author@example.com &&
96 test_commit author-email-override-user &&
97 echo user author@example.com > expected-author &&
98 echo user user@example.com > expected-committer &&
99 git log --format="%an %ae" -1 > actual-author &&
100 git log --format="%cn %ce" -1 > actual-committer &&
101 test_cmp expected-author actual-author &&
102 test_cmp expected-committer actual-committer
103'
104
105test_expect_success 'committer.name overrides user.name' '
106 test_config user.name user &&
107 test_config user.email user@example.com &&
108 test_config committer.name committer &&
109 test_commit committer-name-override-user &&
110 echo user user@example.com > expected-author &&
111 echo committer user@example.com > expected-committer &&
112 git log --format="%an %ae" -1 > actual-author &&
113 git log --format="%cn %ce" -1 > actual-committer &&
114 test_cmp expected-author actual-author &&
115 test_cmp expected-committer actual-committer
116'
117
118test_expect_success 'committer.email overrides user.email' '
119 test_config user.name user &&
120 test_config user.email user@example.com &&
121 test_config committer.email committer@example.com &&
122 test_commit committer-email-override-user &&
123 echo user user@example.com > expected-author &&
124 echo user committer@example.com > expected-committer &&
125 git log --format="%an %ae" -1 > actual-author &&
126 git log --format="%cn %ce" -1 > actual-committer &&
127 test_cmp expected-author actual-author &&
128 test_cmp expected-committer actual-committer
129'
130
131test_expect_success 'author and committer environment variables override config settings' '
132 test_config user.name user &&
133 test_config user.email user@example.com &&
134 test_config author.name author &&
135 test_config author.email author@example.com &&
136 test_config committer.name committer &&
137 test_config committer.email committer@example.com &&
138 GIT_AUTHOR_NAME=env_author && export GIT_AUTHOR_NAME &&
139 GIT_AUTHOR_EMAIL=env_author@example.com && export GIT_AUTHOR_EMAIL &&
140 GIT_COMMITTER_NAME=env_commit && export GIT_COMMITTER_NAME &&
141 GIT_COMMITTER_EMAIL=env_commit@example.com && export GIT_COMMITTER_EMAIL &&
142 test_commit env-override-conf &&
143 echo env_author env_author@example.com > expected-author &&
144 echo env_commit env_commit@example.com > expected-committer &&
145 git log --format="%an %ae" -1 > actual-author &&
146 git log --format="%cn %ce" -1 > actual-committer &&
147 sane_unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL &&
148 sane_unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL &&
149 test_cmp expected-author actual-author &&
150 test_cmp expected-committer actual-committer
151'
152
4d5c2956 153test_done