Skip to content

Commit ac75ac0

Browse files
authored
New option to be able to disable sign for commit/tag to be able use this with jgit when you have gpgsign configured in ~/.gitconfig (#1266)
* New option to be able to disable sign for commit/tag to be able use this with jgit when you have gpgsign forced in ~/.gitconfig --------- Signed-off-by: Olivier Lamy <olamy@apache.org>
1 parent cdff5d4 commit ac75ac0

File tree

25 files changed

+267
-31
lines changed

25 files changed

+267
-31
lines changed

maven-scm-api/src/main/java/org/apache/maven/scm/CommandParameter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ public class CommandParameter implements Serializable {
9393
*/
9494
public static final CommandParameter IGNORE_WHITESPACE = new CommandParameter("ignoreWhitespace");
9595

96+
/**
97+
* Parameter to indicate whether the commit should be signed or not.
98+
* if false (default true) this will be used by the Git provider to pass the --no-signoff option to the commit command.
99+
* @since 2.1.1
100+
*/
101+
public static final CommandParameter SCM_COMMIT_SIGN = new CommandParameter("gitCommitSign");
102+
96103
/**
97104
* Parameter name
98105
*/

maven-scm-api/src/main/java/org/apache/maven/scm/CommandParameters.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ public boolean getBoolean(CommandParameter parameter) throws ScmException {
187187
* @throws ScmException if the parameter doesn't exist
188188
*/
189189
public boolean getBoolean(CommandParameter parameter, boolean defaultValue) throws ScmException {
190-
return Boolean.valueOf(getString(parameter, Boolean.toString(defaultValue)))
191-
.booleanValue();
190+
return Boolean.parseBoolean(getString(parameter, Boolean.toString(defaultValue)));
192191
}
193192

194193
// ----------------------------------------------------------------------

maven-scm-api/src/main/java/org/apache/maven/scm/ScmTagParameters.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class ScmTagParameters implements Serializable {
3535

3636
private boolean sign = false;
3737

38+
private boolean forceNoSign = false;
39+
3840
private String scmRevision;
3941

4042
public ScmTagParameters() {
@@ -87,7 +89,22 @@ public void setScmRevision(String scmRevision) {
8789
this.scmRevision = scmRevision;
8890
}
8991

92+
public boolean isForceNoSign() {
93+
return forceNoSign;
94+
}
95+
96+
public void setForceNoSign(boolean forceNoSign) {
97+
this.forceNoSign = forceNoSign;
98+
}
99+
100+
@Override
90101
public String toString() {
91-
return "[" + scmRevision + "] " + message;
102+
return "ScmTagParameters{" + "message='"
103+
+ message + '\'' + ", remoteTagging="
104+
+ remoteTagging + ", pinExternals="
105+
+ pinExternals + ", sign="
106+
+ sign + ", forceNoSign="
107+
+ forceNoSign + ", scmRevision='"
108+
+ scmRevision + '\'' + '}';
92109
}
93110
}

maven-scm-api/src/main/java/org/apache/maven/scm/manager/AbstractScmManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Map;
2626
import java.util.concurrent.ConcurrentHashMap;
2727

28+
import org.apache.maven.scm.CommandParameters;
2829
import org.apache.maven.scm.ScmBranch;
2930
import org.apache.maven.scm.ScmBranchParameters;
3031
import org.apache.maven.scm.ScmException;
@@ -388,6 +389,12 @@ public CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, Sc
388389
return this.getProviderByRepository(repository).checkIn(repository, fileSet, revision, message);
389390
}
390391

392+
@Override
393+
public CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, CommandParameters commandParameters)
394+
throws ScmException {
395+
return this.getProviderByRepository(repository).checkIn(repository, fileSet, commandParameters);
396+
}
397+
391398
/**
392399
* {@inheritDoc}
393400
*/

maven-scm-api/src/main/java/org/apache/maven/scm/manager/ScmManager.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Date;
2323
import java.util.List;
2424

25+
import org.apache.maven.scm.CommandParameters;
2526
import org.apache.maven.scm.ScmBranch;
2627
import org.apache.maven.scm.ScmException;
2728
import org.apache.maven.scm.ScmFileSet;
@@ -280,6 +281,23 @@ ChangeLogScmResult changeLog(
280281
*/
281282
CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, String message) throws ScmException;
282283

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

maven-scm-api/src/main/java/org/apache/maven/scm/provider/AbstractScmProvider.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,16 @@ public CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, Sc
416416
return checkin(repository.getProviderRepository(), fileSet, parameters);
417417
}
418418

419+
@Override
420+
public CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters)
421+
throws ScmException {
422+
return checkIn(
423+
repository,
424+
fileSet,
425+
parameters.getScmVersion(CommandParameter.SCM_VERSION, null),
426+
parameters.getString(CommandParameter.MESSAGE));
427+
}
428+
419429
protected CheckInScmResult checkin(
420430
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
421431
throw new NoSuchCommandScmException("checkin");

maven-scm-api/src/main/java/org/apache/maven/scm/provider/ScmProvider.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,23 @@ CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, String ta
405405
*/
406406
CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, String message) throws ScmException;
407407

408+
/**
409+
* Save the changes you have done into the repository. This will create a new version of the file or
410+
* directory in the repository.
411+
* <p>
412+
* When the fileSet has no entries, the fileSet.getBaseDir() is recursively committed.
413+
* When the fileSet has entries, the commit is non-recursive and only the elements in the fileSet
414+
* are committed.
415+
*
416+
* @param repository the source control system
417+
* @param fileSet the files to check in (sometimes called commit)
418+
* @param parameters {@link CommandParameters}
419+
* @return TODO
420+
* @throws ScmException if any
421+
*/
422+
CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters)
423+
throws ScmException;
424+
408425
/**
409426
* Save the changes you have done into the repository. This will create a new version of the file or
410427
* directory in the repository.

maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/TagMojo.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ public class TagMojo extends AbstractScmMojo {
107107
@Parameter(property = "sign", defaultValue = "false")
108108
private boolean sign;
109109

110+
/**
111+
* Enable the "--no-sign" in Git
112+
*
113+
* @since 2.1.1
114+
*/
115+
@Parameter(property = "forceNoSign", defaultValue = "false")
116+
private boolean forceNoSign;
117+
110118
@Inject
111119
public TagMojo(ScmManager manager, SettingsDecrypter settingsDecrypter) {
112120
super(manager, settingsDecrypter);
@@ -150,6 +158,7 @@ public void execute() throws MojoExecutionException {
150158
scmTagParameters.setRemoteTagging(remoteTagging);
151159
scmTagParameters.setPinExternals(pinExternals);
152160
scmTagParameters.setSign(sign);
161+
scmTagParameters.setForceNoSign(forceNoSign);
153162

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

@@ -158,4 +167,20 @@ public void execute() throws MojoExecutionException {
158167
throw new MojoExecutionException("Cannot run tag command : ", e);
159168
}
160169
}
170+
171+
public boolean isSign() {
172+
return sign;
173+
}
174+
175+
public void setSign(boolean sign) {
176+
this.sign = sign;
177+
}
178+
179+
public boolean isForceNoSign() {
180+
return forceNoSign;
181+
}
182+
183+
public void setForceNoSign(boolean forceNoSign) {
184+
this.forceNoSign = forceNoSign;
185+
}
161186
}

maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/UntagMojoTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public void testUntag() throws Exception {
7272

7373
TagMojo tagMojo = (TagMojo) lookupMojo("tag", getTestFile("src/test/resources/mojos/untag/tag.xml"));
7474
tagMojo.setWorkingDirectory(checkoutDir);
75+
tagMojo.setSign(false);
76+
tagMojo.setForceNoSign(true);
7577
tagMojo.setConnectionUrl(getConnectionLocalAddress(tagMojo));
7678
tagMojo.execute();
7779

maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/AbstractGitScmProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ public CheckInScmResult checkin(ScmProviderRepository repository, ScmFileSet fil
186186
return (CheckInScmResult) executeCommand(getCheckInCommand(), repository, fileSet, parameters);
187187
}
188188

189+
@Override
190+
public CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters)
191+
throws ScmException {
192+
return (CheckInScmResult) getCheckInCommand().execute(repository.getProviderRepository(), fileSet, parameters);
193+
}
194+
189195
protected abstract GitCommand getCheckOutCommand();
190196

191197
/** {@inheritDoc} */

0 commit comments

Comments
 (0)