Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestCommit.java @ 660:4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 09 Jul 2013 21:46:45 +0200 |
parents | cd77bf51b562 |
children |
comparison
equal
deleted
inserted
replaced
658:d10399f80f4e | 660:4fd317a2fecf |
---|---|
18 | 18 |
19 import static org.junit.Assert.*; | 19 import static org.junit.Assert.*; |
20 import static org.tmatesoft.hg.repo.HgRepository.*; | 20 import static org.tmatesoft.hg.repo.HgRepository.*; |
21 | 21 |
22 import java.io.File; | 22 import java.io.File; |
23 import java.io.IOException; | |
24 import java.util.List; | 23 import java.util.List; |
25 | 24 |
26 import org.junit.Rule; | 25 import org.junit.Rule; |
27 import org.junit.Test; | 26 import org.junit.Test; |
28 import org.tmatesoft.hg.core.HgAddRemoveCommand; | 27 import org.tmatesoft.hg.core.HgAddRemoveCommand; |
158 errorCollector.assertEquals("FIRST", c1.getComment()); | 157 errorCollector.assertEquals("FIRST", c1.getComment()); |
159 // | 158 // |
160 // check if cached value in hgRepo got updated | 159 // check if cached value in hgRepo got updated |
161 errorCollector.assertEquals("branch1", hgRepo.getWorkingCopyBranchName()); | 160 errorCollector.assertEquals("branch1", hgRepo.getWorkingCopyBranchName()); |
162 // | 161 // |
163 assertHgVerifyOk(repoLoc); | 162 RepoUtils.assertHgVerifyOk(errorCollector, repoLoc); |
164 } | 163 } |
165 | 164 |
166 /** | 165 /** |
167 * use own add and remove commands and then commit | 166 * use own add and remove commands and then commit |
168 */ | 167 */ |
190 errorCollector.assertEquals("d", cmt.getRemovedFiles().get(0).toString()); | 189 errorCollector.assertEquals("d", cmt.getRemovedFiles().get(0).toString()); |
191 ByteArrayChannel sink = new ByteArrayChannel(); | 190 ByteArrayChannel sink = new ByteArrayChannel(); |
192 new HgCatCommand(hgRepo).file(Path.create("xx")).changeset(commitRev).execute(sink); | 191 new HgCatCommand(hgRepo).file(Path.create("xx")).changeset(commitRev).execute(sink); |
193 assertArrayEquals("xyz".getBytes(), sink.toArray()); | 192 assertArrayEquals("xyz".getBytes(), sink.toArray()); |
194 // | 193 // |
195 assertHgVerifyOk(repoLoc); | 194 RepoUtils.assertHgVerifyOk(errorCollector, repoLoc); |
196 } | 195 } |
197 /** | 196 /** |
198 * perform few commits one by one, into different branches | 197 * perform few commits one by one, into different branches |
199 */ | 198 */ |
200 @Test | 199 @Test |
238 errorCollector.assertEquals("branch2", c2.getBranch()); | 237 errorCollector.assertEquals("branch2", c2.getBranch()); |
239 errorCollector.assertEquals(DEFAULT_BRANCH_NAME, c3.getBranch()); | 238 errorCollector.assertEquals(DEFAULT_BRANCH_NAME, c3.getBranch()); |
240 errorCollector.assertEquals("FIRST", c1.getComment()); | 239 errorCollector.assertEquals("FIRST", c1.getComment()); |
241 errorCollector.assertEquals("SECOND", c2.getComment()); | 240 errorCollector.assertEquals("SECOND", c2.getComment()); |
242 errorCollector.assertEquals("THIRD", c3.getComment()); | 241 errorCollector.assertEquals("THIRD", c3.getComment()); |
243 assertHgVerifyOk(repoLoc); | 242 RepoUtils.assertHgVerifyOk(errorCollector, repoLoc); |
244 } | 243 } |
245 | 244 |
246 @Test | 245 @Test |
247 public void testCommandBasics() throws Exception { | 246 public void testCommandBasics() throws Exception { |
248 File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-commit-cmd", false); | 247 File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-commit-cmd", false); |
287 List<HgChangeset> csets = new HgLogCommand(hgRepo).range(lastRev-1, lastRev).execute(); | 286 List<HgChangeset> csets = new HgLogCommand(hgRepo).range(lastRev-1, lastRev).execute(); |
288 errorCollector.assertEquals(csets.get(0).getNodeid(), c1); | 287 errorCollector.assertEquals(csets.get(0).getNodeid(), c1); |
289 errorCollector.assertEquals(csets.get(1).getNodeid(), c2); | 288 errorCollector.assertEquals(csets.get(1).getNodeid(), c2); |
290 errorCollector.assertEquals(csets.get(0).getComment(), "FIRST"); | 289 errorCollector.assertEquals(csets.get(0).getComment(), "FIRST"); |
291 errorCollector.assertEquals(csets.get(1).getComment(), "SECOND"); | 290 errorCollector.assertEquals(csets.get(1).getComment(), "SECOND"); |
292 assertHgVerifyOk(repoLoc); | 291 RepoUtils.assertHgVerifyOk(errorCollector, repoLoc); |
293 // new commits are drafts by default, check our commit respects this | 292 // new commits are drafts by default, check our commit respects this |
294 // TODO more tests with children of changesets with draft, secret or public phases (latter - | 293 // TODO more tests with children of changesets with draft, secret or public phases (latter - |
295 // new commit is child of public, but there are other commits with draft/secret phases - ensure they are intact) | 294 // new commit is child of public, but there are other commits with draft/secret phases - ensure they are intact) |
296 assertEquals(HgPhase.Draft, HgPhase.parse(hgRepo.getConfiguration().getStringValue("phases", "new-commit", HgPhase.Draft.mercurialString()))); | 295 assertEquals(HgPhase.Draft, HgPhase.parse(hgRepo.getConfiguration().getStringValue("phases", "new-commit", HgPhase.Draft.mercurialString()))); |
297 errorCollector.assertEquals(HgPhase.Draft, csets.get(0).getPhase()); | 296 errorCollector.assertEquals(HgPhase.Draft, csets.get(0).getPhase()); |
486 errorCollector.assertTrue(status.getErrors().isEmpty()); | 485 errorCollector.assertTrue(status.getErrors().isEmpty()); |
487 errorCollector.assertTrue(status.get(Kind.Added).contains(newFilePath)); | 486 errorCollector.assertTrue(status.get(Kind.Added).contains(newFilePath)); |
488 errorCollector.assertTrue(status.get(Kind.Modified).contains(dfB.getPath())); | 487 errorCollector.assertTrue(status.get(Kind.Modified).contains(dfB.getPath())); |
489 errorCollector.assertTrue(status.get(Kind.Removed).contains(dfD.getPath())); | 488 errorCollector.assertTrue(status.get(Kind.Removed).contains(dfD.getPath())); |
490 | 489 |
491 assertHgVerifyOk(repoLoc); | 490 RepoUtils.assertHgVerifyOk(errorCollector, repoLoc); |
492 } | |
493 | |
494 private void assertHgVerifyOk(File repoLoc) throws InterruptedException, IOException { | |
495 ExecHelper verifyRun = new ExecHelper(new OutputParser.Stub(), repoLoc); | |
496 verifyRun.run("hg", "verify"); | |
497 errorCollector.assertEquals("hg verify", 0, verifyRun.getExitValue()); | |
498 } | 491 } |
499 | 492 |
500 private Transaction newTransaction(SessionContext.Source ctxSource) { | 493 private Transaction newTransaction(SessionContext.Source ctxSource) { |
501 return trFactory.create(ctxSource); | 494 return trFactory.create(ctxSource); |
502 } | 495 } |