From 4ad4a58a9471d3fd4e27e3b19bae979d91916cef Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Sat, 22 Aug 2020 23:28:40 +0300 Subject: [PATCH] feat: allow to fixup everything into first commit with fixupAll --- components/git/land.js | 6 ++++++ lib/landing_session.js | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/components/git/land.js b/components/git/land.js index c175b6e8..fee03f97 100644 --- a/components/git/land.js +++ b/components/git/land.js @@ -57,6 +57,12 @@ const landOptions = { describe: 'Automatically rebase branches with multiple commits', default: false, type: 'boolean' + }, + fixupAll: { + describe: 'Automatically fixup all commits to the first one dismissing ' + + 'other commit messages', + default: false, + type: 'boolean' } }; diff --git a/lib/landing_session.js b/lib/landing_session.js index ed61d9cd..87311dbd 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -22,12 +22,14 @@ const LINT_RESULTS = { }; class LandingSession extends Session { - constructor(cli, req, dir, { prid, backport, lint, autorebase } = {}) { + constructor(cli, req, dir, + { prid, backport, lint, autorebase, fixupAll } = {}) { super(cli, dir, prid); this.req = req; this.backport = backport; this.lint = lint; this.autorebase = autorebase; + this.fixupAll = fixupAll; } get argv() { @@ -35,6 +37,7 @@ class LandingSession extends Session { args.backport = this.backport; args.lint = this.lint; args.autorebase = this.autorebase; + args.fixupAll = this.fixupAll; return args; } @@ -222,6 +225,12 @@ class LandingSession extends Session { cli.log(`Couldn't rebase ${count} commits in the PR automatically`); this.makeRebaseSuggestion(subjects); } + } else if (this.fixupAll) { + 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']); + return await this.amend() && this.final(); } else { this.makeRebaseSuggestion(subjects); }