Dan Aloni | 4d5c295 | 2016-02-06 08:23:36 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2016 Dan Aloni |
| 4 | # Copyright (c) 2016 Jeff King |
| 5 | # |
| 6 | |
| 7 | test_description='per-repo forced setting of email address' |
| 8 | |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 9 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 10 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 11 | |
Ævar Arnfjörð Bjarmason | 5ff6e8a | 2022-11-08 19:17:48 +0100 | [diff] [blame] | 12 | TEST_PASSES_SANITIZE_LEAK=true |
Dan Aloni | 4d5c295 | 2016-02-06 08:23:36 +0200 | [diff] [blame] | 13 | . ./test-lib.sh |
| 14 | |
| 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 && |
| 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 | |
| 26 | test_expect_success 'fails committing if clone email is not set' ' |
| 27 | test_must_fail git commit --allow-empty -m msg |
| 28 | ' |
| 29 | |
| 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 |
| 32 | ' |
| 33 | |
| 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 |
| 37 | ' |
| 38 | |
| 39 | test_expect_success 'succeeds cloning if global email is not set' ' |
| 40 | git clone . clone |
| 41 | ' |
| 42 | |
Jeff King | 1e461c4 | 2016-07-29 18:31:35 -0400 | [diff] [blame] | 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 |
| 50 | ' |
| 51 | |
| 52 | test_expect_success 'fast-forward rebase does not care about ident' ' |
| 53 | git checkout -B tmp side-without-commit && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 54 | git rebase main |
Jeff King | 1e461c4 | 2016-07-29 18:31:35 -0400 | [diff] [blame] | 55 | ' |
| 56 | |
| 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 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 60 | test_must_fail git rebase main |
Jeff King | 1e461c4 | 2016-07-29 18:31:35 -0400 | [diff] [blame] | 61 | ' |
| 62 | |
| 63 | test_expect_success 'fast-forward rebase does not care about ident (interactive)' ' |
| 64 | git checkout -B tmp side-without-commit && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 65 | git rebase -i main |
Jeff King | 1e461c4 | 2016-07-29 18:31:35 -0400 | [diff] [blame] | 66 | ' |
| 67 | |
| 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 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 71 | test_must_fail git rebase -i main |
Jeff King | 1e461c4 | 2016-07-29 18:31:35 -0400 | [diff] [blame] | 72 | ' |
| 73 | |
| 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^ |
| 77 | ' |
| 78 | |
William Hubbs | 39ab4d0 | 2019-02-04 12:48:50 -0600 | [diff] [blame] | 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 |
| 90 | ' |
| 91 | |
| 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 |
| 103 | ' |
| 104 | |
| 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 |
| 116 | ' |
| 117 | |
| 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 |
| 129 | ' |
| 130 | |
| 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 |
| 151 | ' |
| 152 | |
Dan Aloni | 4d5c295 | 2016-02-06 08:23:36 +0200 | [diff] [blame] | 153 | test_done |