Check that git branch is up to date before publishing
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user