final HgLookup hgLookup = new HgLookup();
final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
final ExecHelper dstRun = new ExecHelper(new OutputParser.Stub(), dstRepoLoc);
final int publicCsetToBranchAt = 4;
final int r5 = 5, r6 = 6, r8 = 8;
PhasesHelper srcPhase = new PhasesHelper(HgInternals.getImplementationRepo(srcRepo));
assertEquals("[sanity]", HgPhase.Draft, srcPhase.getPhase(r5, null));
assertEquals("[sanity]", HgPhase.Secret, srcPhase.getPhase(r6, null));
assertEquals("[sanity]", HgPhase.Draft, srcPhase.getPhase(r8, null));
// change phases in repository of remote server:
dstRun.exec("hg", "phase", "--public", String.valueOf(r5));
assertEquals(0, dstRun.getExitValue());
dstRun.exec("hg", "phase", "--draft", String.valueOf(r6));
assertEquals(0, dstRun.getExitValue());
dstRun.exec("hg", "phase", "--secret", "--force", String.valueOf(r8));
assertEquals(0, dstRun.getExitValue());
HgServer server = new HgServer().publishing(false).start(dstRepoLoc);
try {
final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
// commit new draft head
new HgCheckoutCommand(srcRepo).changeset(publicCsetToBranchAt).clean(true).execute();
RepoUtils.modifyFileAppend(f1, "// aaa");
final HgCommitCommand commitCmd = new HgCommitCommand(srcRepo).message("Commit aaa");
assertTrue(commitCmd.execute().isOk());
final Nodeid newCommit = commitCmd.getCommittedRevision();
//
new HgPushCommand(srcRepo).destination(dstRemote).execute();
// refresh phase information
srcPhase = new PhasesHelper(HgInternals.getImplementationRepo(srcRepo));
// r5 and r6 are changed to match server phases (more exposed)
errorCollector.assertEquals(HgPhase.Public, srcPhase.getPhase(r5, null));
errorCollector.assertEquals(HgPhase.Draft, srcPhase.getPhase(r6, null));
// r8 is secret on server, locally can't make it less exposed though
errorCollector.assertEquals(HgPhase.Draft, srcPhase.getPhase(r8, null));
//
HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
final HgChangelog dstClog = dstRepo.getChangelog();
assertTrue(dstClog.isKnown(newCommit));
PhasesHelper dstPhase = new PhasesHelper(HgInternals.getImplementationRepo(dstRepo));
errorCollector.assertEquals(HgPhase.Draft, dstPhase.getPhase(dstClog.getRevisionIndex(newCommit), newCommit));
// the one that was secret is draft now
errorCollector.assertEquals(HgPhase.Draft, srcPhase.getPhase(r8, null));
} finally {
server.stop();
}