Check that git branch is up to date before publishing

This commit is contained in:
Leonid Logvinov
2018-06-01 13:55:40 -07:00
parent 2f8e52f905
commit d4d03f3d7f

View File

@@ -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);
});