diff --git a/package.json b/package.json index 884134d8..3b64057e 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "chalk": "^2.3.0", "cosmiconfig": "^5.1.0", "del": "^4.1.0", + "escape-string-regexp": "^2.0.0", "execa": "^1.0.0", "github-url-from-git": "^1.5.0", "has-yarn": "^2.1.0", diff --git a/source/git-util.js b/source/git-util.js index f4a96975..91a996ca 100644 --- a/source/git-util.js +++ b/source/git-util.js @@ -1,5 +1,6 @@ 'use strict'; const execa = require('execa'); +const escapeStringRegexp = require('escape-string-regexp'); const version = require('./version'); exports.latestTag = () => execa.stdout('git', ['describe', '--abbrev=0', '--tags']); @@ -20,8 +21,10 @@ exports.latestTagOrFirstCommit = async () => { }; exports.hasUpstream = async () => { - const {stdout} = await execa('git', ['status', '--short', '--branch', '--porcelain=2']); - return /^# branch\.upstream [\w\-/]+$/m.test(stdout); + const escapedCurrentBranch = escapeStringRegexp(await exports.currentBranch()); + const {stdout} = await execa('git', ['status', '--short', '--branch', '--porcelain']); + + return new RegExp(String.raw`^## ${escapedCurrentBranch}\.\.\..+\/${escapedCurrentBranch}`).test(stdout); }; exports.currentBranch = () => execa.stdout('git', ['symbolic-ref', '--short', 'HEAD']);