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