Skip to content

Commit a51f894

Browse files
committed
release-version.sh: remove hardcoded master+origin
We now discern the default/main branch, as well as its upstream remote, rather than hardcoding master and origin respectively.
1 parent e62940a commit a51f894

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

release-version.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,25 @@ no_changes_pending || die 'There are uncommitted changes!'
172172
test -z "$(git ls-files -o --exclude-standard)" ||
173173
die 'There are untracked files! Please stash them before releasing.'
174174

175-
# Check that we are on the master branch.
176-
test refs/heads/master = "$(git rev-parse --symbolic-full-name HEAD)" ||
177-
die "Not on 'master' branch"
175+
# Discern default branch.
176+
currentBranch=$(git rev-parse --abbrev-ref --symbolic-full-name HEAD)
177+
upstreamBranch=$(git rev-parse --abbrev-ref --symbolic-full-name @{u})
178+
remote=${upstreamBranch%/*}
179+
defaultBranch=$(git remote show "$remote" | grep "HEAD branch" | sed 's/.*: //')
178180

179-
# If REMOTE is unset, use origin by default.
180-
REMOTE="${REMOTE:-origin}"
181+
# Check that we are on the main branch.
182+
test "$currentBranch" = "$defaultBranch" || die "Non-default branch: $currentBranch"
181183

182-
# Check that the master branch isn't behind the upstream branch.
184+
# If REMOTE is unset, use branch's upstream remote by default.
185+
REMOTE="${REMOTE:-$remote}"
186+
187+
# Check that the main branch isn't behind the upstream branch.
183188
HEAD="$(git rev-parse HEAD)" &&
184-
git fetch "$REMOTE" master &&
189+
git fetch "$REMOTE" "$defaultBranch" &&
185190
FETCH_HEAD="$(git rev-parse FETCH_HEAD)" &&
186191
test "$FETCH_HEAD" = HEAD ||
187192
test "$FETCH_HEAD" = "$(git merge-base $FETCH_HEAD $HEAD)" ||
188-
die "'master' is not up-to-date"
193+
die "'$defaultBranch' is not up-to-date"
189194

190195
# Ensure license headers are up-to-date.
191196
test "$SKIP_LICENSE_UPDATE" -o -z "$licenseName" -o "$licenseName" = "N/A" || {

0 commit comments

Comments
 (0)