comparison test/org/tmatesoft/hg/test/TestOutgoing.java @ 653:629a7370554c

Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 03 Jul 2013 14:38:30 +0200
parents 2813a26b8999
children
comparison
equal deleted inserted replaced
652:cd77bf51b562 653:629a7370554c
1 /* 1 /*
2 * Copyright (c) 2011 TMate Software Ltd 2 * Copyright (c) 2011-2013 TMate Software Ltd
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License. 6 * the Free Software Foundation; version 2 of the License.
7 * 7 *
14 * the terms of a license other than GNU General Public License 14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.test; 17 package org.tmatesoft.hg.test;
18 18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21
19 import java.io.File; 22 import java.io.File;
20 import java.io.FileWriter;
21 import java.io.IOException;
22 import java.util.List; 23 import java.util.List;
23 24
24 import org.junit.Assert; 25 import org.junit.Assert;
25 import org.junit.Rule; 26 import org.junit.Rule;
26 import org.junit.Test; 27 import org.junit.Test;
28 import org.tmatesoft.hg.core.HgCheckoutCommand;
29 import org.tmatesoft.hg.core.HgCommitCommand;
27 import org.tmatesoft.hg.core.HgLogCommand; 30 import org.tmatesoft.hg.core.HgLogCommand;
28 import org.tmatesoft.hg.core.HgOutgoingCommand; 31 import org.tmatesoft.hg.core.HgOutgoingCommand;
29 import org.tmatesoft.hg.core.Nodeid; 32 import org.tmatesoft.hg.core.Nodeid;
30 import org.tmatesoft.hg.repo.HgLookup; 33 import org.tmatesoft.hg.repo.HgLookup;
31 import org.tmatesoft.hg.repo.HgRemoteRepository; 34 import org.tmatesoft.hg.repo.HgRemoteRepository;
35 import org.tmatesoft.hg.repo.HgRepository;
32 36
33 /** 37 /**
34 * 38 *
35 * @author Artem Tikhomirov 39 * @author Artem Tikhomirov
36 * @author TMate Software Ltd. 40 * @author TMate Software Ltd.
69 List<Nodeid> liteResult = cmd.executeLite(); 73 List<Nodeid> liteResult = cmd.executeLite();
70 eh.run("hg", "outgoing", "--debug", hgRemote.getLocation()); 74 eh.run("hg", "outgoing", "--debug", hgRemote.getLocation());
71 TestIncoming.report(collector, outParser, liteResult, errorCollector); 75 TestIncoming.report(collector, outParser, liteResult, errorCollector);
72 // 76 //
73 File f = new File(dest, "Test.txt"); 77 File f = new File(dest, "Test.txt");
74 append(f, "1"); 78 RepoUtils.createFile(f, "1");
75 eh0.run("hg", "add"); 79 eh0.run("hg", "add");
76 eh0.run("hg", "commit", "-m", "1"); 80 eh0.run("hg", "commit", "-m", "1");
77 append(f, "2"); 81 RepoUtils.modifyFileAppend(f, "2");
78 eh0.run("hg", "commit", "-m", "2"); 82 eh0.run("hg", "commit", "-m", "2");
79 // 83 //
80 cmd = new HgOutgoingCommand(lookup.detect(dest)).against(hgRemote); 84 cmd = new HgOutgoingCommand(lookup.detect(dest)).against(hgRemote);
81 cmd.executeFull(collector = new HgLogCommand.CollectHandler()); 85 cmd.executeFull(collector = new HgLogCommand.CollectHandler());
82 liteResult = cmd.executeLite(); 86 liteResult = cmd.executeLite();
83 outParser.reset(); 87 outParser.reset();
84 eh.run("hg", "outgoing", "--debug", hgRemote.getLocation()); 88 eh.run("hg", "outgoing", "--debug", hgRemote.getLocation());
85 TestIncoming.report(collector, outParser, liteResult, errorCollector); 89 TestIncoming.report(collector, outParser, liteResult, errorCollector);
86 } 90 }
87 } 91 }
88 92
89 static void append(File f, String s) throws IOException { 93 /**
90 FileWriter fw = new FileWriter(f); 94 * Issue 47: Incorrect set of outgoing changes when revision spins off prior to common revision of local and remote repos
91 fw.append(s); 95 */
92 fw.close(); 96 @Test
97 public void testOutgoingPreceedsCommon() throws Exception {
98 File srcRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-outgoing-src", false);
99 File dstRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-outgoing-dst", false);
100 File f1 = new File(srcRepoLoc, "file1");
101 assertTrue("[sanity]", f1.canWrite());
102 HgServer server = new HgServer().start(dstRepoLoc);
103 try {
104 final HgLookup hgLookup = new HgLookup();
105 final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
106 final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
107 new HgCheckoutCommand(srcRepo).changeset(6).clean(true).execute();
108 assertEquals("[sanity]", "with-merge", srcRepo.getWorkingCopyBranchName());
109 RepoUtils.modifyFileAppend(f1, "change1");
110 new HgCommitCommand(srcRepo).message("Commit 1").execute();
111 new HgCheckoutCommand(srcRepo).changeset(5).clean(true).execute();
112 assertEquals("[sanity]", "no-merge", srcRepo.getWorkingCopyBranchName());
113 RepoUtils.modifyFileAppend(f1, "change2");
114 new HgCommitCommand(srcRepo).message("Commit 2").execute();
115 //
116 HgOutgoingCommand cmd = new HgOutgoingCommand(srcRepo).against(dstRemote);
117 LogOutputParser outParser = new LogOutputParser(true);
118 ExecHelper eh = new ExecHelper(outParser, srcRepoLoc);
119 HgLogCommand.CollectHandler collector = new HgLogCommand.CollectHandler();
120 //
121 List<Nodeid> liteResult = cmd.executeLite();
122 cmd.executeFull(collector);
123 eh.run("hg", "outgoing", "--debug", dstRemote.getLocation());
124 TestIncoming.report(collector, outParser, liteResult, errorCollector);
125 } finally {
126 server.stop();
127 }
93 } 128 }
94 } 129 }