Skip to content

Commit

Permalink
Add git commitOptions.
Browse files Browse the repository at this point in the history
This means a user can do something like ["-s"] to satisfy DCO bots: https://github.com/apps/dco
  • Loading branch information
loosebazooka committed Aug 25, 2022
1 parent 7fd812c commit d5a3b24
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ Below are some properties of the Release Plugin Convention that are specific to
<td>main</td>
<td>Defines the branch which releases must be done off of. Eg. set to `release` to require releases are done on the `release` branch (or use a regular expression to allow releases from multiple branches, e.g. `/release|main/`). Set to null to ignore.</td>
</tr>
<tr>
<td>Git</td>
<td>commitOptions</td>
<td>{empty}</td>
<td>Defines an array of options to add to the git adapter during a commit. Example `commitOptions = ["-s"]`</td>
</tr>
<tr>
<td>Git</td>
<td>pushOptions</td>
Expand Down
5 changes: 5 additions & 0 deletions src/main/groovy/net/researchgate/release/GitAdapter.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class GitAdapter extends BaseScmAdapter {
final Property<String> requireBranch
@Optional
@Input
ListProperty<String> commitOptions
@Optional
@Input
final Property<Object> pushToRemote
@Optional
@Input
Expand All @@ -54,6 +57,7 @@ class GitAdapter extends BaseScmAdapter {

GitConfig(Project project) {
requireBranch = project.objects.property(String.class).convention('main')
commitOptions = project.objects.listProperty(String.class).convention([])
pushToRemote = project.objects.property(Object.class).convention('origin')
pushOptions = project.objects.listProperty(String.class).convention([])
signTag = project.objects.property(Boolean.class).convention(false)
Expand Down Expand Up @@ -142,6 +146,7 @@ class GitAdapter extends BaseScmAdapter {
} else {
command << '-a'
}
command += extension.git.commitOptions.get()

exec(command, directory: workingDirectory, errorPatterns: ['error: ', 'fatal: '])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,22 @@ class GitReleasePluginTests extends Specification {
then:
remoteRepo.list().any { it == 'gradle.properties' }
}

def 'commitOptions are passed through to git command'() {
given:
executor.exec(['git', 'checkout', '-B', 'myBranch'], failOnStderr: false, directory: localRepo, env: [:])
when:
project.release {
git {
requireBranch.set('myBranch')
commitOptions.set(['-s'])
}
}
(project.tasks.commitNewVersion as CommitNewVersion).commitNewVersion()
String newestCommit = executor.exec(['git', 'show', 'myBranch', '-s'], failOnStderr: false, directory: remoteRepo, env: [:])
executor.exec(['git', 'checkout', 'myBranch'], failOnStderr: false, directory: remoteRepo, env: [:])
executor.exec(['git', 'reset', '--hard', 'HEAD'], failOnStderr: false, directory: remoteRepo, env: [:])
then:
newestCommit.contains("Signed-off-by: Unit Test <unit@test>")
}
}

0 comments on commit d5a3b24

Please sign in to comment.