| 
									
										
										
										
											2024-07-14 16:18:26 -04:00
										 |  |  | # Documentation defined in Library/Homebrew/cmd/update-reset.rb | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 03:38:40 +01:00
										 |  |  | # Replaces the function in Library/Homebrew/brew.sh to cache the Git executable to provide | 
					
						
							|  |  |  | # speedup when using Git repeatedly and prevent errors if the shim changes mid-update. | 
					
						
							|  |  |  | git() { | 
					
						
							|  |  |  |   if [[ -z "${GIT_EXECUTABLE}" ]] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     # HOMEBREW_LIBRARY is set by bin/brew | 
					
						
							|  |  |  |     # shellcheck disable=SC2154 | 
					
						
							|  |  |  |     GIT_EXECUTABLE="$("${HOMEBREW_LIBRARY}/Homebrew/shims/shared/git" --homebrew=print-path)" | 
					
						
							| 
									
										
										
										
											2023-03-22 18:03:47 +08:00
										 |  |  |     if [[ -z "${GIT_EXECUTABLE}" ]] | 
					
						
							|  |  |  |     then | 
					
						
							|  |  |  |       odie "Can't find a working Git!" | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2021-10-05 03:38:40 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  |   "${GIT_EXECUTABLE}" "$@" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  | homebrew-update-reset() { | 
					
						
							| 
									
										
										
										
											2022-04-25 04:22:12 -07:00
										 |  |  |   local option | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  |   local DIR | 
					
						
							| 
									
										
										
										
											2018-09-18 21:14:21 +01:00
										 |  |  |   local -a REPOS=() | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for option in "$@" | 
					
						
							|  |  |  |   do | 
					
						
							| 
									
										
										
										
											2021-04-24 11:11:09 +05:30
										 |  |  |     case "${option}" in | 
					
						
							| 
									
										
										
										
											2021-09-16 01:08:02 +08:00
										 |  |  |       -\? | -h | --help | --usage) | 
					
						
							|  |  |  |         brew help update-reset | 
					
						
							|  |  |  |         exit $? | 
					
						
							|  |  |  |         ;; | 
					
						
							|  |  |  |       --debug) HOMEBREW_DEBUG=1 ;; | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  |       -*) | 
					
						
							| 
									
										
										
										
											2021-09-13 20:32:20 +08:00
										 |  |  |         [[ "${option}" == *d* ]] && HOMEBREW_DEBUG=1 | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  |         ;; | 
					
						
							|  |  |  |       *) | 
					
						
							| 
									
										
										
										
											2023-02-28 20:38:00 +08:00
										 |  |  |         if [[ -d "${option}/.git" ]] | 
					
						
							|  |  |  |         then | 
					
						
							|  |  |  |           REPOS+=("${option}") | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           onoe "${option} is not a Git repository!" | 
					
						
							|  |  |  |           brew help update-reset | 
					
						
							|  |  |  |           exit 1 | 
					
						
							|  |  |  |         fi | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  |         ;; | 
					
						
							|  |  |  |     esac | 
					
						
							|  |  |  |   done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-24 11:11:09 +05:30
										 |  |  |   if [[ -n "${HOMEBREW_DEBUG}" ]] | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  |   then | 
					
						
							|  |  |  |     set -x | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-08 18:41:46 +01:00
										 |  |  |   if [[ -z "${REPOS[*]}" ]] | 
					
						
							| 
									
										
										
										
											2018-09-18 21:14:21 +01:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2021-04-24 11:11:09 +05:30
										 |  |  |     REPOS+=("${HOMEBREW_REPOSITORY}" "${HOMEBREW_LIBRARY}"/Taps/*/*) | 
					
						
							| 
									
										
										
										
											2018-09-18 21:14:21 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-04 09:31:37 +01:00
										 |  |  |   for DIR in "${REPOS[@]}" | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  |   do | 
					
						
							| 
									
										
										
										
											2021-04-24 11:11:09 +05:30
										 |  |  |     [[ -d "${DIR}/.git" ]] || continue | 
					
						
							| 
									
										
										
										
											2022-04-25 04:22:12 -07:00
										 |  |  |     if ! git -C "${DIR}" config --local --get remote.origin.url &>/dev/null | 
					
						
							|  |  |  |     then | 
					
						
							| 
									
										
										
										
											2022-04-25 09:16:36 -05:00
										 |  |  |       opoo "No remote 'origin' in ${DIR}, skipping update and reset!" | 
					
						
							| 
									
										
										
										
											2022-04-25 04:22:12 -07:00
										 |  |  |       continue | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2022-10-08 21:57:44 +08:00
										 |  |  |     git -C "${DIR}" config --bool core.autocrlf false | 
					
						
							|  |  |  |     git -C "${DIR}" config --bool core.symlinks true | 
					
						
							| 
									
										
										
										
											2021-04-24 11:11:09 +05:30
										 |  |  |     ohai "Fetching ${DIR}..." | 
					
						
							|  |  |  |     git -C "${DIR}" fetch --force --tags origin | 
					
						
							|  |  |  |     git -C "${DIR}" remote set-head origin --auto >/dev/null | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  |     echo | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-24 11:11:09 +05:30
										 |  |  |     ohai "Resetting ${DIR}..." | 
					
						
							| 
									
										
										
										
											2024-03-14 16:41:30 +00:00
										 |  |  |     # HOMEBREW_* variables here may all set by bin/brew or the user | 
					
						
							|  |  |  |     # shellcheck disable=SC2154 | 
					
						
							|  |  |  |     if [[ "${DIR}" == "${HOMEBREW_REPOSITORY}" && | 
					
						
							|  |  |  |        (-n "${HOMEBREW_UPDATE_TO_TAG}" || | 
					
						
							|  |  |  |        (-z "${HOMEBREW_DEVELOPER}" && -z "${HOMEBREW_DEV_CMD_RUN}")) ]] | 
					
						
							|  |  |  |     then | 
					
						
							|  |  |  |       local latest_git_tag | 
					
						
							|  |  |  |       latest_git_tag="$(git -C "${DIR}" tag --list --sort="-version:refname" | head -n1)" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       git -C "${DIR}" checkout --force -B stable "refs/tags/${latest_git_tag}" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       head="$(git -C "${DIR}" symbolic-ref refs/remotes/origin/HEAD)" | 
					
						
							|  |  |  |       head="${head#refs/remotes/origin/}" | 
					
						
							|  |  |  |       git -C "${DIR}" checkout --force -B "${head}" origin/HEAD | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2024-12-03 14:30:14 +00:00
										 |  |  |     rm -rf "${DIR}/.git/describe-cache" | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  |     echo | 
					
						
							|  |  |  |   done | 
					
						
							|  |  |  | } |