Merge branch 'js/var-git-shell-path'
[git/debian.git] / t / t7517-per-repo-email.sh
blobefc6496e2b27f3ec74431d625e64e52c384e0383
1 #!/bin/sh
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
12 TEST_PASSES_SANITIZE_LEAK=true
13 . ./test-lib.sh
15 test_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 &&
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
26 test_expect_success 'fails committing if clone email is not set' '
27 test_must_fail git commit --allow-empty -m msg
30 test_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
34 test_expect_success 'succeeds committing if clone email is set' '
35 test_config user.email "test@ok.com" &&
36 git commit --allow-empty -m msg
39 test_expect_success 'succeeds cloning if global email is not set' '
40 git clone . clone
43 test_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
52 test_expect_success 'fast-forward rebase does not care about ident' '
53 git checkout -B tmp side-without-commit &&
54 git rebase main
57 test_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 &&
60 test_must_fail git rebase main
63 test_expect_success 'fast-forward rebase does not care about ident (interactive)' '
64 git checkout -B tmp side-without-commit &&
65 git rebase -i main
68 test_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 &&
71 test_must_fail git rebase -i main
74 test_expect_success 'noop interactive rebase does not care about ident' '
75 git checkout -B tmp side-with-commit &&
76 git rebase -i HEAD^
79 test_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
92 test_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
105 test_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
118 test_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
131 test_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
153 test_done