use of org.apache.maven.scm.provider.git.repository.GitScmProviderRepository in project maven-scm by apache.
the class GitChangeLogCommandTest method testCommandLine.
private void testCommandLine(String scmUrl, ScmBranch branch, Date startDate, Date endDate, ScmVersion startVersion, ScmVersion endVersion, String commandLine) throws Exception {
ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
Commandline cl = GitChangeLogCommand.createCommandLine(gitRepository, workingDirectory, branch, startDate, endDate, startVersion, endVersion);
assertCommandLine(commandLine, workingDirectory, cl);
}
use of org.apache.maven.scm.provider.git.repository.GitScmProviderRepository in project maven-scm by apache.
the class GitRemoteInfoCommand method executeRemoteInfoCommand.
@Override
public RemoteInfoScmResult executeRemoteInfoCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository;
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
Commandline clLsRemote = createCommandLine(gitRepository);
GitRemoteInfoConsumer consumer = new GitRemoteInfoConsumer(getLogger(), clLsRemote.toString());
int exitCode = GitCommandLineUtils.execute(clLsRemote, consumer, stderr, getLogger());
if (exitCode != 0) {
throw new ScmException("unbale to execute ls-remote on " + gitRepository.getFetchUrl());
}
return consumer.getRemoteInfoScmResult();
}
use of org.apache.maven.scm.provider.git.repository.GitScmProviderRepository in project maven-scm by apache.
the class GitTagCommand method executeTagCommand.
/**
* {@inheritDoc}
*/
public ScmResult executeTagCommand(ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
if (tag == null || StringUtils.isEmpty(tag.trim())) {
throw new ScmException("tag name must be specified");
}
if (!fileSet.getFileList().isEmpty()) {
throw new ScmException("This provider doesn't support tagging subsets of a directory");
}
GitScmProviderRepository repository = (GitScmProviderRepository) repo;
File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
try {
FileUtils.fileWrite(messageFile.getAbsolutePath(), scmTagParameters.getMessage());
} catch (IOException ex) {
return new TagScmResult(null, "Error while making a temporary file for the commit message: " + ex.getMessage(), null, false);
}
try {
CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitCode;
Commandline clTag = createCommandLine(repository, fileSet.getBasedir(), tag, messageFile);
exitCode = GitCommandLineUtils.execute(clTag, stdout, stderr, getLogger());
if (exitCode != 0) {
return new TagScmResult(clTag.toString(), "The git-tag command failed.", stderr.getOutput(), false);
}
if (repo.isPushChanges()) {
// and now push the tag to the configured upstream repository
Commandline clPush = createPushCommandLine(repository, fileSet, tag);
exitCode = GitCommandLineUtils.execute(clPush, stdout, stderr, getLogger());
if (exitCode != 0) {
return new TagScmResult(clPush.toString(), "The git-push command failed.", stderr.getOutput(), false);
}
}
// plus search for the tagged files
GitListConsumer listConsumer = new GitListConsumer(getLogger(), fileSet.getBasedir(), ScmFileStatus.TAGGED);
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 TagScmResult(clTag.toString(), listConsumer.getListedFiles());
} finally {
try {
FileUtils.forceDelete(messageFile);
} catch (IOException ex) {
// ignore
}
}
}
use of org.apache.maven.scm.provider.git.repository.GitScmProviderRepository in project maven-scm by apache.
the class GitTagCommandTest method testCommandLine.
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
private void testCommandLine(String scmUrl, String tag, String commandLine) throws Exception {
File workingDirectory = getTestFile("target/git-checkin-command-test");
ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
Commandline cl = GitTagCommand.createCommandLine(gitRepository, workingDirectory, tag, messageFile);
assertCommandLine(commandLine, workingDirectory, cl);
}
use of org.apache.maven.scm.provider.git.repository.GitScmProviderRepository in project maven-scm by apache.
the class GitAddCommand method executeAddCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
GitScmProviderRepository repository = (GitScmProviderRepository) repo;
if (fileSet.getFileList().isEmpty()) {
throw new ScmException("You must provide at least one file/directory to add");
}
AddScmResult result = executeAddFileSet(fileSet);
if (result != null) {
return result;
}
// SCM-709: statusCommand uses repositoryRoot instead of workingDirectory, adjust it with relativeRepositoryPath
Commandline clRevparse = GitStatusCommand.createRevparseShowToplevelCommand(fileSet);
CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
URI relativeRepositoryPath = null;
int exitCode;
exitCode = GitCommandLineUtils.execute(clRevparse, stdout, stderr, getLogger());
if (exitCode != 0) {
// git-status returns non-zero if nothing to do
if (getLogger().isInfoEnabled()) {
getLogger().info("Could not resolve toplevel");
}
} else {
relativeRepositoryPath = GitStatusConsumer.resolveURI(stdout.getOutput().trim(), fileSet.getBasedir().toURI());
}
// git-add doesn't show single files, but only summary :/
// so we must run git-status and consume the output
// borrow a few things from the git-status command
Commandline clStatus = GitStatusCommand.createCommandLine(repository, fileSet);
GitStatusConsumer statusConsumer = new GitStatusConsumer(getLogger(), fileSet.getBasedir(), relativeRepositoryPath);
stderr = new CommandLineUtils.StringStreamConsumer();
exitCode = GitCommandLineUtils.execute(clStatus, statusConsumer, stderr, getLogger());
if (exitCode != 0) {
// git-status returns non-zero if nothing to do
if (getLogger().isInfoEnabled()) {
getLogger().info("nothing added to commit but untracked files present (use \"git add\" to track)");
}
}
List<ScmFile> changedFiles = new ArrayList<ScmFile>();
// rewrite all detected files to now have status 'checked_in'
for (ScmFile scmfile : statusConsumer.getChangedFiles()) {
// if a specific fileSet is given, we have to check if the file is really tracked
for (File f : fileSet.getFileList()) {
if (FilenameUtils.separatorsToUnix(f.getPath()).equals(scmfile.getPath())) {
changedFiles.add(scmfile);
}
}
}
Commandline cl = createCommandLine(fileSet.getBasedir(), fileSet.getFileList());
return new AddScmResult(cl.toString(), changedFiles);
}
Aggregations