use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.
the class GitCheckOutCommand method executeCheckOutCommand.
/**
* For git, the given repository is a remote one.
* We have to clone it first if the working directory does not contain a git repo yet,
* otherwise we have to git-pull it.
* <p/>
* TODO We currently assume a '.git' directory, so this does not work for --bare repos
* {@inheritDoc}
*/
protected CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version, boolean recursive, boolean shallow) throws ScmException {
GitScmProviderRepository repository = (GitScmProviderRepository) repo;
if (GitScmProviderRepository.PROTOCOL_FILE.equals(repository.getFetchInfo().getProtocol()) && repository.getFetchInfo().getPath().indexOf(fileSet.getBasedir().getPath()) >= 0) {
throw new ScmException("remote repository must not be the working directory");
}
int exitCode;
CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
String lastCommandLine = "git-nothing-to-do";
if (!fileSet.getBasedir().exists() || !(new File(fileSet.getBasedir(), ".git").exists())) {
if (fileSet.getBasedir().exists()) {
// git refuses to clone otherwise
fileSet.getBasedir().delete();
}
// no git repo seems to exist, let's clone the original repo
Commandline clClone = createCloneCommand(repository, fileSet.getBasedir(), version, shallow);
exitCode = GitCommandLineUtils.execute(clClone, stdout, stderr, getLogger());
if (exitCode != 0) {
return new CheckOutScmResult(clClone.toString(), "The git-clone command failed.", stderr.getOutput(), false);
}
lastCommandLine = clClone.toString();
}
GitRemoteInfoCommand gitRemoteInfoCommand = new GitRemoteInfoCommand();
gitRemoteInfoCommand.setLogger(getLogger());
RemoteInfoScmResult result = gitRemoteInfoCommand.executeRemoteInfoCommand(repository, null, null);
if (fileSet.getBasedir().exists() && new File(fileSet.getBasedir(), ".git").exists() && result.getBranches().size() > 0) {
// git repo exists, so we must git-pull the changes
Commandline clPull = createPullCommand(repository, fileSet.getBasedir(), version);
exitCode = GitCommandLineUtils.execute(clPull, stdout, stderr, getLogger());
if (exitCode != 0) {
return new CheckOutScmResult(clPull.toString(), "The git-pull command failed.", stderr.getOutput(), false);
}
lastCommandLine = clPull.toString();
// and now lets do the git-checkout itself
Commandline clCheckout = createCommandLine(repository, fileSet.getBasedir(), version);
exitCode = GitCommandLineUtils.execute(clCheckout, stdout, stderr, getLogger());
if (exitCode != 0) {
return new CheckOutScmResult(clCheckout.toString(), "The git-checkout command failed.", stderr.getOutput(), false);
}
lastCommandLine = clCheckout.toString();
}
// and now search for the files
GitListConsumer listConsumer = new GitListConsumer(getLogger(), fileSet.getBasedir(), ScmFileStatus.CHECKED_IN);
Commandline clList = GitListCommand.createCommandLine(repository, fileSet.getBasedir());
exitCode = GitCommandLineUtils.execute(clList, listConsumer, stderr, getLogger());
if (exitCode != 0) {
return new CheckOutScmResult(clList.toString(), "The git-ls-files command failed.", stderr.getOutput(), false);
}
return new CheckOutScmResult(lastCommandLine, listConsumer.getListedFiles());
}
use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.
the class GitCheckInCommandNoBranchTest method testCheckinNoBranch.
public void testCheckinNoBranch() throws Exception {
if (!ScmTestCase.isSystemCmd("git")) {
System.out.println("skip test which git native executable in path");
return;
}
File repo_orig = new File("src/test/resources/repository_no_branch");
File repo = getTestFile("target/git_copy");
FileUtils.deleteDirectory(repo);
FileUtils.copyDirectoryStructure(repo_orig, repo);
ScmRepository scmRepository = getScmManager().makeScmRepository("scm:git:file:///" + repo.getAbsolutePath());
CheckOutScmResult checkOutScmResult = checkoutRepo(scmRepository);
assertEquals(0, checkOutScmResult.getCheckedOutFiles().size());
File f = new File(workingDirectory.getAbsolutePath() + File.separator + "pom.xml");
FileUtils.fileWrite(f.getAbsolutePath(), "toto");
ScmFileSet scmFileSet = new ScmFileSet(workingDirectory, new File("pom.xml"));
AddScmResult addResult = getScmManager().add(scmRepository, scmFileSet);
assertResultIsSuccess(addResult);
CheckInScmResult checkInScmResult = getScmManager().checkIn(scmRepository, scmFileSet, "commit");
assertResultIsSuccess(checkInScmResult);
assertEquals(1, checkInScmResult.getCheckedInFiles().size());
assertEquals("pom.xml", checkInScmResult.getCheckedInFiles().get(0).getPath());
checkOutScmResult = checkoutRepo(scmRepository);
assertResultIsSuccess(checkOutScmResult);
assertEquals(1, checkOutScmResult.getCheckedOutFiles().size());
assertEquals("pom.xml", checkOutScmResult.getCheckedOutFiles().get(0).getPath());
}
use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.
the class GitCheckInCommandTest method checkoutRepoInto.
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
private CheckOutScmResult checkoutRepoInto(File workingCopy, ScmRepository scmRepository) throws Exception {
FileUtils.deleteDirectory(workingCopy);
workingCopy.mkdir();
CheckOutScmResult result = getScmManager().checkOut(scmRepository, new ScmFileSet(workingCopy), (ScmVersion) null);
assertResultIsSuccess(result);
return result;
}
use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.
the class GitExeCheckOutCommandNoBranchTest method checkoutRepo.
protected CheckOutScmResult checkoutRepo() throws Exception {
CheckOutScmResult result = getScmManager().checkOut(scmRepository, new ScmFileSet(workingDirectory), (ScmVersion) null);
assertResultIsSuccess(result);
return result;
}
use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project plugin-compat-tester by jenkinsci.
the class ExampleMultiParent method action.
/*
* No check implementation is required because transformedPlugins
* returns your specific list.
*/
/**
* Point to the shared location. Check if this needs to be downloaded.
*/
public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception {
PluginCompatTesterConfig config = (PluginCompatTesterConfig) moreInfo.get("config");
Plugin currentPlugin = (Plugin) moreInfo.get("plugin");
// Determine if we need to run the download; only run for first identified plugin in the series
if (firstRun) {
System.out.println("Preparing for Multimodule checkout.");
// Checkout to the parent directory. All other processes will be on the child directory
File parentPath = new File(config.workDirectory.getAbsolutePath() + "/" + parentName);
System.out.println("Checking out from SCM connection URL : " + parentUrl + " (" + parentName + "-" + currentPlugin.version + ")");
ScmManager scmManager = SCMManagerFactory.getInstance().createScmManager();
ScmRepository repository = scmManager.makeScmRepository(parentUrl);
CheckOutScmResult result = scmManager.checkOut(repository, new ScmFileSet(parentPath), new ScmTag(parentName + "-" + currentPlugin.version));
if (!result.isSuccess()) {
throw new RuntimeException(result.getProviderMessage() + "||" + result.getCommandOutput());
}
}
// Checkout already happened, don't run through again
moreInfo.put("runCheckout", false);
firstRun = false;
// Change the "download"" directory; after download, it's simply used for reference
File childPath = new File(config.workDirectory.getAbsolutePath() + "/" + parentName + "/" + currentPlugin.name);
moreInfo.put("checkoutDir", childPath);
return moreInfo;
}
Aggregations