Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ public class CommandParameter implements Serializable {
*/
public static final CommandParameter IGNORE_WHITESPACE = new CommandParameter("ignoreWhitespace");

/**
* Parameter to indicate whether the commit should be signed or not.
* if false (default true) this will be used by the Git provider to pass the --no-signoff option to the commit command.
* @since 2.1.1
*/
public static final CommandParameter SCM_COMMIT_SIGN = new CommandParameter("gitCommitSign");

/**
* Parameter name
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ public boolean getBoolean(CommandParameter parameter) throws ScmException {
* @throws ScmException if the parameter doesn't exist
*/
public boolean getBoolean(CommandParameter parameter, boolean defaultValue) throws ScmException {
return Boolean.valueOf(getString(parameter, Boolean.toString(defaultValue)))
.booleanValue();
return Boolean.parseBoolean(getString(parameter, Boolean.toString(defaultValue)));
}

// ----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class ScmTagParameters implements Serializable {

private boolean sign = false;

private boolean forceNoSign = false;

private String scmRevision;

public ScmTagParameters() {
Expand Down Expand Up @@ -87,7 +89,22 @@ public void setScmRevision(String scmRevision) {
this.scmRevision = scmRevision;
}

public boolean isForceNoSign() {
return forceNoSign;
}

public void setForceNoSign(boolean forceNoSign) {
this.forceNoSign = forceNoSign;
}

@Override
public String toString() {
return "[" + scmRevision + "] " + message;
return "ScmTagParameters{" + "message='"
+ message + '\'' + ", remoteTagging="
+ remoteTagging + ", pinExternals="
+ pinExternals + ", sign="
+ sign + ", forceNoSign="
+ forceNoSign + ", scmRevision='"
+ scmRevision + '\'' + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmBranch;
import org.apache.maven.scm.ScmBranchParameters;
import org.apache.maven.scm.ScmException;
Expand Down Expand Up @@ -388,6 +389,12 @@ public CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, Sc
return this.getProviderByRepository(repository).checkIn(repository, fileSet, revision, message);
}

@Override
public CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, CommandParameters commandParameters)
throws ScmException {
return this.getProviderByRepository(repository).checkIn(repository, fileSet, commandParameters);
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Date;
import java.util.List;

import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmBranch;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
Expand Down Expand Up @@ -280,6 +281,23 @@ ChangeLogScmResult changeLog(
*/
CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, String message) throws ScmException;

/**
* Save the changes you have done into the repository. This will create a new version of the file or directory in
* the repository.
* <p>
* When the fileSet has no entries, the {@code fileSet.getBasedir()} is recursively committed. When the fileSet
* has entries, the commit is non-recursive and only the elements in the fileSet are committed.
*
* @param repository the source control system
* @param fileSet the files to check in (sometimes called commit)
* @param commandParameters parameters for the command, such as commit message and whether to sign the commit. {@link CommandParameters}
* @return a {@link CheckInScmResult} that contains the file paths (relative to {@code fileSet.getBasedir()}) that
* have been checked in.
* @throws ScmException if any
*/
CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, CommandParameters commandParameters)
throws ScmException;

/**
* Save the changes you have done into the repository. This will create a new version of the file or directory in
* the repository.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,16 @@ public CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, Sc
return checkin(repository.getProviderRepository(), fileSet, parameters);
}

@Override
public CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters)
throws ScmException {
return checkIn(
repository,
fileSet,
parameters.getScmVersion(CommandParameter.SCM_VERSION, null),
parameters.getString(CommandParameter.MESSAGE));
}

protected CheckInScmResult checkin(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
throw new NoSuchCommandScmException("checkin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,23 @@ CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, String ta
*/
CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, String message) throws ScmException;

/**
* Save the changes you have done into the repository. This will create a new version of the file or
* directory in the repository.
* <p>
* When the fileSet has no entries, the fileSet.getBaseDir() is recursively committed.
* When the fileSet has entries, the commit is non-recursive and only the elements in the fileSet
* are committed.
*
* @param repository the source control system
* @param fileSet the files to check in (sometimes called commit)
* @param parameters {@link CommandParameters}
* @return TODO
* @throws ScmException if any
*/
CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters)
throws ScmException;

/**
* Save the changes you have done into the repository. This will create a new version of the file or
* directory in the repository.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ public class TagMojo extends AbstractScmMojo {
@Parameter(property = "sign", defaultValue = "false")
private boolean sign;

/**
* Enable the "--no-sign" in Git
*
* @since 2.1.1
*/
@Parameter(property = "forceNoSign", defaultValue = "false")
private boolean forceNoSign;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there is both sign and forceNoSign which can be set independently of each other? Which ones is gonna win @olamy ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing really prevent you using git tag --sign --no-sign

But they do have a different behaviour (but I agree no sense used together maybe a warning in this case?)

forcing --sign in a the mojo means you forcing the tag to be signed (whatever environment people have).

The other one is really a sort of parameter to avoid failure for scm developer having configured signing in ~/.gitconfig

another option is possibly for testing only to change local configuration of the git test repos.
such

git config --local commit.gpgsign false
git config --local tag.gpgsign false

I vaguely remember issue with jgit and modifying my ~/.gitconfig (so if testing that make a backup first :))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at my proposal in #1293.


@Inject
public TagMojo(ScmManager manager, SettingsDecrypter settingsDecrypter) {
super(manager, settingsDecrypter);
Expand Down Expand Up @@ -150,6 +158,7 @@ public void execute() throws MojoExecutionException {
scmTagParameters.setRemoteTagging(remoteTagging);
scmTagParameters.setPinExternals(pinExternals);
scmTagParameters.setSign(sign);
scmTagParameters.setForceNoSign(forceNoSign);

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

Expand All @@ -158,4 +167,20 @@ public void execute() throws MojoExecutionException {
throw new MojoExecutionException("Cannot run tag command : ", e);
}
}

public boolean isSign() {
return sign;
}

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

public boolean isForceNoSign() {
return forceNoSign;
}

public void setForceNoSign(boolean forceNoSign) {
this.forceNoSign = forceNoSign;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public void testUntag() throws Exception {

TagMojo tagMojo = (TagMojo) lookupMojo("tag", getTestFile("src/test/resources/mojos/untag/tag.xml"));
tagMojo.setWorkingDirectory(checkoutDir);
tagMojo.setSign(false);
tagMojo.setForceNoSign(true);
tagMojo.setConnectionUrl(getConnectionLocalAddress(tagMojo));
tagMojo.execute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ public CheckInScmResult checkin(ScmProviderRepository repository, ScmFileSet fil
return (CheckInScmResult) executeCommand(getCheckInCommand(), repository, fileSet, parameters);
}

@Override
public CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters)
throws ScmException {
return (CheckInScmResult) getCheckInCommand().execute(repository.getProviderRepository(), fileSet, parameters);
}

protected abstract GitCommand getCheckOutCommand();

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ public ScmResult executeTagCommand(

int exitCode;

boolean sign = scmTagParameters.isSign();

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

exitCode = GitCommandLineUtils.execute(clTag, stdout, stderr);
if (exitCode != 0) {
Expand Down Expand Up @@ -127,13 +131,21 @@ public ScmResult executeTagCommand(
//
// ----------------------------------------------------------------------

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

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

cl.createArg().setValue("-F");
cl.createArg().setValue(messageFile.getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public void setUp() throws Exception {
@Test
public void testCommandLineTag() throws Exception {
testCommandLine(
"scm:git:http://foo.com/git/trunk", "my-tag-1", "git tag " + messageFileString + " my-tag-1", false);
"scm:git:http://foo.com/git/trunk",
"my-tag-1",
"git tag " + messageFileString + " my-tag-1",
false,
false);
}

@Test
Expand All @@ -61,30 +65,44 @@ public void testCommandLineWithUsernameAndTag() throws Exception {
"scm:git:http://anonymous@foo.com/git/trunk",
"my-tag-1",
"git tag " + messageFileString + " my-tag-1",
false,
false);
}

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

@Test
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);
true,
false);
}

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

private void testCommandLine(String scmUrl, String tag, String commandLine, boolean sign) throws Exception {
private void testCommandLine(String scmUrl, String tag, String commandLine, boolean sign, boolean forceNoSign)
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, sign);
Commandline cl =
GitTagCommand.createCommandLine(gitRepository, workingDirectory, tag, messageFile, sign, forceNoSign);

assertCommandLine(commandLine, workingDirectory, cl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.io.File;
import java.io.IOException;

import org.apache.maven.scm.CommandParameter;
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.PlexusJUnit4TestCase;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.command.checkin.CheckInScmResult;
Expand Down Expand Up @@ -84,12 +86,20 @@ public void testRejectedNonFastForwardPush() throws Exception {

ScmFileSet blockingFileSet = createWorkspaceChange(rejectedRepo);

CheckInScmResult blockingResult = getScmManager().checkIn(scmRepository, blockingFileSet, "Blocking commit");
CommandParameters commandParameters = new CommandParameters();
commandParameters.setString(CommandParameter.MESSAGE, "Blocking commit");
commandParameters.setString(CommandParameter.SCM_COMMIT_SIGN, "false");

CheckInScmResult blockingResult = getScmManager().checkIn(scmRepository, blockingFileSet, commandParameters);
assertResultIsSuccess(blockingResult);

ScmFileSet rejectedFileSet = createWorkspaceChange(blockingRepo);

CheckInScmResult checkInScmResult = getScmManager().checkIn(scmRepository, rejectedFileSet, "Rejected commit");
commandParameters = new CommandParameters();
commandParameters.setString(CommandParameter.MESSAGE, "Rejected commit");
commandParameters.setString(CommandParameter.SCM_COMMIT_SIGN, "false");

CheckInScmResult checkInScmResult = getScmManager().checkIn(scmRepository, rejectedFileSet, commandParameters);
assertFalse(
"check-in should have been rejected since fast forward was not possible", checkInScmResult.isSuccess());
}
Expand Down
Loading
Loading