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