comparison tests/test-branch-change.t @ 35745:3bd8ab4c80a5

branch: add a --rev flag to change branch name of given revisions This patch adds a new --rev flag to hg branch which can be used to change branch of revisions. This is motivated from topic extension where you can change topic on revisions but this one has few restrictions which are: 1) You cannot change branch name in between the stack 2) You cannot change branch name and set it to an existing name 3) You cannot change branch of non-linear set of commits 4) You cannot change branch of merge commits. Tests are added for the same. .. feature:: An experimental flag `--rev` to `hg branch` which can be used to change branch of changesets. Differential Revision: https://phab.mercurial-scm.org/D1074
author Pulkit Goyal <7895pulkit@gmail.com>
date Sun, 15 Oct 2017 23:08:45 +0530
parents
children e5b6ba786d83
comparison
equal deleted inserted replaced
35744:8685192a8733 35745:3bd8ab4c80a5
1 Testing changing branch on commits
2 ==================================
3
4 Setup
5
6 $ cat >> $HGRCPATH << EOF
7 > [alias]
8 > glog = log -G -T "{rev}:{node|short} {desc}\n{branch} ({bookmarks})"
9 > [experimental]
10 > evolution = createmarkers
11 > [extensions]
12 > rebase=
13 > EOF
14
15 $ hg init repo
16 $ cd repo
17 $ for ch in a b c d e; do echo foo >> $ch; hg ci -Aqm "Added "$ch; done
18 $ hg glog
19 @ 4:aa98ab95a928 Added e
20 | default ()
21 o 3:62615734edd5 Added d
22 | default ()
23 o 2:28ad74487de9 Added c
24 | default ()
25 o 1:29becc82797a Added b
26 | default ()
27 o 0:18d04c59bb5d Added a
28 default ()
29
30 $ hg branches
31 default 4:aa98ab95a928
32
33 Try without passing a new branch name
34
35 $ hg branch -r .
36 abort: no branch name specified for the revisions
37 [255]
38
39 Setting an invalid branch name
40
41 $ hg branch -r . a:b
42 abort: ':' cannot be used in a name
43 [255]
44 $ hg branch -r . tip
45 abort: the name 'tip' is reserved
46 [255]
47 $ hg branch -r . 1234
48 abort: cannot use an integer as a name
49 [255]
50
51 Change on non-linear set of commits
52
53 $ hg branch -r 2 -r 4 foo
54 abort: cannot change branch of non-linear revisions
55 [255]
56
57 Change in middle of the stack (linear commits)
58
59 $ hg branch -r 1::3 foo
60 abort: cannot change branch of changeset with children
61 [255]
62
63 Change with dirty working directory
64
65 $ echo bar > a
66 $ hg branch -r . foo
67 abort: uncommitted changes
68 [255]
69
70 $ hg revert --all
71 reverting a
72
73 Change on empty revision set
74
75 $ hg branch -r 'draft() - all()' foo
76 abort: empty revision set
77 [255]
78
79 Changing branch on linear set of commits from head
80
81 Without obsmarkers
82
83 $ hg branch -r 3:4 foo --config experimental.evolution=!
84 changed branch on 2 changesets
85 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/62615734edd5-e86bd13a-branch-change.hg (glob)
86 $ hg glog
87 @ 4:3938acfb5c0f Added e
88 | foo ()
89 o 3:9435da006bdc Added d
90 | foo ()
91 o 2:28ad74487de9 Added c
92 | default ()
93 o 1:29becc82797a Added b
94 | default ()
95 o 0:18d04c59bb5d Added a
96 default ()
97
98 $ hg branches
99 foo 4:3938acfb5c0f
100 default 2:28ad74487de9 (inactive)
101
102 With obsmarkers
103
104 $ hg branch -r 3::4 bar
105 changed branch on 2 changesets
106 $ hg glog
107 @ 6:7c1991464886 Added e
108 | bar ()
109 o 5:1ea05e93925f Added d
110 | bar ()
111 o 2:28ad74487de9 Added c
112 | default ()
113 o 1:29becc82797a Added b
114 | default ()
115 o 0:18d04c59bb5d Added a
116 default ()
117
118 $ hg branches
119 bar 6:7c1991464886
120 default 2:28ad74487de9 (inactive)
121
122 Change branch name to an existing branch
123
124 $ hg branch -r . default
125 abort: a branch of the same name already exists
126 [255]
127
128 Changing on a branch head which is not topological head
129
130 $ hg branch -r 2 stable
131 abort: cannot change branch of changeset with children
132 [255]
133
134 Enabling the allowunstable config and trying to change branch on a branch head
135 which is not a topological head
136
137 $ echo "[experimental]" >> .hg/hgrc
138 $ echo "evolution.allowunstable=yes" >> .hg/hgrc
139 $ hg branch -r 2 foo
140 changed branch on 1 changesets
141 2 new orphan changesets
142
143 Changing branch of an obsoleted changeset
144
145 $ hg branch -r 4 foobar
146 abort: hidden revision '4' was rewritten as: 7c1991464886!
147 (use --hidden to access hidden revisions)
148 [255]
149
150 $ hg branch -r 4 --hidden foobar
151 abort: cannot change branch of a obsolete changeset
152 [255]
153
154 Make sure bookmark movement is correct
155
156 $ hg bookmark b1
157 $ hg glog -r '.^::'
158 @ 6:7c1991464886 Added e
159 | bar (b1)
160 * 5:1ea05e93925f Added d
161 | bar ()
162 ~
163
164 $ hg branch -r '(.^)::' wat --debug
165 changing branch of '1ea05e93925f806d875a2163f9b76764be644636' from 'bar' to 'wat'
166 committing files:
167 d
168 committing manifest
169 committing changelog
170 new node id is 343660ccab7400da637bd6a211d07f413536d718
171 changing branch of '7c19914648869f5b02fc7fed31ddee9783fdd680' from 'bar' to 'wat'
172 committing files:
173 e
174 committing manifest
175 committing changelog
176 new node id is de1404b45a69f8cc6437d7679033ee33e9efb4ba
177 moving bookmarks ['b1'] from 7c19914648869f5b02fc7fed31ddee9783fdd680 to de1404b45a69f8cc6437d7679033ee33e9efb4ba
178 resolving manifests
179 branchmerge: False, force: False, partial: False
180 ancestor: 7c1991464886, local: 7c1991464886+, remote: de1404b45a69
181 changed branch on 2 changesets
182 updating the branch cache
183 invalid branchheads cache (served): tip differs
184
185 $ hg glog -r '(.^)::'
186 @ 9:de1404b45a69 Added e
187 | wat (b1)
188 * 8:343660ccab74 Added d
189 | wat ()
190 ~
191
192 Make sure phase handling is correct
193
194 $ echo foo >> bar
195 $ hg ci -Aqm "added bar" --secret
196 1 new orphan changesets
197 $ hg glog -r .
198 @ 10:8ad1294c1660 added bar
199 | wat (b1)
200 ~
201 $ hg branch -r . secret
202 changed branch on 1 changesets
203 $ hg phase -r .
204 11: secret
205
206 $ hg branches
207 secret 11:38a9b2d53f98
208 foo 7:8a4729a5e2b8
209 wat 9:de1404b45a69 (inactive)
210 default 2:28ad74487de9 (inactive)
211 $ hg branch
212 secret
213
214 Changing branch of another head, different from one on which we are
215
216 $ hg glog
217 @ 11:38a9b2d53f98 added bar
218 | secret (b1)
219 * 9:de1404b45a69 Added e
220 | wat ()
221 * 8:343660ccab74 Added d
222 | wat ()
223 | o 7:8a4729a5e2b8 Added c
224 | | foo ()
225 x | 2:28ad74487de9 Added c
226 |/ default ()
227 o 1:29becc82797a Added b
228 | default ()
229 o 0:18d04c59bb5d Added a
230 default ()
231
232 $ hg branch
233 secret
234
235 $ hg branch -r 7 foobar
236 changed branch on 1 changesets
237
238 The current branch must be preserved
239 $ hg branch
240 secret
241
242 Changing branch on multiple heads at once
243
244 $ hg rebase -s 8 -d 12 --keepbranches -q
245
246 $ hg rebase -s 14 -d 1 --keepbranches -q
247
248 $ hg branch -r 0: stable
249 changed branch on 6 changesets
250 $ hg glog
251 @ 23:6a5ddbcfb870 added bar
252 | stable (b1)
253 o 22:baedc6e98a67 Added e
254 | stable ()
255 | o 21:99ac7bf8aad1 Added d
256 | | stable ()
257 | o 20:0ecb4d39c4bd Added c
258 |/ stable ()
259 o 19:fd45b986b109 Added b
260 | stable ()
261 o 18:204d2769eca2 Added a
262 stable ()
263
264 $ hg branches
265 stable 23:6a5ddbcfb870
266
267 $ hg branch
268 stable
269
270 Changing to same branch name does not work
271
272 $ hg branch -r 19::21 stable
273 abort: a branch of the same name already exists
274 [255]
275
276 Testing on merge
277
278 $ hg merge -r 20
279 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
280 (branch merge, don't forget to commit)
281
282 $ hg branch -r . abcd
283 abort: outstanding uncommitted merge
284 [255]
285 $ hg ci -m "Merge commit"
286 $ hg branch -r '(.^)::' def
287 abort: cannot change branch of a merge commit
288 [255]
289
290 Changing branch on public changeset
291
292 $ hg phase -r 21 -p
293 $ hg branch -r 21 def
294 abort: cannot change branch of public changesets
295 (see 'hg help phases' for details)
296 [255]