Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='check various push.default settings' |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 6 | |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 7 | . ./test-lib.sh |
| 8 | |
| 9 | test_expect_success 'setup bare remotes' ' |
| 10 | git init --bare repo1 && |
| 11 | git remote add parent1 repo1 && |
| 12 | git init --bare repo2 && |
| 13 | git remote add parent2 repo2 && |
| 14 | test_commit one && |
| 15 | git push parent1 HEAD && |
| 16 | git push parent2 HEAD |
| 17 | ' |
| 18 | |
Matthieu Moy | 321e75c | 2012-04-24 09:50:02 +0200 | [diff] [blame] | 19 | # $1 = local revision |
| 20 | # $2 = remote revision (tested to be equal to the local one) |
Ramkumar Ramachandra | 396243f | 2013-06-19 16:41:43 +0530 | [diff] [blame] | 21 | # $3 = [optional] repo to check for actual output (repo1 by default) |
Matthieu Moy | 321e75c | 2012-04-24 09:50:02 +0200 | [diff] [blame] | 22 | check_pushed_commit () { |
| 23 | git log -1 --format='%h %s' "$1" >expect && |
Ramkumar Ramachandra | 396243f | 2013-06-19 16:41:43 +0530 | [diff] [blame] | 24 | git --git-dir="${3:-repo1}" log -1 --format='%h %s' "$2" >actual && |
Matthieu Moy | 321e75c | 2012-04-24 09:50:02 +0200 | [diff] [blame] | 25 | test_cmp expect actual |
| 26 | } |
| 27 | |
| 28 | # $1 = push.default value |
| 29 | # $2 = expected target branch for the push |
Ramkumar Ramachandra | 396243f | 2013-06-19 16:41:43 +0530 | [diff] [blame] | 30 | # $3 = [optional] repo to check for actual output (repo1 by default) |
Matthieu Moy | 321e75c | 2012-04-24 09:50:02 +0200 | [diff] [blame] | 31 | test_push_success () { |
Kyle J. McKay | ce026cc | 2015-03-08 08:37:50 -0700 | [diff] [blame] | 32 | git ${1:+-c} ${1:+push.default="$1"} push && |
Ramkumar Ramachandra | 396243f | 2013-06-19 16:41:43 +0530 | [diff] [blame] | 33 | check_pushed_commit HEAD "$2" "$3" |
Matthieu Moy | 321e75c | 2012-04-24 09:50:02 +0200 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | # $1 = push.default value |
| 37 | # check that push fails and does not modify any remote branch |
| 38 | test_push_failure () { |
| 39 | git --git-dir=repo1 log --no-walk --format='%h %s' --all >expect && |
Kyle J. McKay | ce026cc | 2015-03-08 08:37:50 -0700 | [diff] [blame] | 40 | test_must_fail git ${1:+-c} ${1:+push.default="$1"} push && |
Matthieu Moy | 321e75c | 2012-04-24 09:50:02 +0200 | [diff] [blame] | 41 | git --git-dir=repo1 log --no-walk --format='%h %s' --all >actual && |
| 42 | test_cmp expect actual |
| 43 | } |
| 44 | |
Ramkumar Ramachandra | 6e1696b | 2013-06-19 16:41:44 +0530 | [diff] [blame] | 45 | # $1 = success or failure |
| 46 | # $2 = push.default value |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 47 | # $3 = branch to check for actual output (main or foo) |
Ramkumar Ramachandra | 6e1696b | 2013-06-19 16:41:44 +0530 | [diff] [blame] | 48 | # $4 = [optional] switch to triangular workflow |
| 49 | test_pushdefault_workflow () { |
| 50 | workflow=central |
| 51 | pushdefault=parent1 |
| 52 | if test -n "${4-}"; then |
| 53 | workflow=triangular |
| 54 | pushdefault=parent2 |
| 55 | fi |
| 56 | test_expect_success "push.default = $2 $1 in $workflow workflows" " |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 57 | test_config branch.main.remote parent1 && |
| 58 | test_config branch.main.merge refs/heads/foo && |
Ramkumar Ramachandra | 6e1696b | 2013-06-19 16:41:44 +0530 | [diff] [blame] | 59 | test_config remote.pushdefault $pushdefault && |
| 60 | test_commit commit-for-$2${4+-triangular} && |
| 61 | test_push_$1 $2 $3 ${4+repo2} |
| 62 | " |
| 63 | } |
| 64 | |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 65 | test_expect_success '"upstream" pushes to configured upstream' ' |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 66 | git checkout main && |
| 67 | test_config branch.main.remote parent1 && |
| 68 | test_config branch.main.merge refs/heads/foo && |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 69 | test_commit two && |
Matthieu Moy | 321e75c | 2012-04-24 09:50:02 +0200 | [diff] [blame] | 70 | test_push_success upstream foo |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 71 | ' |
| 72 | |
| 73 | test_expect_success '"upstream" does not push on unconfigured remote' ' |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 74 | git checkout main && |
| 75 | test_unconfig branch.main.remote && |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 76 | test_commit three && |
Matthieu Moy | 321e75c | 2012-04-24 09:50:02 +0200 | [diff] [blame] | 77 | test_push_failure upstream |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 78 | ' |
| 79 | |
| 80 | test_expect_success '"upstream" does not push on unconfigured branch' ' |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 81 | git checkout main && |
| 82 | test_config branch.main.remote parent1 && |
| 83 | test_unconfig branch.main.merge && |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 84 | test_commit four && |
Matthieu Moy | 321e75c | 2012-04-24 09:50:02 +0200 | [diff] [blame] | 85 | test_push_failure upstream |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 86 | ' |
| 87 | |
| 88 | test_expect_success '"upstream" does not push when remotes do not match' ' |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 89 | git checkout main && |
| 90 | test_config branch.main.remote parent1 && |
| 91 | test_config branch.main.merge refs/heads/foo && |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 92 | test_config push.default upstream && |
| 93 | test_commit five && |
| 94 | test_must_fail git push parent2 |
| 95 | ' |
| 96 | |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 97 | test_expect_success 'push from/to new branch with upstream, matching and simple' ' |
| 98 | git checkout -b new-branch && |
| 99 | test_push_failure simple && |
| 100 | test_push_failure matching && |
| 101 | test_push_failure upstream |
| 102 | ' |
| 103 | |
Johannes Schindelin | 4d04658 | 2020-06-24 14:46:29 +0000 | [diff] [blame] | 104 | test_expect_success '"matching" fails if none match' ' |
| 105 | git init --bare empty && |
| 106 | test_must_fail git push empty : 2>actual && |
| 107 | test_i18ngrep "Perhaps you should specify a branch" actual |
| 108 | ' |
| 109 | |
Dennis Kaarsemaker | b284495 | 2016-10-31 21:38:35 +0100 | [diff] [blame] | 110 | test_expect_success 'push ambiguously named branch with upstream, matching and simple' ' |
| 111 | git checkout -b ambiguous && |
| 112 | test_config branch.ambiguous.remote parent1 && |
| 113 | test_config branch.ambiguous.merge refs/heads/ambiguous && |
| 114 | git tag ambiguous && |
| 115 | test_push_success simple ambiguous && |
| 116 | test_push_success matching ambiguous && |
| 117 | test_push_success upstream ambiguous |
| 118 | ' |
| 119 | |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 120 | test_expect_success 'push from/to new branch with current creates remote branch' ' |
| 121 | test_config branch.new-branch.remote repo1 && |
| 122 | git checkout new-branch && |
| 123 | test_push_success current new-branch |
| 124 | ' |
| 125 | |
| 126 | test_expect_success 'push to existing branch, with no upstream configured' ' |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 127 | test_config branch.main.remote repo1 && |
| 128 | git checkout main && |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 129 | test_push_failure simple && |
| 130 | test_push_failure upstream |
| 131 | ' |
| 132 | |
| 133 | test_expect_success 'push to existing branch, upstream configured with same name' ' |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 134 | test_config branch.main.remote repo1 && |
| 135 | test_config branch.main.merge refs/heads/main && |
| 136 | git checkout main && |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 137 | test_commit six && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 138 | test_push_success upstream main && |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 139 | test_commit seven && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 140 | test_push_success simple main |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 141 | ' |
| 142 | |
| 143 | test_expect_success 'push to existing branch, upstream configured with different name' ' |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 144 | test_config branch.main.remote repo1 && |
| 145 | test_config branch.main.merge refs/heads/other-name && |
| 146 | git checkout main && |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 147 | test_commit eight && |
| 148 | test_push_success upstream other-name && |
| 149 | test_commit nine && |
| 150 | test_push_failure simple && |
| 151 | git --git-dir=repo1 log -1 --format="%h %s" "other-name" >expect-other-name && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 152 | test_push_success current main && |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 153 | git --git-dir=repo1 log -1 --format="%h %s" "other-name" >actual-other-name && |
| 154 | test_cmp expect-other-name actual-other-name |
| 155 | ' |
| 156 | |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 157 | # We are on 'main', which integrates with 'foo' from parent1 |
Ramkumar Ramachandra | 6e1696b | 2013-06-19 16:41:44 +0530 | [diff] [blame] | 158 | # remote (set in test_pushdefault_workflow helper). Push to |
| 159 | # parent1 in centralized, and push to parent2 in triangular workflow. |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 160 | # The parent1 repository has 'main' and 'foo' branches, while |
| 161 | # the parent2 repository has only 'main' branch. |
Ramkumar Ramachandra | 6e1696b | 2013-06-19 16:41:44 +0530 | [diff] [blame] | 162 | # |
| 163 | # test_pushdefault_workflow() arguments: |
| 164 | # $1 = success or failure |
| 165 | # $2 = push.default value |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 166 | # $3 = branch to check for actual output (main or foo) |
Ramkumar Ramachandra | 6e1696b | 2013-06-19 16:41:44 +0530 | [diff] [blame] | 167 | # $4 = [optional] switch to triangular workflow |
| 168 | |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 169 | # update parent1's main (which is not our upstream) |
| 170 | test_pushdefault_workflow success current main |
Ramkumar Ramachandra | 6e1696b | 2013-06-19 16:41:44 +0530 | [diff] [blame] | 171 | |
| 172 | # update parent1's foo (which is our upstream) |
| 173 | test_pushdefault_workflow success upstream foo |
| 174 | |
Elijah Newren | 7a40cf1 | 2019-11-05 17:07:24 +0000 | [diff] [blame] | 175 | # upstream is foo which is not the name of the current branch |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 176 | test_pushdefault_workflow failure simple main |
Ramkumar Ramachandra | 6e1696b | 2013-06-19 16:41:44 +0530 | [diff] [blame] | 177 | |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 178 | # main and foo are updated |
| 179 | test_pushdefault_workflow success matching main |
Ramkumar Ramachandra | 6e1696b | 2013-06-19 16:41:44 +0530 | [diff] [blame] | 180 | |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 181 | # main is updated |
| 182 | test_pushdefault_workflow success current main triangular |
Ramkumar Ramachandra | 6e1696b | 2013-06-19 16:41:44 +0530 | [diff] [blame] | 183 | |
| 184 | # upstream mode cannot be used in triangular |
| 185 | test_pushdefault_workflow failure upstream foo triangular |
| 186 | |
| 187 | # in triangular, 'simple' works as 'current' and update the branch |
| 188 | # with the same name. |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 189 | test_pushdefault_workflow success simple main triangular |
Ramkumar Ramachandra | 6e1696b | 2013-06-19 16:41:44 +0530 | [diff] [blame] | 190 | |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 191 | # main is updated (parent2 does not have foo) |
| 192 | test_pushdefault_workflow success matching main triangular |
Ramkumar Ramachandra | 6e1696b | 2013-06-19 16:41:44 +0530 | [diff] [blame] | 193 | |
Jeff King | 00a6fa0 | 2014-11-26 22:43:06 -0500 | [diff] [blame] | 194 | # default tests, when no push-default is specified. This |
| 195 | # should behave the same as "simple" in non-triangular |
| 196 | # settings, and as "current" otherwise. |
| 197 | |
| 198 | test_expect_success 'default behavior allows "simple" push' ' |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 199 | test_config branch.main.remote parent1 && |
| 200 | test_config branch.main.merge refs/heads/main && |
Jeff King | 00a6fa0 | 2014-11-26 22:43:06 -0500 | [diff] [blame] | 201 | test_config remote.pushdefault parent1 && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 202 | test_commit default-main-main && |
| 203 | test_push_success "" main |
Jeff King | 00a6fa0 | 2014-11-26 22:43:06 -0500 | [diff] [blame] | 204 | ' |
| 205 | |
| 206 | test_expect_success 'default behavior rejects non-simple push' ' |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 207 | test_config branch.main.remote parent1 && |
| 208 | test_config branch.main.merge refs/heads/foo && |
Jeff King | 00a6fa0 | 2014-11-26 22:43:06 -0500 | [diff] [blame] | 209 | test_config remote.pushdefault parent1 && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 210 | test_commit default-main-foo && |
Jeff King | 00a6fa0 | 2014-11-26 22:43:06 -0500 | [diff] [blame] | 211 | test_push_failure "" |
| 212 | ' |
| 213 | |
| 214 | test_expect_success 'default triangular behavior acts like "current"' ' |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 215 | test_config branch.main.remote parent1 && |
| 216 | test_config branch.main.merge refs/heads/foo && |
Jeff King | 00a6fa0 | 2014-11-26 22:43:06 -0500 | [diff] [blame] | 217 | test_config remote.pushdefault parent2 && |
| 218 | test_commit default-triangular && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 219 | test_push_success "" main repo2 |
Jeff King | 00a6fa0 | 2014-11-26 22:43:06 -0500 | [diff] [blame] | 220 | ' |
| 221 | |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 222 | test_done |