Skip to content

Commit

Permalink
enh(cli): add --oneCommitMax option
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Oct 14, 2021
1 parent 35d281b commit a54cebd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions components/git/land.js
Expand Up @@ -46,6 +46,11 @@ const landActions = {
'other commit messages',
default: false,
type: 'boolean'
},
oneCommitMax: {
describe: 'Abort if the pull request more than one commit',
default: false,
type: 'boolean'
}
};

Expand Down
15 changes: 12 additions & 3 deletions lib/landing_session.js
Expand Up @@ -22,14 +22,17 @@ const LINT_RESULTS = {
};

class LandingSession extends Session {
constructor(cli, req, dir,
{ prid, backport, lint, autorebase, fixupAll, checkCI } = {}) {
constructor(cli, req, dir, {
prid, backport, lint, autorebase, fixupAll,
checkCI, oneCommitMax
} = {}) {
super(cli, dir, prid);
this.req = req;
this.backport = backport;
this.lint = lint;
this.autorebase = autorebase;
this.fixupAll = fixupAll;
this.oneCommitMax = oneCommitMax;
this.expectedCommitShas = [];
this.checkCI = !!checkCI;
}
Expand All @@ -40,6 +43,7 @@ class LandingSession extends Session {
args.lint = this.lint;
args.autorebase = this.autorebase;
args.fixupAll = this.fixupAll;
args.oneCommitMax = this.oneCommitMax;
return args;
}

Expand Down Expand Up @@ -349,7 +353,7 @@ class LandingSession extends Session {
}

async final() {
const { cli, owner, repo, upstream, branch, prid } = this;
const { cli, owner, repo, upstream, branch, prid, oneCommitMax } = this;

// Check that git rebase/am has been completed.
if (!this.readyToFinal()) {
Expand All @@ -360,6 +364,11 @@ class LandingSession extends Session {
};

const stray = this.getStrayCommits();
if (oneCommitMax && stray.length > 1) {
throw new Error(`There are ${stray.length} commits in the PR. ` +
'Only one commit is permitted by the configuration. Use --fixupAll ' +
'or remove --oneCommitMax flag.');
}
const strayVerbose = this.getStrayCommits(true);
const validateCommand = path.join(
__dirname,
Expand Down

0 comments on commit a54cebd

Please sign in to comment.