Skip to content

Commit 89925c3

Browse files
authored
feat(cli): prompt user when landing PR with several commits (#572)
And add an option to abort the session if trying to land more than one commit. Refs: nodejs/node#40436
1 parent 8f1fa9c commit 89925c3

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

components/git/land.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ const landActions = {
4646
'other commit messages',
4747
default: false,
4848
type: 'boolean'
49+
},
50+
oneCommitMax: {
51+
describe: 'When run in conjunction with the --yes and --autorebase ' +
52+
'options, will abort the session if trying to land more than one commit',
53+
default: false,
54+
type: 'boolean'
4955
}
5056
};
5157

lib/landing_session.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ const LINT_RESULTS = {
2222
};
2323

2424
class LandingSession extends Session {
25-
constructor(cli, req, dir,
26-
{ prid, backport, lint, autorebase, fixupAll, checkCI } = {}) {
25+
constructor(cli, req, dir, {
26+
prid, backport, lint, autorebase, fixupAll,
27+
checkCI, oneCommitMax
28+
} = {}) {
2729
super(cli, dir, prid);
2830
this.req = req;
2931
this.backport = backport;
3032
this.lint = lint;
3133
this.autorebase = autorebase;
3234
this.fixupAll = fixupAll;
35+
this.oneCommitMax = oneCommitMax;
3336
this.expectedCommitShas = [];
3437
this.checkCI = !!checkCI;
3538
}
@@ -40,6 +43,7 @@ class LandingSession extends Session {
4043
args.lint = this.lint;
4144
args.autorebase = this.autorebase;
4245
args.fixupAll = this.fixupAll;
46+
args.oneCommitMax = this.oneCommitMax;
4347
return args;
4448
}
4549

@@ -349,7 +353,9 @@ class LandingSession extends Session {
349353
}
350354

351355
async final() {
352-
const { cli, owner, repo, upstream, branch, prid } = this;
356+
const {
357+
cli, owner, repo, upstream, branch, prid, oneCommitMax
358+
} = this;
353359

354360
// Check that git rebase/am has been completed.
355361
if (!this.readyToFinal()) {
@@ -360,6 +366,20 @@ class LandingSession extends Session {
360366
};
361367

362368
const stray = this.getStrayCommits();
369+
if (stray.length > 1) {
370+
const forceLand = await cli.prompt(
371+
'There is more than one commit in the PR. ' +
372+
'Do you still want to land it?',
373+
{ defaultAnswer: !oneCommitMax });
374+
375+
if (!forceLand) {
376+
cli.info(
377+
'Use --fixupAll option, squash the PR manually or land the PR from ' +
378+
'the command line.'
379+
);
380+
process.exit(1);
381+
}
382+
}
363383
const strayVerbose = this.getStrayCommits(true);
364384
const validateCommand = path.join(
365385
__dirname,

0 commit comments

Comments
 (0)