annotate test/org/tmatesoft/hg/test/TestBranches.java @ 341:75c452fdd76a

Merging state not detected when there's no conflicts to resolve (no merge/state file)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 17 Nov 2011 07:04:58 +0100
parents 8952f89be195
children
rev   line source
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2011 TMate Software Ltd
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.test;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import static org.junit.Assert.*;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import org.junit.Test;
315
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
22 import org.tmatesoft.hg.core.Nodeid;
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import org.tmatesoft.hg.repo.HgBranches;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import org.tmatesoft.hg.repo.HgBranches.BranchInfo;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.tmatesoft.hg.repo.HgRepository;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 /**
315
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
28 * <pre>
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
29 * branches-1/create.bat:
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
30 * branch1 to have fork, two heads, both closed -- shall be recognized as closed
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
31 * branch2 to have fork, two heads, one closed -- shall be recognized as active
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
32 * branch3 no active head -- shall be recognized as inactive
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
33 * branch4 to fork, with 1 inactive and 1 active heads
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
34 * branch5 to be closed and reopened
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
35 * </pre>
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
36 *
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 * @author Artem Tikhomirov
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 * @author TMate Software Ltd.
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 */
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 public class TestBranches {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 @Test
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 public void testClosedInactiveBranches() throws Exception {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 HgRepository repo = Configuration.get().find("branches-1");
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 HgBranches branches = repo.getBranches();
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 BranchInfo b1 = branches.getBranch("branch1");
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 assertNotNull(b1);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 assertTrue(b1.isClosed());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 assertEquals(2, b1.getHeads().size());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 // order is important!
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 assertEquals("131e84b878d25b5eab7f529ebb35e57b2a439db7", b1.getHeads().get(0).toString());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 assertEquals("c993cda1f5a7afd771efa87fe95fb7c5f73169e6", b1.getHeads().get(1).toString());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 //
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 BranchInfo b2 = branches.getBranch("branch2");
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 assertNotNull(b2);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 assertFalse(b2.isClosed());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 assertEquals(2, b2.getHeads().size());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 assertEquals("537f548adfd7eb9ce2a73ed7e7ca163eb1b61401", b2.getHeads().get(0).toString());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 assertEquals("e698babd9479b1c07e0ed3155f5e290ee15affed", b2.getHeads().get(1).toString());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 //
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 BranchInfo b3 = branches.getBranch("branch3");
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 assertNotNull(b3);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 assertFalse(b3.isClosed());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 assertEquals(1, b3.getHeads().size());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 assertEquals("b103f33723f37c7bb4b81d74a66135d6fdaf0ced", b3.getHeads().get(0).toString());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 //
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 BranchInfo b4 = branches.getBranch("branch4");
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 assertNotNull(b4);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 assertFalse(b4.isClosed());
309
962f78aac342 Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
70 assertEquals(2, b4.getHeads().size());
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 assertEquals("fceabd402f0193fb30605aed0ee3a9d5feb99f60", b4.getHeads().get(0).toString());
309
962f78aac342 Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 308
diff changeset
72 assertEquals("892b6a504be7835f1748ba632fe15a9389d4479b", b4.getHeads().get(1).toString());
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 //
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 BranchInfo b5 = branches.getBranch("branch5");
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 assertNotNull(b5);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 assertFalse(b5.isClosed());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 assertEquals(1, b5.getHeads().size());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 assertEquals("9cb6ad32b9074021356c38050e2aab6addba4393", b5.getHeads().get(0).toString());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 }
315
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
80
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
81 @Test
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
82 public void testBranchInfoClosedHeads() throws Exception{
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
83 HgRepository repo = Configuration.get().find("branches-1");
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
84 HgBranches branches = repo.getBranches();
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
85 // branch1 - two closed heads
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
86 BranchInfo b1 = branches.getBranch("branch1");
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
87 assertTrue(b1.isClosed(b1.getHeads().get(0)));
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
88 assertTrue(b1.isClosed(b1.getHeads().get(1)));
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
89 try {
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
90 b1.isClosed(Nodeid.fromAscii("9cb6ad32b9074021356c38050e2aab6addba4393"));
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
91 fail("Revision that doesn't belong to heads of the branch shall not be handled");
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
92 } catch (IllegalArgumentException ex) {
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
93 // good
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
94 }
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
95 //
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
96 // branch2, one closed head
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
97 BranchInfo b2 = branches.getBranch("branch2");
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
98 assertFalse(b2.isClosed(b2.getHeads().get(0)));
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
99 assertTrue(b2.isClosed(b2.getHeads().get(1)));
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
100 //
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
101 // branch5, closed and reopened, 1 open head
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
102 BranchInfo b5 = branches.getBranch("branch5");
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
103 for (Nodeid h : b5.getHeads()) {
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
104 assertFalse(b5.isClosed(h));
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
105 }
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
106 }
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 }