aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd/update.sh
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/cmd/update.sh')
-rw-r--r--Library/Homebrew/cmd/update.sh44
1 files changed, 29 insertions, 15 deletions
diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh
index b57691893..579890820 100644
--- a/Library/Homebrew/cmd/update.sh
+++ b/Library/Homebrew/cmd/update.sh
@@ -215,7 +215,20 @@ merge_or_rebase() {
trap reset_on_interrupt SIGINT
- REMOTE_REF="origin/$UPSTREAM_BRANCH"
+ if [[ "$DIR" = "$HOMEBREW_REPOSITORY" && -z "$HOMEBREW_NO_UPDATE_CLEANUP" ]]
+ then
+ UPSTREAM_TAG="$(git tag --list --sort=-version:refname | grep '^[0-9]*\.[0-9]*\.[0-9]*$' | head -n1)"
+ else
+ UPSTREAM_TAG=""
+ fi
+
+ if [ -n "$UPSTREAM_TAG" ]
+ then
+ REMOTE_REF="refs/tags/$UPSTREAM_TAG"
+ UPSTREAM_BRANCH="stable"
+ else
+ REMOTE_REF="origin/$UPSTREAM_BRANCH"
+ fi
if [[ -n "$(git status --untracked-files=all --porcelain 2>/dev/null)" ]]
then
@@ -242,19 +255,13 @@ EOS
fi
INITIAL_BRANCH="$(git symbolic-ref --short HEAD 2>/dev/null)"
- if [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" ]]
+ if [[ -n "$UPSTREAM_TAG" ]] ||
+ [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" ]]
then
-
- if [[ -z "$HOMEBREW_NO_UPDATE_CLEANUP" ]]
- then
- echo "Checking out $UPSTREAM_BRANCH in $DIR..."
- echo "To checkout $INITIAL_BRANCH in $DIR run:"
- echo " 'cd $DIR && git checkout $INITIAL_BRANCH"
- fi
-
# Recreate and check out `#{upstream_branch}` if unable to fast-forward
# it to `origin/#{@upstream_branch}`. Otherwise, just check it out.
- if git merge-base --is-ancestor "$UPSTREAM_BRANCH" "$REMOTE_REF" &>/dev/null
+ if [[ -z "$UPSTREAM_TAG" ]] &&
+ git merge-base --is-ancestor "$UPSTREAM_BRANCH" "$REMOTE_REF" &>/dev/null
then
git checkout --force "$UPSTREAM_BRANCH" "${QUIET_ARGS[@]}"
else
@@ -290,7 +297,8 @@ EOS
if [[ -n "$HOMEBREW_NO_UPDATE_CLEANUP" ]]
then
- if [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" ]]
+ if [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" &&
+ ! "$INITIAL_BRANCH" =~ ^v[0-9]+\.[0-9]+\.[0-9]$ ]]
then
git checkout "$INITIAL_BRANCH" "${QUIET_ARGS[@]}"
fi
@@ -337,7 +345,7 @@ EOS
set -x
fi
- if [[ -z "$HOMEBREW_UPDATE_CLEANUP" ]]
+ if [[ -z "$HOMEBREW_UPDATE_CLEANUP" && -z "$HOMEBREW_UPDATE_TO_TAG" ]]
then
if [[ -n "$HOMEBREW_DEVELOPER" || -n "$HOMEBREW_DEV_CMD_RUN" ]]
then
@@ -425,6 +433,12 @@ EOS
declare UPSTREAM_BRANCH"$TAP_VAR"="$UPSTREAM_BRANCH_DIR"
declare PREFETCH_REVISION"$TAP_VAR"="$(git rev-parse -q --verify refs/remotes/origin/"$UPSTREAM_BRANCH_DIR")"
+ # Force a full update if we don't have any tags.
+ if [[ "$DIR" = "$HOMEBREW_REPOSITORY" && -z "$(git tag --list)" ]]
+ then
+ HOMEBREW_UPDATE_FORCE=1
+ fi
+
if [[ -z "$HOMEBREW_UPDATE_FORCE" ]]
then
[[ -n "$SKIP_FETCH_BREW_REPOSITORY" && "$DIR" = "$HOMEBREW_REPOSITORY" ]] && continue
@@ -480,10 +494,10 @@ EOS
if [[ -n "$HOMEBREW_UPDATE_PREINSTALL" ]]
then
- git fetch --force "${QUIET_ARGS[@]}" origin \
+ git fetch --tags --force "${QUIET_ARGS[@]}" origin \
"refs/heads/$UPSTREAM_BRANCH_DIR:refs/remotes/origin/$UPSTREAM_BRANCH_DIR" 2>/dev/null
else
- if ! git fetch --force "${QUIET_ARGS[@]}" origin \
+ if ! git fetch --tags --force "${QUIET_ARGS[@]}" origin \
"refs/heads/$UPSTREAM_BRANCH_DIR:refs/remotes/origin/$UPSTREAM_BRANCH_DIR"
then
echo "Fetching $DIR failed!" >>"$update_failed_file"