Skip to content
Snippets Groups Projects
Commit 87cf4f7f authored by Mike McQuaid's avatar Mike McQuaid
Browse files

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.
parent 232078df
No related branches found
No related tags found
No related merge requests found
...@@ -217,7 +217,8 @@ merge_or_rebase() { ...@@ -217,7 +217,8 @@ merge_or_rebase() {
if [[ "$DIR" = "$HOMEBREW_REPOSITORY" && -z "$HOMEBREW_NO_UPDATE_CLEANUP" ]] if [[ "$DIR" = "$HOMEBREW_REPOSITORY" && -z "$HOMEBREW_NO_UPDATE_CLEANUP" ]]
then 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 else
UPSTREAM_TAG="" UPSTREAM_TAG=""
fi fi
...@@ -244,7 +245,7 @@ merge_or_rebase() { ...@@ -244,7 +245,7 @@ merge_or_rebase() {
stash save --include-untracked "${QUIET_ARGS[@]}" stash save --include-untracked "${QUIET_ARGS[@]}"
then then
odie <<EOS 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: Please stash/commit manually if you need to keep your changes or, if not, run:
cd $DIR cd $DIR
git reset --hard origin/master git reset --hard origin/master
...@@ -469,15 +470,30 @@ EOS ...@@ -469,15 +470,30 @@ EOS
then then
UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY_URL#https://github.com/}" UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY_URL#https://github.com/}"
UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY%.git}" 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 if [[ "$DIR" = "$HOMEBREW_REPOSITORY" && -z "$HOMEBREW_NO_UPDATE_CLEANUP" ]]
# (so the API does not return 304: unmodified). 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 \ UPSTREAM_SHA_HTTP_CODE="$("$HOMEBREW_CURL" --silent --max-time 3 \
--output /dev/null --write-out "%{http_code}" \ --output /dev/null --write-out "%{http_code}" \
--dump-header "$DIR/.git/GITHUB_HEADERS" \
--user-agent "$HOMEBREW_USER_AGENT_CURL" \ --user-agent "$HOMEBREW_USER_AGENT_CURL" \
--header "Accept: application/vnd.github.v3.sha" \ --header "Accept: $GITHUB_API_ACCEPT" \
--header "If-None-Match: \"$UPSTREAM_BRANCH_LOCAL_SHA\"" \ --header "If-None-Match: \"$GITHUB_API_ETAG\"" \
"https://api.github.com/repos/$UPSTREAM_REPOSITORY/commits/$UPSTREAM_BRANCH_DIR")" "https://api.github.com/repos/$UPSTREAM_REPOSITORY/$GITHUB_API_ENDPOINT")"
# Touch FETCH_HEAD to confirm we've checked for an update. # Touch FETCH_HEAD to confirm we've checked for an update.
[[ -f "$DIR/.git/FETCH_HEAD" ]] && touch "$DIR/.git/FETCH_HEAD" [[ -f "$DIR/.git/FETCH_HEAD" ]] && touch "$DIR/.git/FETCH_HEAD"
[[ -z "$HOMEBREW_UPDATE_FORCE" ]] && [[ "$UPSTREAM_SHA_HTTP_CODE" = "304" ]] && exit [[ -z "$HOMEBREW_UPDATE_FORCE" ]] && [[ "$UPSTREAM_SHA_HTTP_CODE" = "304" ]] && exit
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment