Skip to content

Commit 4c55189

Browse files
committed
feat(cli): prompt user when landing PR with several commits
1 parent 35d281b commit 4c55189

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

components/git/land.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ const landActions = {
4646
'other commit messages',
4747
default: false,
4848
type: 'boolean'
49+
},
50+
allowMultipleCommits: {
51+
describe: 'Switch default answer if the pull request more than one commit',
52+
default: false,
53+
type: 'boolean'
4954
}
5055
};
5156

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, allowMultipleCommits
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.allowMultipleCommits = allowMultipleCommits;
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.allowMultipleCommits = this.allowMultipleCommits;
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, allowMultipleCommits
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 are more than one commit in the PR. ' +
372+
'Do you still want to land it?',
373+
{ defaultAnswer: allowMultipleCommits });
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)