From 92d621eebc5bd2d9548d9f728ebfb2ac7d64f62c Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 18 Mar 2023 16:13:08 +0100 Subject: [PATCH] feat(git-node): add support for the `--gpg-sign` git flag (#684) --- .eslintrc | 2 +- components/git/land.js | 4 ++++ lib/landing_session.js | 26 ++++++++++++++++---------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.eslintrc b/.eslintrc index 03861c2d..5a1ce310 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,7 +5,7 @@ "space-before-function-paren": ["error", "never"], "no-multi-spaces": ["error", { "ignoreEOLComments": true }], "camelcase": "off", - "max-len": [2, 80, 4, {"ignoreRegExpLiterals": true, "ignoreUrls": true}], + "max-len": [2, 100, 4, {"ignoreRegExpLiterals": true, "ignoreUrls": true}], "object-property-newline": "off" }, "env": { diff --git a/components/git/land.js b/components/git/land.js index 2e467618..f2fa5b69 100644 --- a/components/git/land.js +++ b/components/git/land.js @@ -38,6 +38,10 @@ const landActions = { default: false, type: 'boolean' }, + 'gpg-sign': { + describe: 'GPG-sign commits, will be passed to the git process', + alias: 'S' + }, autorebase: { describe: 'Automatically rebase branches with multiple commits', default: false, diff --git a/lib/landing_session.js b/lib/landing_session.js index ef7890fc..3facf6b4 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -23,7 +23,7 @@ const LINT_RESULTS = { export default class LandingSession extends Session { constructor(cli, req, dir, { prid, backport, lint, autorebase, fixupAll, - checkCI, oneCommitMax + checkCI, oneCommitMax, ...argv } = {}) { super(cli, dir, prid); this.req = req; @@ -31,6 +31,9 @@ export default class LandingSession extends Session { this.lint = lint; this.autorebase = autorebase; this.fixupAll = fixupAll; + this.gpgSign = argv?.['gpg-sign'] + ? (argv['gpg-sign'] === true ? ['-S'] : ['-S', argv['gpg-sign']]) + : []; this.oneCommitMax = oneCommitMax; this.expectedCommitShas = []; this.checkCI = !!checkCI; @@ -119,9 +122,8 @@ export default class LandingSession extends Session { const allowEmptyCommits = this.fixupAll ? ['--allow-empty'] : []; try { await forceRunAsync('git', - ['cherry-pick', ...allowEmptyCommits, `${base}..${head}`], - { ignoreFailure: false } - ); + ['cherry-pick', ...allowEmptyCommits, ...this.gpgSign, `${base}..${head}`], + { ignoreFailure: false }); } catch (ex) { cli.error('Failed to apply patches'); process.exit(1); @@ -137,7 +139,7 @@ export default class LandingSession extends Session { // Update items then stage files and amend the last commit. await updateDeprecations(unmarkedDeprecations); await runAsync('git', ['add', 'doc', 'lib', 'src', 'test']); - await runAsync('git', ['commit', '--amend', '--no-edit']); + await runAsync('git', ['commit', '--amend', '--no-edit', ...this.gpgSign]); cli .stopSpinner(`Updated ${unmarkedDepCount} DEPOXXX items in codebase`); @@ -160,6 +162,10 @@ export default class LandingSession extends Session { command += ' --autosquash'; } + if (this.gpgSign) { + command += ' ' + this.gpgSign.join(' '); + } + return command; } @@ -215,7 +221,7 @@ export default class LandingSession extends Session { cli.log(`There are ${subjects.length} commits in the PR. ` + 'Attempting to fixup everything into first commit.'); await runAsync('git', ['reset', '--soft', `HEAD~${subjects.length - 1}`]); - await runAsync('git', ['commit', '--amend', '--no-edit']); + await runAsync('git', ['commit', '--amend', '--no-edit', ...this.gpgSign]); return await this.amend() && this.final(); } else if (this.autorebase && this.canAutomaticallyRebase(subjects)) { // Run git rebase in interactive mode with autosquash but without editor @@ -227,7 +233,7 @@ export default class LandingSession extends Session { const msgAmend = `-x "git node land --amend ${assumeYes}"`; try { await forceRunAsync('git', - ['rebase', `${upstream}/${branch}`, '-i', '--autosquash', msgAmend], + ['rebase', ...this.gpgSign, `${upstream}/${branch}`, '-i', '--autosquash', msgAmend], { ignoreFailure: false, spawnArgs: { @@ -278,7 +284,7 @@ export default class LandingSession extends Session { await runAsync('git', ['add', '.']); // Final message will be edited later - don't try to change it here. - await runAsync('git', ['commit', '--amend', '--no-edit']); + await runAsync('git', ['commit', '--amend', '--no-edit', ...this.gpgSign]); } else { cli.info('Please fix lint errors and then run ' + '`git node land --amend` followed by ' + @@ -359,7 +365,7 @@ export default class LandingSession extends Session { cli.log(message.trim()); const takeMessage = await cli.prompt('Use this message?'); if (takeMessage) { - await runAsync('git', ['commit', '--amend', '-F', messageFile]); + await runAsync('git', ['commit', '--amend', '-F', messageFile, ...this.gpgSign]); return true; } @@ -371,7 +377,7 @@ export default class LandingSession extends Session { [`"${messageFile}"`], { ignoreFailure: false, spawnArgs: { shell: true } } ); - await runAsync('git', ['commit', '--amend', '-F', messageFile]); + await runAsync('git', ['commit', '--amend', '-F', messageFile, ...this.gpgSign]); return true; } catch { cli.error('Failed to edit the message using the configured editor');