From d4d03f3d7f437d4199dcfec58cbd98735e5e7d51 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 1 Jun 2018 13:55:40 -0700 Subject: Check that git branch is up to date before publishing --- packages/monorepo-scripts/src/prepublish_checks.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/monorepo-scripts/src/prepublish_checks.ts b/packages/monorepo-scripts/src/prepublish_checks.ts index ae58524f5..2c096d8f6 100644 --- a/packages/monorepo-scripts/src/prepublish_checks.ts +++ b/packages/monorepo-scripts/src/prepublish_checks.ts @@ -47,9 +47,25 @@ async function checkPublishRequiredSetupAsync(): Promise { } catch (err) { throw new Error('You must setup your AWS credentials by running `aws configure`. Do this and try again.'); } + + utils.log('Checking that git branch is up to date with upstream...'); + await execAsync('git fetch'); + const res = await execAsync('git status -bs'); // s - short format, b - branch info + /** + * Possible outcomes + * ## branch_name...origin/branch_name [behind n] + * ## branch_name...origin/branch_name [ahead n] + * ## branch_name...origin/branch_name + */ + const gitShortStatusHeader = res.stdout.split('\n')[0]; + if (gitShortStatusHeader.includes('behind')) { + throw new Error('Your branch is behind upstream. Please pull before publishing.'); + } else if (gitShortStatusHeader.includes('ahead')) { + throw new Error('Your branch is ahead of upstream. Please push before publishing.'); + } } checkPublishRequiredSetupAsync().catch(err => { - utils.log(err); + utils.log(err.message); process.exit(1); }); -- cgit v1.2.3