| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  | #:  * `update-reset` [<repository> ...] | 
					
						
							| 
									
										
										
										
											2019-01-30 21:31:45 +00:00
										 |  |  | #: | 
					
						
							| 
									
										
										
										
											2021-01-28 01:51:40 -05:00
										 |  |  | #:  Fetch and reset Homebrew and all tap repositories (or any specified <repository>) using `git`(1) to their latest `origin/HEAD`. | 
					
						
							| 
									
										
										
										
											2019-08-19 22:44:50 -04:00
										 |  |  | #: | 
					
						
							|  |  |  | #:  *Note:* this will destroy all your uncommitted or committed changes. | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | homebrew-update-reset() { | 
					
						
							|  |  |  |   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 | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  |       -\?|-h|--help|--usage)          brew help update-reset; exit $? ;; | 
					
						
							|  |  |  |       --debug)                        HOMEBREW_DEBUG=1 ;; | 
					
						
							|  |  |  |       -*) | 
					
						
							| 
									
										
										
										
											2021-04-24 11:11:09 +05:30
										 |  |  |         [[ "${option}" = *d* ]] && HOMEBREW_DEBUG=1 | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  |         ;; | 
					
						
							|  |  |  |       *) | 
					
						
							| 
									
										
										
										
											2021-04-24 11:11:09 +05:30
										 |  |  |         REPOS+=("${option}") | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |     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}..." | 
					
						
							|  |  |  |     head="$(git -C "${DIR}" symbolic-ref refs/remotes/origin/HEAD)" | 
					
						
							| 
									
										
										
										
											2020-06-17 17:26:15 -07:00
										 |  |  |     head="${head#refs/remotes/origin/}" | 
					
						
							| 
									
										
										
										
											2021-04-24 11:11:09 +05:30
										 |  |  |     git -C "${DIR}" checkout --force -B "${head}" origin/HEAD | 
					
						
							| 
									
										
										
										
											2016-12-18 15:25:16 -08:00
										 |  |  |     echo | 
					
						
							|  |  |  |   done | 
					
						
							|  |  |  | } |