private BuildCommand isBranchChanged(String workDir) { return test("-neq", material.getBranch(), exec("hg", "branch").setWorkingDirectory(workDir)); }
private BuildCommand shouldDoCleanupAndUpdate(String workingDir) { return compose( test("-d", workingDir), isRepository(workingDir), repoUrlUnchanged(workingDir) ); }
private BuildCommand isBranchChanged(String workDir) { return test("-neq", material.branchWithDefault(), exec("git", "rev-parse", "--abbrev-ref", "HEAD").setWorkingDirectory(workDir)); }
@Test public void testDirExists() throws IOException { runBuild(test("-d", ""), Passed); runBuild(test("-d", "dir"), Failed); runBuild(test("-d", "file"), Failed); assertTrue(new File(sandbox, "file").createNewFile()); assertTrue(new File(sandbox, "dir").mkdir()); runBuild(test("-d", "file"), Failed); runBuild(test("-d", "dir"), Passed); }
@Test public void testDirNotExists() throws IOException { runBuild(test("-nd", ""), Failed); runBuild(test("-nd", "dir"), Passed); runBuild(test("-nd", "file"), Passed); assertTrue(new File(sandbox, "file").createNewFile()); assertTrue(new File(sandbox, "dir").mkdir()); runBuild(test("-nd", "file"), Passed); runBuild(test("-nd", "dir"), Failed); }
private BuildCommand isRepoUrlChanged(String workDir) { return test("-neq", material.getUrlArgument().forCommandline(), exec("git", "config", "remote.origin.url").setWorkingDirectory(workDir)); }
private BuildCommand cloneIfNeeded(String workDir, int cloneDepth) { return compose( mkdirs(workDir).setTest(test("-nd", workDir)), cleanWorkingDir(workDir), cmdClone(workDir, cloneDepth)); }
private BuildCommand refreshWorkingDir() { return BuildCommand.compose( cleanWorkingDir(), mkdirs(workingDirectory()).setTest(test("-nd", workingDirectory()))); }
private BuildCommand isRepoUrlChanged(String workDir) { return test("-neq", new MaterialUrl(material.getHgUrlArgument().defaultRemoteUrl()).getUrl(), exec("hg", "showconfig", "paths.default").setWorkingDirectory(workDir)); }
@Test public void testDirectoryExistsBeforeMkdir() { File dir = new File(sandbox, "foo"); runBuild(mkdirs("foo"), Passed); runBuild(mkdirs("foo").setTest(test("-nd", dir.getPath())), Passed); assertThat(new File(sandbox, "foo").isDirectory(), is(true)); } }
private BuildCommand cloneIfNeeded(String workDir) { return compose( mkdirs(workDir).setTest(test("-nd", workDir)), cleanWorkingDir(workDir), cmdClone(workDir).setTest(isNotRepository(workDir)) ); }
private BuildCommand cleanWorkingDir(String workDir) { return compose( cleandir(workDir).setTest(isNotRepository(workDir)), cleandir(workDir).setTest(isRepoUrlChanged(workDir)), cleandir(workDir).setTest(isBranchChanged(workDir)) ).setTest(test("-d", workDir)); }
private BuildCommand cleanWorkingDir(String workDir) { return compose( cleandir(workDir).setTest(isNotRepository(workDir)), cleandir(workDir).setTest(isRepoUrlChanged(workDir)), cleandir(workDir).setTest(isBranchChanged(workDir)), material.isShallowClone() ? noop() : cleandir(workDir).setTest(isShallow(workDir)) ).setTest(test("-d", workDir)); }