From c8d757624bb5066e264c4b31f7b9559fde474ffb Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Tue, 29 Sep 2020 16:06:50 -0700 Subject: [PATCH] refactor(dev-infra): use common git client for git environment reset (#39051) For rebase tooling, use the `GitClient`'s `checkout` method rather than a custom function doing the same task. PR Close #39051 --- dev-infra/pr/rebase/index.ts | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/dev-infra/pr/rebase/index.ts b/dev-infra/pr/rebase/index.ts index b79abb2a10..7aa63e6290 100644 --- a/dev-infra/pr/rebase/index.ts +++ b/dev-infra/pr/rebase/index.ts @@ -7,7 +7,6 @@ */ import {types as graphQLTypes} from 'typed-graphqlify'; -import {URL} from 'url'; import {getConfig, NgDevConfig} from '../../utils/config'; import {error, info, promptConfirm} from '../../utils/console'; @@ -100,12 +99,12 @@ export async function rebasePr( info(`Pushing rebased PR #${prNumber} to ${fullHeadRef}`); git.run(['push', headRefUrl, `HEAD:${headRefName}`, forceWithLeaseFlag]); info(`Rebased and updated PR #${prNumber}`); - cleanUpGitState(); + git.checkout(previousBranchOrRevision, true); process.exit(0); } } catch (err) { error(err.message); - cleanUpGitState(); + git.checkout(previousBranchOrRevision, true); process.exit(1); } @@ -128,16 +127,6 @@ export async function rebasePr( info(`Cleaning up git state, and restoring previous state.`); } - cleanUpGitState(); + git.checkout(previousBranchOrRevision, true); process.exit(1); - - /** Reset git back to the original branch. */ - function cleanUpGitState() { - // Ensure that any outstanding rebases are aborted. - git.runGraceful(['rebase', '--abort'], {stdio: 'ignore'}); - // Ensure that any changes in the current repo state are cleared. - git.runGraceful(['reset', '--hard'], {stdio: 'ignore'}); - // Checkout the original branch from before the run began. - git.runGraceful(['checkout', previousBranchOrRevision], {stdio: 'ignore'}); - } }