Skip to content

Commit

Permalink
[SCM-486] Support signed tags for Git
Browse files Browse the repository at this point in the history
This closes #81
  • Loading branch information
dfa1 authored and michael-o committed Aug 11, 2018
1 parent b630e3a commit 6c31363
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ public class ScmTagParameters

private boolean pinExternals = false;

private boolean sign = false;

private String scmRevision;

public ScmTagParameters()
{
this.remoteTagging = false;
this.pinExternals = false;
this.sign = false;
}

public ScmTagParameters( String message )
Expand Down Expand Up @@ -79,6 +82,16 @@ public void setPinExternals( boolean pinExternals )
this.pinExternals = pinExternals;
}

public boolean isSign()
{
return sign;
}

public void setSign( boolean sign )
{
this.sign = sign;
}

public String getScmRevision()
{
return scmRevision;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ public class TagMojo
@Parameter( property = "pinExternals", defaultValue = "false" )
private boolean pinExternals;

/**
* Enable the "--sign" in Git
*
* @since 1.10.1
*/
@Parameter( property = "sign", defaultValue = "false" )
private boolean sign;

/** {@inheritDoc} */
public void execute()
throws MojoExecutionException
Expand Down Expand Up @@ -145,6 +153,7 @@ public void execute()
ScmTagParameters scmTagParameters = new ScmTagParameters( message );
scmTagParameters.setRemoteTagging( remoteTagging );
scmTagParameters.setPinExternals( pinExternals );
scmTagParameters.setSign( sign );

TagScmResult result = provider.tag( repository, getFileSet(), finalTag, scmTagParameters );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public ScmResult executeTagCommand( ScmProviderRepository repo, ScmFileSet fileS

int exitCode;

Commandline clTag = createCommandLine( repository, fileSet.getBasedir(), tag, messageFile );
boolean sign = scmTagParameters.isSign();

Commandline clTag = createCommandLine( repository, fileSet.getBasedir(), tag, messageFile, sign );

exitCode = GitCommandLineUtils.execute( clTag, stdout, stderr, getLogger() );
if ( exitCode != 0 )
Expand Down Expand Up @@ -147,10 +149,15 @@ public ScmResult executeTagCommand( ScmProviderRepository repo, ScmFileSet fileS
// ----------------------------------------------------------------------

public static Commandline createCommandLine( GitScmProviderRepository repository, File workingDirectory,
String tag, File messageFile )
String tag, File messageFile, boolean sign )
{
Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( workingDirectory, "tag" );

if ( sign )
{
cl.createArg().setValue( "-s" );
}

cl.createArg().setValue( "-F" );
cl.createArg().setValue( messageFile.getAbsolutePath() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,28 @@ public void setUp()
public void testCommandLineTag()
throws Exception
{
testCommandLine( "scm:git:http://foo.com/git/trunk", "my-tag-1", "git tag " + messageFileString + " my-tag-1" );
testCommandLine( "scm:git:http://foo.com/git/trunk", "my-tag-1", "git tag " + messageFileString + " my-tag-1", false );
}

public void testCommandLineWithUsernameAndTag()
throws Exception
{
testCommandLine( "scm:git:http://anonymous@foo.com/git/trunk", "my-tag-1",
"git tag " + messageFileString + " my-tag-1" );
"git tag " + messageFileString + " my-tag-1", false );
}

public void testCommandLineWithUsernameAndTagAndSign()
throws Exception
{
testCommandLine( "scm:git:http://anonymous@foo.com/git/trunk", "my-tag-1",
"git tag -s " + messageFileString + " my-tag-1", true );
}

// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------

private void testCommandLine( String scmUrl, String tag, String commandLine )
private void testCommandLine( String scmUrl, String tag, String commandLine, boolean sign )
throws Exception
{
File workingDirectory = getTestFile( "target/git-checkin-command-test" );
Expand All @@ -78,7 +85,7 @@ private void testCommandLine( String scmUrl, String tag, String commandLine )

GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();

Commandline cl = GitTagCommand.createCommandLine( gitRepository, workingDirectory, tag, messageFile );
Commandline cl = GitTagCommand.createCommandLine( gitRepository, workingDirectory, tag, messageFile, sign );

assertCommandLine( commandLine, workingDirectory, cl );
}
Expand Down

0 comments on commit 6c31363

Please sign in to comment.