From f5b356b578e42ed0dfeb73e0359a21184a85034d Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Sat, 22 Aug 2020 23:27:39 +0300 Subject: [PATCH 1/2] refactor: use options object in LandingSession --- components/git/land.js | 3 +-- lib/landing_session.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/components/git/land.js b/components/git/land.js index 237ed7d5..c175b6e8 100644 --- a/components/git/land.js +++ b/components/git/land.js @@ -175,8 +175,7 @@ async function main(state, argv, cli, req, dir) { cli.log('run `git node land --abort` before starting a new session'); return; } - session = new LandingSession(cli, req, dir, argv.prid, argv.backport, - argv.lint, argv.autorebase); + session = new LandingSession(cli, req, dir, argv); const metadata = await getMetadata(session.argv, argv.skipRefs, cli); if (argv.backport) { const split = metadata.metadata.split('\n')[0]; diff --git a/lib/landing_session.js b/lib/landing_session.js index d8504d07..ed61d9cd 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -22,7 +22,7 @@ const LINT_RESULTS = { }; class LandingSession extends Session { - constructor(cli, req, dir, prid, backport, lint, autorebase) { + constructor(cli, req, dir, { prid, backport, lint, autorebase } = {}) { super(cli, dir, prid); this.req = req; this.backport = backport; From 0f5f0691a86c47e2af9ebb5abec3caf7e229c4b2 Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Sat, 22 Aug 2020 23:28:40 +0300 Subject: [PATCH 2/2] 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); }