Skip to content

Commit

Permalink
feat(git-node): add support for the --gpg-sign git flag (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Mar 18, 2023
1 parent b9c443b commit 92d621e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions components/git/land.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 16 additions & 10 deletions lib/landing_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ 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;
this.backport = backport;
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;
Expand Down Expand Up @@ -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);
Expand All @@ -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`);
Expand All @@ -160,6 +162,10 @@ export default class LandingSession extends Session {
command += ' --autosquash';
}

if (this.gpgSign) {
command += ' ' + this.gpgSign.join(' ');
}

return command;
}

Expand Down Expand Up @@ -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
Expand All @@ -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: {
Expand Down Expand Up @@ -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 ' +
Expand Down Expand Up @@ -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;
}

Expand All @@ -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');
Expand Down

0 comments on commit 92d621e

Please sign in to comment.