| 
									
										
										
										
											2016-08-17 01:19:40 +02:00
										 |  |  | #:  * `update` [`--merge`] [`--force`]: | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #:    Fetch the newest version of Homebrew and all formulae from GitHub using | 
					
						
							| 
									
										
										
										
											2017-01-29 17:30:44 +00:00
										 |  |  | #:    `git`(1) and perform any necessary migrations. | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #: | 
					
						
							| 
									
										
										
										
											2016-04-22 10:06:59 +01:00
										 |  |  | #:    If `--merge` is specified then `git merge` is used to include updates | 
					
						
							| 
									
										
										
										
											2016-08-17 01:19:40 +02:00
										 |  |  | #:    (rather than `git rebase`). | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2017-04-02 10:14:21 +01:00
										 |  |  | #:    If `--force` (or `-f`) is specified then always do a slower, full update check even | 
					
						
							| 
									
										
										
										
											2016-08-17 01:19:40 +02:00
										 |  |  | #:    if unnecessary. | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-13 14:41:29 +08:00
										 |  |  | # Hide shellcheck complaint: | 
					
						
							|  |  |  | # shellcheck source=/dev/null | 
					
						
							| 
									
										
										
										
											2016-05-10 20:16:25 +08:00
										 |  |  | source "$HOMEBREW_LIBRARY/Homebrew/utils/lock.sh" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-15 19:33:30 +01:00
										 |  |  | # Replaces the function in Library/Homebrew/brew.sh to cache the Git executable to | 
					
						
							| 
									
										
										
										
											2016-07-07 10:24:37 +01:00
										 |  |  | # provide speedup when using Git repeatedly (as update.sh does). | 
					
						
							|  |  |  | git() { | 
					
						
							|  |  |  |   if [[ -z "$GIT_EXECUTABLE" ]] | 
					
						
							|  |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-08-24 14:49:31 +01:00
										 |  |  |     GIT_EXECUTABLE="$("$HOMEBREW_LIBRARY/Homebrew/shims/scm/git" --homebrew=print-path)" | 
					
						
							| 
									
										
										
										
											2016-07-07 10:24:37 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  |   "$GIT_EXECUTABLE" "$@" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | git_init_if_necessary() { | 
					
						
							| 
									
										
										
										
											2017-04-25 09:13:36 +01:00
										 |  |  |   if [[ -n "$HOMEBREW_MACOS" ]] || [[ -n "$HOMEBREW_FORCE_HOMEBREW_ORG" ]] | 
					
						
							| 
									
										
										
										
											2016-04-03 18:34:17 +08:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-07-14 15:39:05 +08:00
										 |  |  |     BREW_OFFICIAL_REMOTE="https://github.com/Homebrew/brew" | 
					
						
							|  |  |  |     CORE_OFFICIAL_REMOTE="https://github.com/Homebrew/homebrew-core" | 
					
						
							| 
									
										
										
										
											2016-07-14 15:41:09 +08:00
										 |  |  |   elif [[ -n "$HOMEBREW_LINUX" ]] | 
					
						
							|  |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-07-14 15:39:05 +08:00
										 |  |  |     BREW_OFFICIAL_REMOTE="https://github.com/Linuxbrew/brew" | 
					
						
							|  |  |  |     CORE_OFFICIAL_REMOTE="https://github.com/Linuxbrew/homebrew-core" | 
					
						
							| 
									
										
										
										
											2016-04-03 18:34:17 +08:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-14 15:39:05 +08:00
										 |  |  |   safe_cd "$HOMEBREW_REPOSITORY" | 
					
						
							| 
									
										
										
										
											2016-01-20 19:51:48 +08:00
										 |  |  |   if [[ ! -d ".git" ]] | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-03-09 17:09:38 +08:00
										 |  |  |     set -e | 
					
						
							|  |  |  |     trap '{ rm -rf .git; exit 1; }' EXIT | 
					
						
							| 
									
										
										
										
											2016-01-28 19:32:41 +08:00
										 |  |  |     git init | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     git config --bool core.autocrlf false | 
					
						
							| 
									
										
										
										
											2016-07-14 15:39:05 +08:00
										 |  |  |     git config remote.origin.url "$BREW_OFFICIAL_REMOTE" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" | 
					
						
							| 
									
										
										
										
											2016-03-09 17:09:38 +08:00
										 |  |  |     git fetch --force --depth=1 origin refs/heads/master:refs/remotes/origin/master | 
					
						
							| 
									
										
										
										
											2016-01-28 17:11:35 +08:00
										 |  |  |     git reset --hard origin/master | 
					
						
							| 
									
										
										
										
											2016-07-14 15:39:05 +08:00
										 |  |  |     SKIP_FETCH_BREW_REPOSITORY=1 | 
					
						
							|  |  |  |     set +e | 
					
						
							|  |  |  |     trap - EXIT | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] || return | 
					
						
							|  |  |  |   safe_cd "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" | 
					
						
							|  |  |  |   if [[ ! -d ".git" ]] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     set -e | 
					
						
							|  |  |  |     trap '{ rm -rf .git; exit 1; }' EXIT | 
					
						
							|  |  |  |     git init | 
					
						
							|  |  |  |     git config --bool core.autocrlf false | 
					
						
							|  |  |  |     git config remote.origin.url "$CORE_OFFICIAL_REMOTE" | 
					
						
							|  |  |  |     git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" | 
					
						
							|  |  |  |     git fetch --force --depth=1 origin refs/heads/master:refs/remotes/origin/master | 
					
						
							|  |  |  |     git reset --hard origin/master | 
					
						
							|  |  |  |     SKIP_FETCH_CORE_REPOSITORY=1 | 
					
						
							| 
									
										
										
										
											2016-03-09 17:09:38 +08:00
										 |  |  |     set +e | 
					
						
							|  |  |  |     trap - EXIT | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-20 21:41:48 +08:00
										 |  |  | rename_taps_dir_if_necessary() { | 
					
						
							|  |  |  |   local tap_dir | 
					
						
							| 
									
										
										
										
											2016-01-21 18:44:32 +08:00
										 |  |  |   local tap_dir_basename | 
					
						
							| 
									
										
										
										
											2016-05-09 20:57:40 +02:00
										 |  |  |   local tap_dir_hyphens | 
					
						
							| 
									
										
										
										
											2016-01-21 18:44:32 +08:00
										 |  |  |   local user | 
					
						
							|  |  |  |   local repo | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-20 21:41:48 +08:00
										 |  |  |   for tap_dir in "$HOMEBREW_LIBRARY"/Taps/* | 
					
						
							|  |  |  |   do | 
					
						
							|  |  |  |     [[ -d "$tap_dir/.git" ]] || continue | 
					
						
							|  |  |  |     tap_dir_basename="${tap_dir##*/}" | 
					
						
							|  |  |  |     if [[ "$tap_dir_basename" = *"-"* ]] | 
					
						
							|  |  |  |     then | 
					
						
							|  |  |  |       # only replace the *last* dash: yes, tap filenames suck | 
					
						
							|  |  |  |       user="$(echo "${tap_dir_basename%-*}" | tr "[:upper:]" "[:lower:]")" | 
					
						
							|  |  |  |       repo="$(echo "${tap_dir_basename:${#user}+1}" | tr "[:upper:]" "[:lower:]")" | 
					
						
							|  |  |  |       mkdir -p "$HOMEBREW_LIBRARY/Taps/$user" | 
					
						
							| 
									
										
										
										
											2016-05-09 20:55:59 +02:00
										 |  |  |       mv "$tap_dir" "$HOMEBREW_LIBRARY/Taps/$user/homebrew-$repo" | 
					
						
							| 
									
										
										
										
											2016-01-20 21:41:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 20:57:40 +02:00
										 |  |  |       tap_dir_hyphens="${tap_dir_basename//[^\-]}" | 
					
						
							|  |  |  |       if [[ ${#tap_dir_hyphens} -gt 1 ]] | 
					
						
							| 
									
										
										
										
											2016-01-20 21:41:48 +08:00
										 |  |  |       then | 
					
						
							|  |  |  |         echo "Homebrew changed the structure of Taps like <someuser>/<sometap>." >&2 | 
					
						
							|  |  |  |         echo "So you may need to rename $HOMEBREW_LIBRARY/Taps/$user/homebrew-$repo manually." >&2 | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       echo "Homebrew changed the structure of Taps like <someuser>/<sometap>. " >&2 | 
					
						
							|  |  |  |       echo "$tap_dir is an incorrect Tap path." >&2 | 
					
						
							|  |  |  |       echo "So you may need to rename it to $HOMEBREW_LIBRARY/Taps/<someuser>/homebrew-<sometap> manually." >&2 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |   done | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | repo_var() { | 
					
						
							| 
									
										
										
										
											2016-01-21 18:44:32 +08:00
										 |  |  |   local repo_var | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   repo_var="$1" | 
					
						
							| 
									
										
										
										
											2016-01-20 19:41:42 +08:00
										 |  |  |   if [[ "$repo_var" = "$HOMEBREW_REPOSITORY" ]] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     repo_var="" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     repo_var="${repo_var#"$HOMEBREW_LIBRARY/Taps"}" | 
					
						
							|  |  |  |     repo_var="$(echo -n "$repo_var" | tr -C "A-Za-z0-9" "_" | tr "[:lower:]" "[:upper:]")" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  |   echo "$repo_var" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | upstream_branch() { | 
					
						
							|  |  |  |   local upstream_branch | 
					
						
							| 
									
										
										
										
											2016-01-21 18:44:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-20 20:29:47 +08:00
										 |  |  |   upstream_branch="$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null)" | 
					
						
							|  |  |  |   upstream_branch="${upstream_branch#refs/remotes/origin/}" | 
					
						
							| 
									
										
										
										
											2016-01-20 19:51:48 +08:00
										 |  |  |   [[ -z "$upstream_branch" ]] && upstream_branch="master" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   echo "$upstream_branch" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | read_current_revision() { | 
					
						
							|  |  |  |   git rev-parse -q --verify HEAD | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pop_stash() { | 
					
						
							| 
									
										
										
										
											2016-01-20 19:51:48 +08:00
										 |  |  |   [[ -z "$STASHED" ]] && return | 
					
						
							|  |  |  |   if [[ -n "$HOMEBREW_VERBOSE" ]] | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-07-12 19:45:49 +01:00
										 |  |  |     echo "Restoring your stashed changes to $DIR..." | 
					
						
							| 
									
										
										
										
											2016-06-05 06:27:58 -07:00
										 |  |  |     git stash pop | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     git stash pop "${QUIET_ARGS[@]}" 1>/dev/null | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   fi | 
					
						
							|  |  |  |   unset STASHED | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pop_stash_message() { | 
					
						
							| 
									
										
										
										
											2016-01-20 19:51:48 +08:00
										 |  |  |   [[ -z "$STASHED" ]] && return | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   echo "To restore the stashed changes to $DIR run:" | 
					
						
							|  |  |  |   echo "  'cd $DIR && git stash pop'" | 
					
						
							|  |  |  |   unset STASHED | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | reset_on_interrupt() { | 
					
						
							| 
									
										
										
										
											2016-01-20 22:58:45 +08:00
										 |  |  |   if [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" ]] | 
					
						
							|  |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-06-16 10:57:46 +01:00
										 |  |  |     git checkout "$INITIAL_BRANCH" "${QUIET_ARGS[@]}" | 
					
						
							| 
									
										
										
										
											2016-01-20 22:58:45 +08:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [[ -n "$INITIAL_REVISION" ]] | 
					
						
							|  |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-05-03 15:28:00 +01:00
										 |  |  |     git rebase --abort &>/dev/null | 
					
						
							|  |  |  |     git merge --abort &>/dev/null | 
					
						
							| 
									
										
										
										
											2016-01-21 18:53:42 +08:00
										 |  |  |     git reset --hard "$INITIAL_REVISION" "${QUIET_ARGS[@]}" | 
					
						
							| 
									
										
										
										
											2016-01-20 22:58:45 +08:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-08 20:44:18 +01:00
										 |  |  |   if [[ -n "$HOMEBREW_NO_UPDATE_CLEANUP" ]] | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   then | 
					
						
							|  |  |  |     pop_stash | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     pop_stash_message | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2016-01-20 22:58:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   exit 130 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-10 09:33:47 +01:00
										 |  |  | # Used for testing purposes, e.g., for testing formula migration after | 
					
						
							|  |  |  | # renaming it in the currently checked-out branch. To test run | 
					
						
							|  |  |  | # "brew update --simulate-from-current-branch" | 
					
						
							|  |  |  | simulate_from_current_branch() { | 
					
						
							|  |  |  |   local DIR | 
					
						
							|  |  |  |   local TAP_VAR | 
					
						
							|  |  |  |   local UPSTREAM_BRANCH | 
					
						
							|  |  |  |   local CURRENT_REVISION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DIR="$1" | 
					
						
							|  |  |  |   cd "$DIR" || return | 
					
						
							|  |  |  |   TAP_VAR="$2" | 
					
						
							|  |  |  |   UPSTREAM_BRANCH="$3" | 
					
						
							|  |  |  |   CURRENT_REVISION="$4" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   INITIAL_REVISION="$(git rev-parse -q --verify "$UPSTREAM_BRANCH")" | 
					
						
							|  |  |  |   export HOMEBREW_UPDATE_BEFORE"$TAP_VAR"="$INITIAL_REVISION" | 
					
						
							|  |  |  |   export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$CURRENT_REVISION" | 
					
						
							|  |  |  |   if [[ "$INITIAL_REVISION" != "$CURRENT_REVISION" ]] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     HOMEBREW_UPDATED="1" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  |   if ! git merge-base --is-ancestor "$INITIAL_REVISION" "$CURRENT_REVISION" | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     odie "Your $DIR HEAD is not a descendant of $UPSTREAM_BRANCH!" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | merge_or_rebase() { | 
					
						
							| 
									
										
										
										
											2016-07-12 19:45:49 +01:00
										 |  |  |   if [[ -n "$HOMEBREW_VERBOSE" ]] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     echo "Updating $DIR..." | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-21 18:44:32 +08:00
										 |  |  |   local DIR | 
					
						
							|  |  |  |   local TAP_VAR | 
					
						
							| 
									
										
										
										
											2016-08-10 09:33:47 +01:00
										 |  |  |   local UPSTREAM_BRANCH | 
					
						
							| 
									
										
										
										
											2016-01-21 18:44:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   DIR="$1" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   cd "$DIR" || return | 
					
						
							| 
									
										
										
										
											2016-08-10 09:33:47 +01:00
										 |  |  |   TAP_VAR="$2" | 
					
						
							|  |  |  |   UPSTREAM_BRANCH="$3" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   unset STASHED | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-21 14:01:51 +08:00
										 |  |  |   trap reset_on_interrupt SIGINT | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-25 21:53:28 +01:00
										 |  |  |   if [[ "$DIR" = "$HOMEBREW_REPOSITORY" && -n "$HOMEBREW_UPDATE_TO_TAG" ]] | 
					
						
							| 
									
										
										
										
											2016-09-17 19:41:21 +01:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-09-29 09:16:15 +01:00
										 |  |  |     UPSTREAM_TAG="$(git tag --list | | 
					
						
							|  |  |  |                     sort --field-separator=. --key=1,1nr -k 2,2nr -k 3,3nr | | 
					
						
							| 
									
										
										
										
											2016-09-24 20:42:55 +01:00
										 |  |  |                     grep --max-count=1 '^[0-9]*\.[0-9]*\.[0-9]*$')"
 | 
					
						
							| 
									
										
										
										
											2016-09-21 14:32:48 +01:00
										 |  |  |   else | 
					
						
							|  |  |  |     UPSTREAM_TAG="" | 
					
						
							| 
									
										
										
										
											2016-09-17 19:41:21 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [ -n "$UPSTREAM_TAG" ] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     REMOTE_REF="refs/tags/$UPSTREAM_TAG" | 
					
						
							| 
									
										
										
										
											2016-09-24 17:25:15 +01:00
										 |  |  |     UPSTREAM_BRANCH="stable" | 
					
						
							| 
									
										
										
										
											2016-09-17 19:41:21 +01:00
										 |  |  |   else | 
					
						
							|  |  |  |     REMOTE_REF="origin/$UPSTREAM_BRANCH" | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2016-09-17 19:36:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-21 14:01:51 +08:00
										 |  |  |   if [[ -n "$(git status --untracked-files=all --porcelain 2>/dev/null)" ]] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     if [[ -n "$HOMEBREW_VERBOSE" ]] | 
					
						
							|  |  |  |     then | 
					
						
							| 
									
										
										
										
											2016-07-12 19:45:49 +01:00
										 |  |  |       echo "Stashing uncommitted changes to $DIR..." | 
					
						
							| 
									
										
										
										
											2016-01-21 14:01:51 +08:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2016-02-18 10:38:30 +00:00
										 |  |  |     git merge --abort &>/dev/null | 
					
						
							| 
									
										
										
										
											2016-05-03 15:28:00 +01:00
										 |  |  |     git rebase --abort &>/dev/null | 
					
						
							| 
									
										
										
										
											2016-08-25 11:40:18 +01:00
										 |  |  |     git reset --mixed "${QUIET_ARGS[@]}" | 
					
						
							|  |  |  |     if ! git -c "user.email=brew-update@localhost" \
 | 
					
						
							|  |  |  |              -c "user.name=brew update" \
 | 
					
						
							|  |  |  |              stash save --include-untracked "${QUIET_ARGS[@]}" | 
					
						
							|  |  |  |     then | 
					
						
							|  |  |  |       odie <<EOS | 
					
						
							| 
									
										
										
										
											2016-09-24 20:42:55 +01:00
										 |  |  | Could not 'git stash' in $DIR! | 
					
						
							| 
									
										
										
										
											2016-08-25 11:40:18 +01:00
										 |  |  | Please stash/commit manually if you need to keep your changes or, if not, run: | 
					
						
							|  |  |  |   cd $DIR | 
					
						
							|  |  |  |   git reset --hard origin/master | 
					
						
							|  |  |  | EOS | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2016-01-21 18:53:42 +08:00
										 |  |  |     git reset --hard "${QUIET_ARGS[@]}" | 
					
						
							| 
									
										
										
										
											2016-01-21 14:01:51 +08:00
										 |  |  |     STASHED="1" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-10 09:33:47 +01:00
										 |  |  |   INITIAL_BRANCH="$(git symbolic-ref --short HEAD 2>/dev/null)" | 
					
						
							| 
									
										
										
										
											2016-09-21 14:32:48 +01:00
										 |  |  |   if [[ -n "$UPSTREAM_TAG" ]] || | 
					
						
							|  |  |  |      [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" ]] | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-03-09 17:35:03 +08:00
										 |  |  |     # Recreate and check out `#{upstream_branch}` if unable to fast-forward | 
					
						
							|  |  |  |     # it to `origin/#{@upstream_branch}`. Otherwise, just check it out. | 
					
						
							| 
									
										
										
										
											2016-09-21 14:32:48 +01:00
										 |  |  |     if [[ -z "$UPSTREAM_TAG" ]] && | 
					
						
							|  |  |  |        git merge-base --is-ancestor "$UPSTREAM_BRANCH" "$REMOTE_REF" &>/dev/null | 
					
						
							| 
									
										
										
										
											2016-03-09 17:35:03 +08:00
										 |  |  |     then | 
					
						
							|  |  |  |       git checkout --force "$UPSTREAM_BRANCH" "${QUIET_ARGS[@]}" | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2016-09-17 19:36:53 +01:00
										 |  |  |       git checkout --force -B "$UPSTREAM_BRANCH" "$REMOTE_REF" "${QUIET_ARGS[@]}" | 
					
						
							| 
									
										
										
										
											2016-03-09 17:35:03 +08:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   INITIAL_REVISION="$(read_current_revision)" | 
					
						
							| 
									
										
										
										
											2016-01-21 13:58:54 +08:00
										 |  |  |   export HOMEBREW_UPDATE_BEFORE"$TAP_VAR"="$INITIAL_REVISION" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   # ensure we don't munge line endings on checkout | 
					
						
							|  |  |  |   git config core.autocrlf false | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-22 10:06:59 +01:00
										 |  |  |   if [[ -z "$HOMEBREW_MERGE" ]] | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-09-17 19:36:53 +01:00
										 |  |  |     git rebase "${QUIET_ARGS[@]}" "$REMOTE_REF" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2016-09-17 19:36:53 +01:00
										 |  |  |     git merge --no-edit --ff "${QUIET_ARGS[@]}" "$REMOTE_REF" \
 | 
					
						
							| 
									
										
										
										
											2016-02-18 10:38:30 +00:00
										 |  |  |       --strategy=recursive \
 | 
					
						
							|  |  |  |       --strategy-option=ours \
 | 
					
						
							|  |  |  |       --strategy-option=ignore-all-space | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:24:41 +01:00
										 |  |  |   CURRENT_REVISION="$(read_current_revision)" | 
					
						
							|  |  |  |   export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$CURRENT_REVISION" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [[ "$INITIAL_REVISION" != "$CURRENT_REVISION" ]] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     HOMEBREW_UPDATED="1" | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-20 22:58:45 +08:00
										 |  |  |   trap '' SIGINT | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-08 20:44:18 +01:00
										 |  |  |   if [[ -n "$HOMEBREW_NO_UPDATE_CLEANUP" ]] | 
					
						
							| 
									
										
										
										
											2016-04-11 09:31:50 +01:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-09-24 05:45:21 -04:00
										 |  |  |     if [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" && | 
					
						
							| 
									
										
										
										
											2016-09-26 08:22:55 +01:00
										 |  |  |           ! "$INITIAL_BRANCH" =~ ^v[0-9]+\.[0-9]+\.[0-9]|stable$ ]] | 
					
						
							| 
									
										
										
										
											2016-06-03 14:12:36 +01:00
										 |  |  |     then | 
					
						
							| 
									
										
										
										
											2016-06-16 10:57:46 +01:00
										 |  |  |       git checkout "$INITIAL_BRANCH" "${QUIET_ARGS[@]}" | 
					
						
							| 
									
										
										
										
											2016-06-03 14:12:36 +01:00
										 |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-11 09:31:50 +01:00
										 |  |  |     pop_stash | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     pop_stash_message | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2016-01-20 22:58:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   trap - SIGINT | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-12 13:25:37 +00:00
										 |  |  | homebrew-update() { | 
					
						
							| 
									
										
										
										
											2016-01-21 18:44:32 +08:00
										 |  |  |   local option | 
					
						
							|  |  |  |   local DIR | 
					
						
							|  |  |  |   local UPSTREAM_BRANCH | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for option in "$@" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   do | 
					
						
							| 
									
										
										
										
											2016-01-21 18:44:32 +08:00
										 |  |  |     case "$option" in | 
					
						
							| 
									
										
										
										
											2016-08-07 12:51:12 +02:00
										 |  |  |       -\?|-h|--help|--usage)          brew help update; exit $? ;; | 
					
						
							|  |  |  |       --verbose)                      HOMEBREW_VERBOSE=1 ;; | 
					
						
							|  |  |  |       --debug)                        HOMEBREW_DEBUG=1 ;; | 
					
						
							|  |  |  |       --merge)                        HOMEBREW_MERGE=1 ;; | 
					
						
							| 
									
										
										
										
											2016-08-12 14:22:00 +01:00
										 |  |  |       --force)                        HOMEBREW_UPDATE_FORCE=1 ;; | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |       --simulate-from-current-branch) HOMEBREW_SIMULATE_FROM_CURRENT_BRANCH=1 ;; | 
					
						
							| 
									
										
										
										
											2016-08-07 12:51:12 +02:00
										 |  |  |       --preinstall)                   export HOMEBREW_UPDATE_PREINSTALL=1 ;; | 
					
						
							|  |  |  |       --*)                            ;; | 
					
						
							| 
									
										
										
										
											2016-01-21 18:36:05 +08:00
										 |  |  |       -*) | 
					
						
							| 
									
										
										
										
											2016-08-07 12:51:12 +02:00
										 |  |  |         [[ "$option" = *v* ]] && HOMEBREW_VERBOSE=1 | 
					
						
							|  |  |  |         [[ "$option" = *d* ]] && HOMEBREW_DEBUG=1 | 
					
						
							| 
									
										
										
										
											2016-01-21 18:36:05 +08:00
										 |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |       *) | 
					
						
							| 
									
										
										
										
											2016-08-07 12:51:12 +02:00
										 |  |  |         odie <<EOS | 
					
						
							| 
									
										
										
										
											2016-01-20 20:26:28 +08:00
										 |  |  | This command updates brew itself, and does not take formula names. | 
					
						
							| 
									
										
										
										
											2017-07-05 21:49:27 +03:00
										 |  |  | Use 'brew upgrade $@' instead. | 
					
						
							| 
									
										
										
										
											2016-01-20 20:26:28 +08:00
										 |  |  | EOS | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |         ;; | 
					
						
							|  |  |  |     esac | 
					
						
							|  |  |  |   done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-20 19:51:48 +08:00
										 |  |  |   if [[ -n "$HOMEBREW_DEBUG" ]] | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   then | 
					
						
							|  |  |  |     set -x | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-18 19:59:56 +01:00
										 |  |  |   if [[ -z "$HOMEBREW_UPDATE_CLEANUP" && -z "$HOMEBREW_UPDATE_TO_TAG" ]] | 
					
						
							| 
									
										
										
										
											2016-09-08 20:44:18 +01:00
										 |  |  |   then | 
					
						
							|  |  |  |     if [[ -n "$HOMEBREW_DEVELOPER" || -n "$HOMEBREW_DEV_CMD_RUN" ]] | 
					
						
							|  |  |  |     then | 
					
						
							|  |  |  |       export HOMEBREW_NO_UPDATE_CLEANUP="1" | 
					
						
							| 
									
										
										
										
											2016-09-25 21:53:28 +01:00
										 |  |  |     else | 
					
						
							|  |  |  |       export HOMEBREW_UPDATE_TO_TAG="1" | 
					
						
							| 
									
										
										
										
											2016-09-08 20:44:18 +01:00
										 |  |  |     fi | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-10 14:18:39 +01:00
										 |  |  |   if [[ -z "$HOMEBREW_AUTO_UPDATE_SECS" ]] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     HOMEBREW_AUTO_UPDATE_SECS="60" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   # check permissions | 
					
						
							| 
									
										
										
										
											2016-09-09 08:06:37 +01:00
										 |  |  |   if [[ -e "$HOMEBREW_CELLAR" && ! -w "$HOMEBREW_CELLAR" ]] | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-08-07 12:51:12 +02:00
										 |  |  |     odie <<EOS | 
					
						
							| 
									
										
										
										
											2016-09-09 08:06:37 +01:00
										 |  |  | $HOMEBREW_CELLAR is not writable. You should change the | 
					
						
							|  |  |  | ownership and permissions of $HOMEBREW_CELLAR back to your | 
					
						
							|  |  |  | user account: | 
					
						
							|  |  |  |   sudo chown -R \$(whoami) $HOMEBREW_CELLAR | 
					
						
							| 
									
										
										
										
											2016-07-10 01:30:29 +01:00
										 |  |  | EOS | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-20 19:51:48 +08:00
										 |  |  |   if [[ ! -w "$HOMEBREW_REPOSITORY" ]] | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-08-07 12:51:12 +02:00
										 |  |  |     odie <<EOS | 
					
						
							| 
									
										
										
										
											2016-07-10 01:30:29 +01:00
										 |  |  | $HOMEBREW_REPOSITORY is not writable. You should change the | 
					
						
							|  |  |  | ownership and permissions of $HOMEBREW_REPOSITORY back to your | 
					
						
							|  |  |  | user account: | 
					
						
							|  |  |  |   sudo chown -R \$(whoami) $HOMEBREW_REPOSITORY | 
					
						
							|  |  |  | EOS | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-15 17:39:32 +08:00
										 |  |  |   if ! git --version >/dev/null 2>&1 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2017-09-16 12:41:08 +01:00
										 |  |  |     # we need a new enough curl to install git | 
					
						
							|  |  |  |     if [[ -n "$HOMEBREW_SYSTEM_CURL_TOO_OLD" && | 
					
						
							|  |  |  |         ! -x "$HOMEBREW_PREFIX/opt/curl/bin/curl" ]] | 
					
						
							|  |  |  |     then | 
					
						
							|  |  |  |       brew install curl | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2016-04-02 18:41:44 +08:00
										 |  |  |     # we cannot install brewed git if homebrew/core is unavailable. | 
					
						
							|  |  |  |     [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] && brew install git | 
					
						
							| 
									
										
										
										
											2016-07-07 10:24:37 +01:00
										 |  |  |     unset GIT_EXECUTABLE | 
					
						
							| 
									
										
										
										
											2016-03-15 17:39:32 +08:00
										 |  |  |     if ! git --version >/dev/null 2>&1 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     then | 
					
						
							| 
									
										
										
										
											2016-01-20 20:26:28 +08:00
										 |  |  |       odie "Git must be installed and in your PATH!" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     fi | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2016-02-12 12:54:47 +00:00
										 |  |  |   export GIT_TERMINAL_PROMPT="0" | 
					
						
							|  |  |  |   export GIT_SSH_COMMAND="ssh -oBatchMode=yes" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-20 19:51:48 +08:00
										 |  |  |   if [[ -z "$HOMEBREW_VERBOSE" ]] | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-01-21 18:53:42 +08:00
										 |  |  |     QUIET_ARGS=(-q) | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     QUIET_ARGS=() | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # ensure GIT_CONFIG is unset as we need to operate on .git/config | 
					
						
							|  |  |  |   unset GIT_CONFIG | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-10 20:16:25 +08:00
										 |  |  |   # only allow one instance of brew update | 
					
						
							|  |  |  |   lock update | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   git_init_if_necessary | 
					
						
							| 
									
										
										
										
											2016-01-20 21:41:48 +08:00
										 |  |  |   # rename Taps directories | 
					
						
							|  |  |  |   # this procedure will be removed in the future if it seems unnecessary | 
					
						
							|  |  |  |   rename_taps_dir_if_necessary | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-14 15:39:05 +08:00
										 |  |  |   safe_cd "$HOMEBREW_REPOSITORY" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-21 13:32:22 +08:00
										 |  |  |   # kill all of subprocess on interrupt | 
					
						
							| 
									
										
										
										
											2016-12-01 20:59:41 +01:00
										 |  |  |   trap '{ /usr/bin/pkill -P $$; wait; exit 130; }' SIGINT | 
					
						
							| 
									
										
										
										
											2016-01-21 13:32:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:24:41 +01:00
										 |  |  |   local update_failed_file="$HOMEBREW_REPOSITORY/.git/UPDATE_FAILED" | 
					
						
							|  |  |  |   rm -f "$update_failed_file" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/* | 
					
						
							|  |  |  |   do | 
					
						
							| 
									
										
										
										
											2016-01-20 19:51:48 +08:00
										 |  |  |     [[ -d "$DIR/.git" ]] || continue | 
					
						
							| 
									
										
										
										
											2016-08-10 09:33:47 +01:00
										 |  |  |     cd "$DIR" || continue | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 10:57:08 +01:00
										 |  |  |     if [[ -n "$HOMEBREW_VERBOSE" ]] | 
					
						
							|  |  |  |     then | 
					
						
							|  |  |  |       echo "Checking if we need to fetch $DIR..." | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-10 09:33:47 +01:00
										 |  |  |     TAP_VAR="$(repo_var "$DIR")" | 
					
						
							| 
									
										
										
										
											2016-08-11 17:22:27 +01:00
										 |  |  |     UPSTREAM_BRANCH_DIR="$(upstream_branch)" | 
					
						
							|  |  |  |     declare UPSTREAM_BRANCH"$TAP_VAR"="$UPSTREAM_BRANCH_DIR" | 
					
						
							|  |  |  |     declare PREFETCH_REVISION"$TAP_VAR"="$(git rev-parse -q --verify refs/remotes/origin/"$UPSTREAM_BRANCH_DIR")" | 
					
						
							| 
									
										
										
										
											2016-08-10 09:33:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-20 17:15:43 +01:00
										 |  |  |     # 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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 14:22:00 +01:00
										 |  |  |     if [[ -z "$HOMEBREW_UPDATE_FORCE" ]] | 
					
						
							|  |  |  |     then | 
					
						
							|  |  |  |       [[ -n "$SKIP_FETCH_BREW_REPOSITORY" && "$DIR" = "$HOMEBREW_REPOSITORY" ]] && continue | 
					
						
							|  |  |  |       [[ -n "$SKIP_FETCH_CORE_REPOSITORY" && "$DIR" = "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] && continue | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2016-08-10 09:33:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # The upstream repository's default branch may not be master; | 
					
						
							|  |  |  |     # check refs/remotes/origin/HEAD to see what the default | 
					
						
							|  |  |  |     # origin branch name is, and use that. If not set, fall back to "master". | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     # the refspec ensures that the default upstream branch gets updated | 
					
						
							| 
									
										
										
										
											2016-02-12 13:09:13 +00:00
										 |  |  |     ( | 
					
						
							| 
									
										
										
										
											2016-07-07 10:24:37 +01:00
										 |  |  |       if [[ -n "$HOMEBREW_UPDATE_PREINSTALL" ]] | 
					
						
							|  |  |  |       then | 
					
						
							| 
									
										
										
										
											2016-08-09 09:19:51 +01:00
										 |  |  |         # Skip taps checked/fetched recently | 
					
						
							| 
									
										
										
										
											2016-08-10 14:18:39 +01:00
										 |  |  |         [[ -n "$(find "$DIR/.git/FETCH_HEAD" -type f -mtime -"${HOMEBREW_AUTO_UPDATE_SECS}"s 2>/dev/null)" ]] && exit | 
					
						
							| 
									
										
										
										
											2016-07-07 10:24:37 +01:00
										 |  |  |       fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-18 10:41:09 +00:00
										 |  |  |       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}" | 
					
						
							| 
									
										
										
										
											2016-09-24 20:42:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-25 21:53:28 +01:00
										 |  |  |         if [[ "$DIR" = "$HOMEBREW_REPOSITORY" && -n "$HOMEBREW_UPDATE_TO_TAG" ]] | 
					
						
							| 
									
										
										
										
											2016-09-24 20:42:55 +01:00
										 |  |  |         then | 
					
						
							|  |  |  |           # Only try to `git fetch` when the upstream tags have changed | 
					
						
							|  |  |  |           # (so the API does not return 304: unmodified). | 
					
						
							| 
									
										
										
										
											2016-09-27 13:54:49 +01:00
										 |  |  |           GITHUB_API_ETAG="$(sed -n 's/^ETag: "\([a-f0-9]\{32\}\)".*/\1/p' ".git/GITHUB_HEADERS" 2>/dev/null)" | 
					
						
							| 
									
										
										
										
											2016-09-24 20:42:55 +01:00
										 |  |  |           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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-07 12:51:12 +02:00
										 |  |  |         UPSTREAM_SHA_HTTP_CODE="$("$HOMEBREW_CURL" --silent --max-time 3 \
 | 
					
						
							| 
									
										
										
										
											2016-02-18 10:41:09 +00:00
										 |  |  |            --output /dev/null --write-out "%{http_code}" \
 | 
					
						
							| 
									
										
										
										
											2016-09-24 20:42:55 +01:00
										 |  |  |            --dump-header "$DIR/.git/GITHUB_HEADERS" \
 | 
					
						
							| 
									
										
										
										
											2016-04-04 11:46:33 +01:00
										 |  |  |            --user-agent "$HOMEBREW_USER_AGENT_CURL" \
 | 
					
						
							| 
									
										
										
										
											2016-09-24 20:42:55 +01:00
										 |  |  |            --header "Accept: $GITHUB_API_ACCEPT" \
 | 
					
						
							|  |  |  |            --header "If-None-Match: \"$GITHUB_API_ETAG\"" \
 | 
					
						
							|  |  |  |            "https://api.github.com/repos/$UPSTREAM_REPOSITORY/$GITHUB_API_ENDPOINT")"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:19:51 +01:00
										 |  |  |         # Touch FETCH_HEAD to confirm we've checked for an update. | 
					
						
							|  |  |  |         [[ -f "$DIR/.git/FETCH_HEAD" ]] && touch "$DIR/.git/FETCH_HEAD" | 
					
						
							| 
									
										
										
										
											2016-08-12 14:22:00 +01:00
										 |  |  |         [[ -z "$HOMEBREW_UPDATE_FORCE" ]] && [[ "$UPSTREAM_SHA_HTTP_CODE" = "304" ]] && exit | 
					
						
							| 
									
										
										
										
											2016-04-11 09:31:50 +01:00
										 |  |  |       elif [[ -n "$HOMEBREW_UPDATE_PREINSTALL" ]] | 
					
						
							|  |  |  |       then | 
					
						
							|  |  |  |         # Don't try to do a `git fetch` that may take longer than expected. | 
					
						
							|  |  |  |         exit | 
					
						
							| 
									
										
										
										
											2016-02-18 10:41:09 +00:00
										 |  |  |       fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-07 10:24:37 +01:00
										 |  |  |       if [[ -n "$HOMEBREW_VERBOSE" ]] | 
					
						
							|  |  |  |       then | 
					
						
							|  |  |  |         echo "Fetching $DIR..." | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-11 09:31:50 +01:00
										 |  |  |       if [[ -n "$HOMEBREW_UPDATE_PREINSTALL" ]] | 
					
						
							|  |  |  |       then | 
					
						
							| 
									
										
										
										
											2016-09-17 19:35:07 +01:00
										 |  |  |         git fetch --tags --force "${QUIET_ARGS[@]}" origin \
 | 
					
						
							| 
									
										
										
										
											2016-08-11 17:22:27 +01:00
										 |  |  |           "refs/heads/$UPSTREAM_BRANCH_DIR:refs/remotes/origin/$UPSTREAM_BRANCH_DIR" 2>/dev/null | 
					
						
							| 
									
										
										
										
											2016-04-11 09:31:50 +01:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2016-09-17 19:35:07 +01:00
										 |  |  |         if ! git fetch --tags --force "${QUIET_ARGS[@]}" origin \
 | 
					
						
							| 
									
										
										
										
											2016-08-11 17:22:27 +01:00
										 |  |  |           "refs/heads/$UPSTREAM_BRANCH_DIR:refs/remotes/origin/$UPSTREAM_BRANCH_DIR" | 
					
						
							| 
									
										
										
										
											2016-05-03 14:24:41 +01:00
										 |  |  |         then | 
					
						
							| 
									
										
										
										
											2016-08-07 12:51:12 +02:00
										 |  |  |           echo "Fetching $DIR failed!" >>"$update_failed_file" | 
					
						
							| 
									
										
										
										
											2016-05-03 14:24:41 +01:00
										 |  |  |         fi | 
					
						
							| 
									
										
										
										
											2016-04-11 09:31:50 +01:00
										 |  |  |       fi | 
					
						
							| 
									
										
										
										
											2016-02-12 13:09:13 +00:00
										 |  |  |     ) & | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   wait | 
					
						
							| 
									
										
										
										
											2016-01-21 13:32:22 +08:00
										 |  |  |   trap - SIGINT | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:24:41 +01:00
										 |  |  |   if [[ -f "$update_failed_file" ]] | 
					
						
							|  |  |  |   then | 
					
						
							| 
									
										
										
										
											2016-08-07 12:51:12 +02:00
										 |  |  |     onoe <"$update_failed_file" | 
					
						
							| 
									
										
										
										
											2016-05-03 14:24:41 +01:00
										 |  |  |     rm -f "$update_failed_file" | 
					
						
							|  |  |  |     export HOMEBREW_UPDATE_FAILED="1" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/* | 
					
						
							|  |  |  |   do | 
					
						
							| 
									
										
										
										
											2016-01-20 19:51:48 +08:00
										 |  |  |     [[ -d "$DIR/.git" ]] || continue | 
					
						
							| 
									
										
										
										
											2016-08-10 09:33:47 +01:00
										 |  |  |     cd "$DIR" || continue | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     TAP_VAR="$(repo_var "$DIR")" | 
					
						
							|  |  |  |     UPSTREAM_BRANCH_VAR="UPSTREAM_BRANCH$TAP_VAR" | 
					
						
							|  |  |  |     UPSTREAM_BRANCH="${!UPSTREAM_BRANCH_VAR}" | 
					
						
							|  |  |  |     CURRENT_REVISION="$(read_current_revision)" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     PREFETCH_REVISION_VAR="PREFETCH_REVISION$TAP_VAR" | 
					
						
							|  |  |  |     PREFETCH_REVISION="${!PREFETCH_REVISION_VAR}" | 
					
						
							| 
									
										
										
										
											2016-08-11 13:47:13 +01:00
										 |  |  |     POSTFETCH_REVISION="$(git rev-parse -q --verify refs/remotes/origin/"$UPSTREAM_BRANCH")" | 
					
						
							| 
									
										
										
										
											2016-08-10 09:33:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if [[ -n "$HOMEBREW_SIMULATE_FROM_CURRENT_BRANCH" ]] | 
					
						
							|  |  |  |     then | 
					
						
							|  |  |  |       simulate_from_current_branch "$DIR" "$TAP_VAR" "$UPSTREAM_BRANCH" "$CURRENT_REVISION" | 
					
						
							| 
									
										
										
										
											2016-08-12 14:22:00 +01:00
										 |  |  |     elif [[ -z "$HOMEBREW_UPDATE_FORCE" ]] && | 
					
						
							|  |  |  |          [[ "$PREFETCH_REVISION" = "$POSTFETCH_REVISION" ]] && | 
					
						
							| 
									
										
										
										
											2016-08-11 13:47:13 +01:00
										 |  |  |          [[ "$CURRENT_REVISION" = "$POSTFETCH_REVISION" ]] | 
					
						
							| 
									
										
										
										
											2016-08-10 09:33:47 +01:00
										 |  |  |     then | 
					
						
							|  |  |  |       export HOMEBREW_UPDATE_BEFORE"$TAP_VAR"="$CURRENT_REVISION" | 
					
						
							|  |  |  |       export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$CURRENT_REVISION" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       merge_or_rebase "$DIR" "$TAP_VAR" "$UPSTREAM_BRANCH" | 
					
						
							| 
									
										
										
										
											2016-08-11 10:57:08 +01:00
										 |  |  |       [[ -n "$HOMEBREW_VERBOSE" ]] && echo | 
					
						
							| 
									
										
										
										
											2016-08-10 09:33:47 +01:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-28 21:35:49 +02:00
										 |  |  |   safe_cd "$HOMEBREW_REPOSITORY" | 
					
						
							| 
									
										
										
										
											2016-05-03 14:24:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-12 18:23:50 +02:00
										 |  |  |   if [[ -n "$HOMEBREW_UPDATED" || | 
					
						
							|  |  |  |         -n "$HOMEBREW_UPDATE_FAILED" || | 
					
						
							| 
									
										
										
										
											2016-08-12 14:22:00 +01:00
										 |  |  |         -n "$HOMEBREW_UPDATE_FORCE" || | 
					
						
							| 
									
										
										
										
											2016-09-17 13:25:32 +01:00
										 |  |  |         -d "$HOMEBREW_LIBRARY/LinkedKegs" || | 
					
						
							| 
									
										
										
										
											2016-07-07 10:24:37 +01:00
										 |  |  |         (-n "$HOMEBREW_DEVELOPER" && -z "$HOMEBREW_UPDATE_PREINSTALL") ]] | 
					
						
							| 
									
										
										
										
											2016-05-03 14:24:41 +01:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2017-09-29 19:53:15 +01:00
										 |  |  |     unset HOMEBREW_RUBY_PATH | 
					
						
							| 
									
										
										
										
											2016-05-03 14:24:41 +01:00
										 |  |  |     brew update-report "$@" | 
					
						
							|  |  |  |     return $? | 
					
						
							|  |  |  |   elif [[ -z "$HOMEBREW_UPDATE_PREINSTALL" ]] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     echo "Already up-to-date." | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | } |