diff options
Diffstat (limited to 'packages/monorepo-scripts')
-rw-r--r-- | packages/monorepo-scripts/src/prepublish_checks.ts | 18 |
1 files changed, 17 insertions, 1 deletions
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<void> { } 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); }); |