| 1 |
$ branchcache=.hg/cache/branch2 |
| 2 |
|
| 3 |
$ listbranchcaches() { |
| 4 |
> for f in .hg/cache/branch2*; |
| 5 |
> do echo === $f ===; |
| 6 |
> cat $f; |
| 7 |
> done; |
| 8 |
> } |
| 9 |
$ purgebranchcaches() { |
| 10 |
> rm .hg/cache/branch2* |
| 11 |
> } |
| 12 |
|
| 13 |
$ hg init t |
| 14 |
$ cd t |
| 15 |
|
| 16 |
$ hg branches |
| 17 |
$ echo foo > a |
| 18 |
$ hg add a |
| 19 |
$ hg ci -m "initial" |
| 20 |
$ hg branch foo |
| 21 |
marked working directory as branch foo |
| 22 |
(branches are permanent and global, did you want a bookmark?) |
| 23 |
$ hg branch |
| 24 |
foo |
| 25 |
$ hg ci -m "add branch name" |
| 26 |
$ hg branch bar |
| 27 |
marked working directory as branch bar |
| 28 |
$ hg ci -m "change branch name" |
| 29 |
|
| 30 |
Branch shadowing: |
| 31 |
|
| 32 |
$ hg branch default |
| 33 |
abort: a branch of the same name already exists |
| 34 |
(use 'hg update' to switch to it) |
| 35 |
[10] |
| 36 |
|
| 37 |
$ hg branch -f default |
| 38 |
marked working directory as branch default |
| 39 |
|
| 40 |
$ hg ci -m "clear branch name" |
| 41 |
created new head |
| 42 |
|
| 43 |
There should be only one default branch head |
| 44 |
|
| 45 |
$ hg heads . |
| 46 |
changeset: 3:1c28f494dae6 |
| 47 |
tag: tip |
| 48 |
user: test |
| 49 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 50 |
summary: clear branch name |
| 51 |
|
| 52 |
Merging and branches |
| 53 |
|
| 54 |
$ hg co foo |
| 55 |
0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 56 |
$ hg branch |
| 57 |
foo |
| 58 |
|
| 59 |
set existing branch name fails unless force - setting existing parent branch works without force: |
| 60 |
|
| 61 |
$ hg branch bar |
| 62 |
abort: a branch of the same name already exists |
| 63 |
(use 'hg update' to switch to it) |
| 64 |
[10] |
| 65 |
|
| 66 |
$ hg branch -f bar |
| 67 |
marked working directory as branch bar |
| 68 |
|
| 69 |
$ hg branch foo |
| 70 |
marked working directory as branch foo |
| 71 |
|
| 72 |
$ echo bleah > a |
| 73 |
$ hg ci -m "modify a branch" |
| 74 |
|
| 75 |
$ hg merge default |
| 76 |
0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 77 |
(branch merge, don't forget to commit) |
| 78 |
|
| 79 |
$ hg branch |
| 80 |
foo |
| 81 |
|
| 82 |
set existing branch name where branch head is ancestor: |
| 83 |
|
| 84 |
$ hg branch bar |
| 85 |
abort: a branch of the same name already exists |
| 86 |
(use 'hg update' to switch to it) |
| 87 |
[10] |
| 88 |
|
| 89 |
set (other) parent branch as branch name |
| 90 |
|
| 91 |
$ hg branch default |
| 92 |
marked working directory as branch default |
| 93 |
|
| 94 |
set (first) parent branch as branch name |
| 95 |
|
| 96 |
$ hg branch foo |
| 97 |
marked working directory as branch foo |
| 98 |
|
| 99 |
$ hg ci -m "merge" |
| 100 |
|
| 101 |
$ hg log -G -T '{rev}:{node|short} {branch} {desc}\n' |
| 102 |
@ 5:530046499edf foo merge |
| 103 |
|\ |
| 104 |
| o 4:adf1a74a7f7b foo modify a branch |
| 105 |
| | |
| 106 |
o | 3:1c28f494dae6 default clear branch name |
| 107 |
| | |
| 108 |
o | 2:c21617b13b22 bar change branch name |
| 109 |
|/ |
| 110 |
o 1:6c0e42da283a foo add branch name |
| 111 |
| |
| 112 |
o 0:db01e8ea3388 default initial |
| 113 |
|
| 114 |
$ hg branches |
| 115 |
foo 5:530046499edf |
| 116 |
default 3:1c28f494dae6 (inactive) |
| 117 |
bar 2:c21617b13b22 (inactive) |
| 118 |
|
| 119 |
$ hg branches -q |
| 120 |
foo |
| 121 |
default |
| 122 |
bar |
| 123 |
|
| 124 |
Test for invalid branch cache: |
| 125 |
|
| 126 |
$ hg rollback |
| 127 |
repository tip rolled back to revision 4 (undo commit) |
| 128 |
working directory now based on revisions 4 and 3 |
| 129 |
|
| 130 |
$ cp ${branchcache}-served .hg/bc-invalid |
| 131 |
|
| 132 |
$ hg log -r foo |
| 133 |
changeset: 4:adf1a74a7f7b |
| 134 |
branch: foo |
| 135 |
tag: tip |
| 136 |
parent: 1:6c0e42da283a |
| 137 |
user: test |
| 138 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 139 |
summary: modify a branch |
| 140 |
|
| 141 |
$ cp .hg/bc-invalid $branchcache |
| 142 |
|
| 143 |
$ hg --debug log -r foo |
| 144 |
changeset: 4:adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 |
| 145 |
branch: foo |
| 146 |
tag: tip |
| 147 |
phase: draft |
| 148 |
parent: 1:6c0e42da283a56b5edc5b4fadb491365ec7f5fa8 |
| 149 |
parent: -1:0000000000000000000000000000000000000000 |
| 150 |
manifest: 1:8c342a37dfba0b3d3ce073562a00d8a813c54ffe |
| 151 |
user: test |
| 152 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 153 |
files: a |
| 154 |
extra: branch=foo |
| 155 |
description: |
| 156 |
modify a branch |
| 157 |
|
| 158 |
|
| 159 |
$ purgebranchcaches |
| 160 |
$ echo corrupted > $branchcache |
| 161 |
|
| 162 |
$ hg log -qr foo |
| 163 |
4:adf1a74a7f7b |
| 164 |
|
| 165 |
$ listbranchcaches |
| 166 |
=== .hg/cache/branch2 === |
| 167 |
corrupted |
| 168 |
=== .hg/cache/branch2-served === |
| 169 |
adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 4 |
| 170 |
c21617b13b220988e7a2e26290fbe4325ffa7139 o bar |
| 171 |
1c28f494dae69a2f8fc815059d257eccf3fcfe75 o default |
| 172 |
adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 o foo |
| 173 |
|
| 174 |
Push should update the branch cache: |
| 175 |
|
| 176 |
$ hg init ../target |
| 177 |
|
| 178 |
Pushing just rev 0: |
| 179 |
|
| 180 |
$ hg push -qr 0 ../target |
| 181 |
|
| 182 |
$ (cd ../target/; listbranchcaches) |
| 183 |
=== .hg/cache/branch2-base === |
| 184 |
db01e8ea3388fd3c7c94e1436ea2bd6a53d581c5 0 |
| 185 |
db01e8ea3388fd3c7c94e1436ea2bd6a53d581c5 o default |
| 186 |
|
| 187 |
Pushing everything: |
| 188 |
|
| 189 |
$ hg push -qf ../target |
| 190 |
|
| 191 |
$ (cd ../target/; listbranchcaches) |
| 192 |
=== .hg/cache/branch2-base === |
| 193 |
adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 4 |
| 194 |
c21617b13b220988e7a2e26290fbe4325ffa7139 o bar |
| 195 |
1c28f494dae69a2f8fc815059d257eccf3fcfe75 o default |
| 196 |
adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 o foo |
| 197 |
|
| 198 |
Update with no arguments: tipmost revision of the current branch: |
| 199 |
|
| 200 |
$ hg up -q -C 0 |
| 201 |
$ hg up -q |
| 202 |
$ hg id |
| 203 |
1c28f494dae6 |
| 204 |
|
| 205 |
$ hg up -q 1 |
| 206 |
$ hg up -q |
| 207 |
$ hg id |
| 208 |
adf1a74a7f7b (foo) tip |
| 209 |
|
| 210 |
$ hg branch foobar |
| 211 |
marked working directory as branch foobar |
| 212 |
|
| 213 |
$ hg up |
| 214 |
0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 215 |
|
| 216 |
Fast-forward merge: |
| 217 |
|
| 218 |
$ hg branch ff |
| 219 |
marked working directory as branch ff |
| 220 |
|
| 221 |
$ echo ff > ff |
| 222 |
$ hg ci -Am'fast forward' |
| 223 |
adding ff |
| 224 |
|
| 225 |
$ hg up foo |
| 226 |
0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
| 227 |
|
| 228 |
$ hg merge ff |
| 229 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 230 |
(branch merge, don't forget to commit) |
| 231 |
|
| 232 |
$ hg branch |
| 233 |
foo |
| 234 |
$ hg commit -m'Merge ff into foo' |
| 235 |
$ hg parents |
| 236 |
changeset: 6:185ffbfefa30 |
| 237 |
branch: foo |
| 238 |
tag: tip |
| 239 |
parent: 4:adf1a74a7f7b |
| 240 |
parent: 5:1a3c27dc5e11 |
| 241 |
user: test |
| 242 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 243 |
summary: Merge ff into foo |
| 244 |
|
| 245 |
$ hg manifest |
| 246 |
a |
| 247 |
ff |
| 248 |
|
| 249 |
|
| 250 |
Test merging, add 3 default heads and one test head: |
| 251 |
|
| 252 |
$ cd .. |
| 253 |
$ hg init merges |
| 254 |
$ cd merges |
| 255 |
$ echo a > a |
| 256 |
$ hg ci -Ama |
| 257 |
adding a |
| 258 |
|
| 259 |
$ echo b > b |
| 260 |
$ hg ci -Amb |
| 261 |
adding b |
| 262 |
|
| 263 |
$ hg up 0 |
| 264 |
0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
| 265 |
$ echo c > c |
| 266 |
$ hg ci -Amc |
| 267 |
adding c |
| 268 |
created new head |
| 269 |
|
| 270 |
$ hg up 0 |
| 271 |
0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
| 272 |
$ echo d > d |
| 273 |
$ hg ci -Amd |
| 274 |
adding d |
| 275 |
created new head |
| 276 |
|
| 277 |
$ hg up 0 |
| 278 |
0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
| 279 |
$ hg branch test |
| 280 |
marked working directory as branch test |
| 281 |
(branches are permanent and global, did you want a bookmark?) |
| 282 |
$ echo e >> e |
| 283 |
$ hg ci -Ame |
| 284 |
adding e |
| 285 |
|
| 286 |
$ hg log |
| 287 |
changeset: 4:3a1e01ed1df4 |
| 288 |
branch: test |
| 289 |
tag: tip |
| 290 |
parent: 0:cb9a9f314b8b |
| 291 |
user: test |
| 292 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 293 |
summary: e |
| 294 |
|
| 295 |
changeset: 3:980f7dc84c29 |
| 296 |
parent: 0:cb9a9f314b8b |
| 297 |
user: test |
| 298 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 299 |
summary: d |
| 300 |
|
| 301 |
changeset: 2:d36c0562f908 |
| 302 |
parent: 0:cb9a9f314b8b |
| 303 |
user: test |
| 304 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 305 |
summary: c |
| 306 |
|
| 307 |
changeset: 1:d2ae7f538514 |
| 308 |
user: test |
| 309 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 310 |
summary: b |
| 311 |
|
| 312 |
changeset: 0:cb9a9f314b8b |
| 313 |
user: test |
| 314 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 315 |
summary: a |
| 316 |
|
| 317 |
Implicit merge with test branch as parent: |
| 318 |
|
| 319 |
$ hg merge |
| 320 |
abort: branch 'test' has one head - please merge with an explicit rev |
| 321 |
(run 'hg heads' to see all heads, specify rev with -r) |
| 322 |
[255] |
| 323 |
$ hg up -C default |
| 324 |
1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
| 325 |
|
| 326 |
Implicit merge with default branch as parent: |
| 327 |
|
| 328 |
$ hg merge |
| 329 |
abort: branch 'default' has 3 heads - please merge with an explicit rev |
| 330 |
(run 'hg heads .' to see heads, specify rev with -r) |
| 331 |
[255] |
| 332 |
|
| 333 |
3 branch heads, explicit merge required: |
| 334 |
|
| 335 |
$ hg merge 2 |
| 336 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 337 |
(branch merge, don't forget to commit) |
| 338 |
$ hg ci -m merge |
| 339 |
|
| 340 |
2 branch heads, implicit merge works: |
| 341 |
|
| 342 |
$ hg merge |
| 343 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 344 |
(branch merge, don't forget to commit) |
| 345 |
|
| 346 |
$ cd .. |
| 347 |
|
| 348 |
We expect that bare update on new branch, updates to parent |
| 349 |
|
| 350 |
$ hg init bareupdateonnewbranch |
| 351 |
$ cd bareupdateonnewbranch |
| 352 |
$ hg update |
| 353 |
0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 354 |
$ touch a |
| 355 |
$ hg commit -A -m "a" |
| 356 |
adding a |
| 357 |
$ touch b |
| 358 |
$ hg commit -A -m "b" |
| 359 |
adding b |
| 360 |
$ touch c |
| 361 |
$ hg commit -A -m "c" |
| 362 |
adding c |
| 363 |
$ hg update -r 1 |
| 364 |
0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
| 365 |
$ hg log -G |
| 366 |
o changeset: 2:991a3460af53 |
| 367 |
| tag: tip |
| 368 |
| user: test |
| 369 |
| date: Thu Jan 01 00:00:00 1970 +0000 |
| 370 |
| summary: c |
| 371 |
| |
| 372 |
@ changeset: 1:0e067c57feba |
| 373 |
| user: test |
| 374 |
| date: Thu Jan 01 00:00:00 1970 +0000 |
| 375 |
| summary: b |
| 376 |
| |
| 377 |
o changeset: 0:3903775176ed |
| 378 |
user: test |
| 379 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 380 |
summary: a |
| 381 |
|
| 382 |
$ hg branch dev |
| 383 |
marked working directory as branch dev |
| 384 |
(branches are permanent and global, did you want a bookmark?) |
| 385 |
$ hg update |
| 386 |
0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 387 |
$ hg summary |
| 388 |
parent: 1:0e067c57feba |
| 389 |
b |
| 390 |
branch: dev |
| 391 |
commit: (new branch) |
| 392 |
update: (current) |
| 393 |
phases: 3 draft |
| 394 |
|
| 395 |
$ cd .. |
| 396 |
|
| 397 |
We need special handling for repositories with no "default" branch because |
| 398 |
"null" revision belongs to non-existent "default" branch. |
| 399 |
|
| 400 |
$ hg init nodefault |
| 401 |
$ cd nodefault |
| 402 |
$ hg branch -q foo |
| 403 |
$ touch 0 |
| 404 |
$ hg ci -Aqm0 |
| 405 |
$ touch 1 |
| 406 |
$ hg ci -Aqm1 |
| 407 |
$ hg update -qr0 |
| 408 |
$ hg branch -q bar |
| 409 |
$ touch 2 |
| 410 |
$ hg ci -Aqm2 |
| 411 |
$ hg update -qr0 |
| 412 |
$ hg branch -q baz |
| 413 |
$ touch 3 |
| 414 |
$ hg ci -Aqm3 |
| 415 |
$ hg ci --close-branch -m 'close baz' |
| 416 |
$ hg update -q null |
| 417 |
$ hg log -GT'{rev} {branch}\n' |
| 418 |
_ 4 baz |
| 419 |
| |
| 420 |
o 3 baz |
| 421 |
| |
| 422 |
| o 2 bar |
| 423 |
|/ |
| 424 |
| o 1 foo |
| 425 |
|/ |
| 426 |
o 0 foo |
| 427 |
|
| 428 |
|
| 429 |
a) updating from "null" should bring us to the tip-most branch head as |
| 430 |
there is no "default" branch: |
| 431 |
|
| 432 |
$ hg update -q null |
| 433 |
$ hg id -bn |
| 434 |
-1 default |
| 435 |
$ hg update |
| 436 |
2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 437 |
$ hg id -bn |
| 438 |
2 bar |
| 439 |
|
| 440 |
b) but if we are at uncommitted "default" branch, we should stick to the |
| 441 |
current revision: |
| 442 |
|
| 443 |
$ hg update -q 0 |
| 444 |
$ hg branch default |
| 445 |
marked working directory as branch default |
| 446 |
$ hg id -bn |
| 447 |
0 default |
| 448 |
$ hg update |
| 449 |
0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 450 |
$ hg id -bn |
| 451 |
0 default |
| 452 |
|
| 453 |
c) also, if we have uncommitted branch at "null", we should stick to it: |
| 454 |
|
| 455 |
$ hg update -q null |
| 456 |
$ hg branch new |
| 457 |
marked working directory as branch new |
| 458 |
$ hg id -bn |
| 459 |
-1 new |
| 460 |
$ hg update |
| 461 |
0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 462 |
$ hg id -bn |
| 463 |
-1 new |
| 464 |
|
| 465 |
$ cd .. |
| 466 |
|
| 467 |
We expect that update --clean discard changes in working directory, |
| 468 |
and updates to the head of parent branch. |
| 469 |
|
| 470 |
$ hg init updatebareclean |
| 471 |
$ cd updatebareclean |
| 472 |
$ hg update --clean |
| 473 |
0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 474 |
$ touch a |
| 475 |
$ hg commit -A -m "a" |
| 476 |
adding a |
| 477 |
$ touch b |
| 478 |
$ hg commit -A -m "b" |
| 479 |
adding b |
| 480 |
$ touch c |
| 481 |
$ hg commit -A -m "c" |
| 482 |
adding c |
| 483 |
$ hg log |
| 484 |
changeset: 2:991a3460af53 |
| 485 |
tag: tip |
| 486 |
user: test |
| 487 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 488 |
summary: c |
| 489 |
|
| 490 |
changeset: 1:0e067c57feba |
| 491 |
user: test |
| 492 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 493 |
summary: b |
| 494 |
|
| 495 |
changeset: 0:3903775176ed |
| 496 |
user: test |
| 497 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 498 |
summary: a |
| 499 |
|
| 500 |
$ hg update -r 1 |
| 501 |
0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
| 502 |
$ hg branch new-branch |
| 503 |
marked working directory as branch new-branch |
| 504 |
(branches are permanent and global, did you want a bookmark?) |
| 505 |
$ echo "aa" >> a |
| 506 |
$ hg update --clean |
| 507 |
2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 508 |
$ hg status |
| 509 |
$ hg branch |
| 510 |
default |
| 511 |
$ hg parent |
| 512 |
changeset: 2:991a3460af53 |
| 513 |
tag: tip |
| 514 |
user: test |
| 515 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 516 |
summary: c |
| 517 |
|
| 518 |
We expect that update --clean on non existing parent discards a new branch |
| 519 |
and updates to the tipmost non-closed branch head |
| 520 |
|
| 521 |
$ hg update null |
| 522 |
0 files updated, 0 files merged, 3 files removed, 0 files unresolved |
| 523 |
$ hg branch newbranch |
| 524 |
marked working directory as branch newbranch |
| 525 |
(branches are permanent and global, did you want a bookmark?) |
| 526 |
$ hg update -C |
| 527 |
3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 528 |
$ hg summary |
| 529 |
parent: 2:991a3460af53 tip |
| 530 |
c |
| 531 |
branch: default |
| 532 |
commit: (clean) |
| 533 |
update: (current) |
| 534 |
phases: 3 draft |