public void testPushCreatingNewHead() throws IOException {
Repository repoA = getTestRepository();
Changeset base = createChangeset();
File dir = createTempDir();
BaseRepository repoB = Repository.clone(dir, repoA.getDirectory().getPath());
Changeset a = createChangeset();
update(base);
Changeset b = createChangeset();
Files.write("a".getBytes(), new File(repoB.getDirectory(), "file"));
AddCommand.on(repoB).execute();
CommitCommand.on(repoB).message("m").user("u").execute();
PushCommand push = PushCommand.on(repoA);
try {
push.execute(repoB.getDirectory().getPath());
assertFailedExecution(push);
} catch (ExecutionException e) {
Assert.assertTrue(e.getMessage().startsWith("push creates new remote head"));
}
List<Changeset> changesets = PushCommand.on(repoA).force().execute(repoB.getDirectory().getPath());
// This strange assert is because mercurial 3.1.1 returns more than 2 changesets
// not sure when the change happened between 2.8.1 and 3.1.1
Assert.assertTrue(2 <= changesets.size() && changesets.size() <= 7);
Assert.assertTrue(changesets.contains(a));
Assert.assertTrue(changesets.contains(b));
repoB.close();
deleteTempDir(dir);
}