aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/update.sh16
1 files changed, 16 insertions, 0 deletions
diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh
index d9226cfb9..4841c96bd 100644
--- a/Library/Homebrew/cmd/update.sh
+++ b/Library/Homebrew/cmd/update.sh
@@ -334,6 +334,22 @@ EOS
UPSTREAM_BRANCH="$(upstream_branch)"
# the refspec ensures that the default upstream branch gets updated
(
+ UPSTREAM_REPOSITORY_URL="$(git config remote.origin.url)"
+ if [[ "$UPSTREAM_REPOSITORY_URL" = "https://github.com/"* ]]
+ 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")"
+ # Only try to `git fetch` when the upstream branch is at a different SHA
+ # (so the API does not return 304: unmodified).
+ UPSTREAM_SHA_HTTP_CODE="$(curl --silent '--max-time' 3 \
+ --output /dev/null --write-out "%{http_code}" \
+ -H "Accept: application/vnd.github.chitauri-preview+sha" \
+ -H "If-None-Match: \"$UPSTREAM_BRANCH_LOCAL_SHA\"" \
+ "https://api.github.com/repos/$UPSTREAM_REPOSITORY/commits/$UPSTREAM_BRANCH")"
+ [[ "$UPSTREAM_SHA_HTTP_CODE" = "304" ]] && exit
+ fi
+
git fetch "${QUIET_ARGS[@]}" origin \
"refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH" || \
odie "Fetching $DIR failed!"