diff --git a/src/lib/git.test.ts b/src/lib/git.test.ts index 59cdac9f..5dfff7b6 100644 --- a/src/lib/git.test.ts +++ b/src/lib/git.test.ts @@ -403,6 +403,35 @@ describe('cherrypick', () => { ]); }); + it('should use signoff option when specified', async () => { + const spawnSpy = jest + .spyOn(childProcess, 'spawnPromise') + .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock getIsMergeCommit(...) + .mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock cherrypick(...) + + await cherrypick({ + options: { ...options, signoff: true }, + sha: 'abcd', + commitAuthor, + }); + + const args = spawnSpy.mock.calls[1]; + expect(args).toEqual([ + 'git', + [ + '-c', + 'user.name="Soren L"', + '-c', + 'user.email="soren@mail.dk"', + 'cherry-pick', + '-x', + '--signoff', + 'abcd', + ], + '/myHomeDir/.backport/repositories/elastic/kibana', + ]); + }); + it('should return `needsResolving: true` upon cherrypick error', async () => { jest .spyOn(childProcess, 'spawnPromise') diff --git a/src/lib/git.ts b/src/lib/git.ts index 6e5f3d22..e1192453 100644 --- a/src/lib/git.ts +++ b/src/lib/git.ts @@ -331,6 +331,7 @@ export async function cherrypick({ ? ['--mainline', `${options.mainline}`] : []), ...(options.cherrypickRef === false ? [] : ['-x']), + ...(options.signoff ? ['--signoff'] : []), shaOrRange, ]; diff --git a/src/options/ConfigOptions.ts b/src/options/ConfigOptions.ts index 10656049..ca72ad6c 100644 --- a/src/options/ConfigOptions.ts +++ b/src/options/ConfigOptions.ts @@ -67,6 +67,7 @@ type Options = Partial<{ targetBranchChoices: TargetBranchChoiceOrString[]; targetBranches: string[]; targetPRLabels: string[]; + signoff: boolean; }>; export type ConfigFileOptions = Options & diff --git a/src/options/cliArgs.ts b/src/options/cliArgs.ts index ae23216a..bc8f435a 100644 --- a/src/options/cliArgs.ts +++ b/src/options/cliArgs.ts @@ -208,6 +208,12 @@ export function getOptionsFromCliArgs(processArgs: readonly string[]) { }, }) + .option('signoff', { + description: 'Pass the --signoff option to the cherry-pick command', + type: 'boolean', + alias: ['s'], + }) + // display 10 commits to pick from .option('maxNumber', { description: 'Number of commits to choose from', diff --git a/src/options/options.test.ts b/src/options/options.test.ts index 6c07d1da..59d5a82a 100644 --- a/src/options/options.test.ts +++ b/src/options/options.test.ts @@ -234,6 +234,7 @@ describe('getOptions', () => { repoOwner: 'elastic', resetAuthor: false, reviewers: [], + signoff: false, sourceBranch: 'default-branch-from-github', sourcePRLabels: [], targetBranchChoices: ['7.9', '8.0'], diff --git a/src/options/options.ts b/src/options/options.ts index 16f825e5..222c9cda 100644 --- a/src/options/options.ts +++ b/src/options/options.ts @@ -52,6 +52,7 @@ export const defaultConfigOptions = { targetBranchChoices: [] as TargetBranchChoiceOrString[], targetBranches: [] as string[], targetPRLabels: [] as string[], + signoff: false, }; export async function getOptions({ diff --git a/src/test/e2e/cli/entrypoint.cli.private.test.ts b/src/test/e2e/cli/entrypoint.cli.private.test.ts index 4d1e65e7..c975ada7 100644 --- a/src/test/e2e/cli/entrypoint.cli.private.test.ts +++ b/src/test/e2e/cli/entrypoint.cli.private.test.ts @@ -65,6 +65,8 @@ describe('entrypoint cli', () => { --ls List commits instead of backporting them [boolean] --mainline Parent id of merge commit. Defaults to 1 when supplied without arguments [number] + -s, --signoff Pass the --signoff option to the cherry-pick command + [boolean] -n, --maxNumber, --number Number of commits to choose from [number] --multiple Select multiple branches/commits [boolean] --multipleBranches Backport to multiple branches [boolean]