aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMike McQuaid2016-09-24 20:42:55 +0100
committerMike McQuaid2016-09-24 20:43:14 +0100
commit87cf4f7f7a5e69d9e0ba2271f7bde2b8bf7e5c1e (patch)
treecc043195b52497682d0ba1f2526fc16c95c37bc6 /Library
parent232078df57418004bb9bf7abef877e734fcf7005 (diff)
downloadbrew-87cf4f7f7a5e69d9e0ba2271f7bde2b8bf7e5c1e.tar.bz2
update.sh: use GitHub tags API.
Otherwise if we've committed to `master` and someone `brew update`s before we cut the tag then they won't be updated to the latest version.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/update.sh32
1 files changed, 24 insertions, 8 deletions
diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh
index 579890820..4d72c6611 100644
--- a/Library/Homebrew/cmd/update.sh
+++ b/Library/Homebrew/cmd/update.sh
@@ -217,7 +217,8 @@ merge_or_rebase() {
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)"
+ UPSTREAM_TAG="$(git tag --list --sort=-version:refname |
+ grep --max-count=1 '^[0-9]*\.[0-9]*\.[0-9]*$')"
else
UPSTREAM_TAG=""
fi
@@ -244,7 +245,7 @@ merge_or_rebase() {
stash save --include-untracked "${QUIET_ARGS[@]}"
then
odie <<EOS
-Could not `git stash` in $DIR!
+Could not 'git stash' in $DIR!
Please stash/commit manually if you need to keep your changes or, if not, run:
cd $DIR
git reset --hard origin/master
@@ -469,15 +470,30 @@ EOS
then
UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY_URL#https://github.com/}"
UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY%.git}"
- UPSTREAM_BRANCH_LOCAL_SHA="$(git rev-parse "refs/remotes/origin/$UPSTREAM_BRANCH_DIR")"
- # Only try to `git fetch` when the upstream branch is at a different SHA
- # (so the API does not return 304: unmodified).
+
+ if [[ "$DIR" = "$HOMEBREW_REPOSITORY" && -z "$HOMEBREW_NO_UPDATE_CLEANUP" ]]
+ then
+ # Only try to `git fetch` when the upstream tags have changed
+ # (so the API does not return 304: unmodified).
+ GITHUB_API_ETAG="$(sed -n 's/^ETag: "\([a-f0-9]\{32\}\)".*/\1/p' ".git/GITHUB_HEADERS")"
+ GITHUB_API_ACCEPT="application/vnd.github.v3+json"
+ GITHUB_API_ENDPOINT="tags"
+ else
+ # Only try to `git fetch` when the upstream branch is at a different SHA
+ # (so the API does not return 304: unmodified).
+ GITHUB_API_ETAG="$(git rev-parse "refs/remotes/origin/$UPSTREAM_BRANCH_DIR")"
+ GITHUB_API_ACCEPT="application/vnd.github.v3.sha"
+ GITHUB_API_ENDPOINT="commits/$UPSTREAM_BRANCH_DIR"
+ fi
+
UPSTREAM_SHA_HTTP_CODE="$("$HOMEBREW_CURL" --silent --max-time 3 \
--output /dev/null --write-out "%{http_code}" \
+ --dump-header "$DIR/.git/GITHUB_HEADERS" \
--user-agent "$HOMEBREW_USER_AGENT_CURL" \
- --header "Accept: application/vnd.github.v3.sha" \
- --header "If-None-Match: \"$UPSTREAM_BRANCH_LOCAL_SHA\"" \
- "https://api.github.com/repos/$UPSTREAM_REPOSITORY/commits/$UPSTREAM_BRANCH_DIR")"
+ --header "Accept: $GITHUB_API_ACCEPT" \
+ --header "If-None-Match: \"$GITHUB_API_ETAG\"" \
+ "https://api.github.com/repos/$UPSTREAM_REPOSITORY/$GITHUB_API_ENDPOINT")"
+
# Touch FETCH_HEAD to confirm we've checked for an update.
[[ -f "$DIR/.git/FETCH_HEAD" ]] && touch "$DIR/.git/FETCH_HEAD"
[[ -z "$HOMEBREW_UPDATE_FORCE" ]] && [[ "$UPSTREAM_SHA_HTTP_CODE" = "304" ]] && exit