use of org.apache.maven.scm.command.info.InfoScmResult in project maven-scm by apache.
the class JGitInfoCommand method executeCommand.
@Override
protected ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
Git git = null;
try {
File basedir = fileSet.getBasedir();
git = Git.open(basedir);
ObjectId objectId = git.getRepository().resolve("HEAD");
InfoItem infoItem = new InfoItem();
infoItem.setRevision(StringUtils.trim(objectId.name()));
infoItem.setURL(basedir.getPath());
return new InfoScmResult(Collections.singletonList(infoItem), new ScmResult("JGit.resolve(HEAD)", "", objectId.toString(), true));
} catch (Exception e) {
throw new ScmException("JGit resolve failure!", e);
} finally {
JGitUtils.closeRepo(git);
}
}
use of org.apache.maven.scm.command.info.InfoScmResult in project maven-scm by apache.
the class GitInfoCommand method executeCommand.
@Override
protected ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
GitInfoConsumer consumer = new GitInfoConsumer(getLogger(), fileSet);
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
Commandline cli = createCommandLine(repository, fileSet, parameters);
int exitCode = GitCommandLineUtils.execute(cli, consumer, stderr, getLogger());
if (exitCode != 0) {
return new InfoScmResult(cli.toString(), "The git rev-parse command failed.", stderr.getOutput(), false);
}
return new InfoScmResult(cli.toString(), consumer.getInfoItems());
}
use of org.apache.maven.scm.command.info.InfoScmResult in project maven-scm by apache.
the class GitInfoCommandTckTest method testInfoCommandWithNegativeShortRevision.
public void testInfoCommandWithNegativeShortRevision() throws Exception {
GitScmTestUtils.initRepo("src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy());
ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
ScmProviderRepository repository = provider.makeProviderScmRepository(getRepositoryRoot());
assertNotNull(repository);
CommandParameters commandParameters = new CommandParameters();
commandParameters.setInt(CommandParameter.SCM_SHORT_REVISION_LENGTH, GitInfoCommand.NO_REVISION_LENGTH);
InfoScmResult result = provider.info(repository, new ScmFileSet(getRepositoryRoot()), commandParameters);
assertNotNull(result);
assertEquals("revision should not be short", "cd3c0dfacb65955e6fbb35c56cc5b1bf8ce4f767", result.getInfoItems().get(0).getRevision());
}
use of org.apache.maven.scm.command.info.InfoScmResult in project maven-scm by apache.
the class GitInfoCommandTckTest method testInfoCommandWithShortRevision.
public void testInfoCommandWithShortRevision() throws Exception {
GitScmTestUtils.initRepo("src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy());
ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
ScmProviderRepository repository = provider.makeProviderScmRepository(getRepositoryRoot());
assertNotNull(repository);
CommandParameters commandParameters = new CommandParameters();
commandParameters.setInt(CommandParameter.SCM_SHORT_REVISION_LENGTH, 6);
InfoScmResult result = provider.info(repository, new ScmFileSet(getRepositoryRoot()), commandParameters);
assertNotNull(result);
assertEquals("revision must be short, exactly 6 digits ", "cd3c0d", result.getInfoItems().get(0).getRevision());
}
use of org.apache.maven.scm.command.info.InfoScmResult in project maven-scm by apache.
the class GitInfoCommandTckTest method testInfoCommand.
public void testInfoCommand() throws Exception {
GitScmTestUtils.initRepo("src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy());
ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
ScmProviderRepository repository = provider.makeProviderScmRepository(getRepositoryRoot());
assertNotNull(repository);
InfoScmResult result = provider.info(repository, new ScmFileSet(getRepositoryRoot()), new CommandParameters());
assertNotNull(result);
assertEquals("cd3c0dfacb65955e6fbb35c56cc5b1bf8ce4f767", result.getInfoItems().get(0).getRevision());
//
}
Aggregations