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.
This commit is contained in:
		
							parent
							
								
									232078df57
								
							
						
					
					
						commit
						87cf4f7f7a
					
				@ -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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user