Skip to content

Commit

Permalink
Support the population of scmBranch from Hg
Browse files Browse the repository at this point in the history
  • Loading branch information
codingtony committed Jun 23, 2015
1 parent 45aaf03 commit 5bd148b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/org/codehaus/mojo/build/CreateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFile;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.command.info.InfoItem;
import org.apache.maven.scm.command.info.InfoScmResult;
import org.apache.maven.scm.command.status.StatusScmResult;
Expand All @@ -57,6 +58,8 @@
import org.apache.maven.scm.provider.ScmProvider;
import org.apache.maven.scm.provider.git.gitexe.command.branch.GitBranchCommand;
import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
import org.apache.maven.scm.provider.hg.HgScmProvider;
import org.apache.maven.scm.provider.hg.HgUtils;
import org.apache.maven.scm.repository.ScmRepository;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
Expand Down Expand Up @@ -564,18 +567,26 @@ public List<ScmFile> getStatus()
public String getScmBranch()
throws MojoExecutionException
{
/* git branch can be obtained directly by a command */
try
{
ScmRepository repository = getScmRepository();
ScmProvider provider = scmManager.getProviderByRepository( repository );
/* git branch can be obtained directly by a command */
if ( GitScmProviderRepository.PROTOCOL_GIT.equals( provider.getScmType() ) )
{
ScmFileSet fileSet = new ScmFileSet( scmDirectory );
return GitBranchCommand.getCurrentBranch( getLogger(),
(GitScmProviderRepository) repository.getProviderRepository(),
fileSet );
}
} else if ( provider instanceof HgScmProvider ) {
/* hg branch can be obtained directly by a command */
HgOutputConsumer consumer = new HgOutputConsumer( getLogger() );
ScmResult result = HgUtils.execute( consumer, logger, scmDirectory, new String[] { "id", "-b" } );
checkResult( result );
if (StringUtils.isNotEmpty(consumer.getOutput())) {
return consumer.getOutput();
}
}
}
catch ( ScmException e )
{
Expand Down

0 comments on commit 5bd148b

Please sign in to comment.