| 
									
										
										
										
											2024-07-14 16:18:26 -04:00
										 |  |  | # Documentation defined in Library/Homebrew/cmd/--version.rb | 
					
						
							| 
									
										
										
										
											2021-03-03 10:22:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-28 20:47:24 +09:00
										 |  |  | # HOMEBREW_CORE_REPOSITORY, HOMEBREW_CASK_REPOSITORY, HOMEBREW_VERSION are set by brew.sh | 
					
						
							|  |  |  | # shellcheck disable=SC2154 | 
					
						
							| 
									
										
										
										
											2021-03-03 10:22:54 +00:00
										 |  |  | version_string() { | 
					
						
							|  |  |  |   local repo="$1" | 
					
						
							| 
									
										
										
										
											2021-09-13 20:32:20 +08:00
										 |  |  |   if ! [[ -d "${repo}" ]] | 
					
						
							|  |  |  |   then | 
					
						
							| 
									
										
										
										
											2021-03-03 10:22:54 +00:00
										 |  |  |     echo "N/A" | 
					
						
							|  |  |  |     return | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local pretty_revision | 
					
						
							| 
									
										
										
										
											2021-04-28 20:47:24 +09:00
										 |  |  |   pretty_revision="$(git -C "${repo}" rev-parse --short --verify --quiet HEAD)" | 
					
						
							| 
									
										
										
										
											2021-09-13 20:32:20 +08:00
										 |  |  |   if [[ -z "${pretty_revision}" ]] | 
					
						
							|  |  |  |   then | 
					
						
							| 
									
										
										
										
											2021-03-03 10:22:54 +00:00
										 |  |  |     echo "(no Git repository)" | 
					
						
							|  |  |  |     return | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local git_last_commit_date | 
					
						
							| 
									
										
										
										
											2021-09-13 20:32:20 +08:00
										 |  |  |   git_last_commit_date="$(git -C "${repo}" show -s --format='%cd' --date=short HEAD)" | 
					
						
							| 
									
										
										
										
											2021-03-03 10:22:54 +00:00
										 |  |  |   echo "(git revision ${pretty_revision}; last commit ${git_last_commit_date})" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | homebrew-version() { | 
					
						
							| 
									
										
										
										
											2021-04-28 20:47:24 +09:00
										 |  |  |   echo "Homebrew ${HOMEBREW_VERSION}" | 
					
						
							| 
									
										
										
										
											2023-02-17 13:39:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if [[ -n "${HOMEBREW_NO_INSTALL_FROM_API}" || -d "${HOMEBREW_CORE_REPOSITORY}" ]] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     echo "Homebrew/homebrew-core $(version_string "${HOMEBREW_CORE_REPOSITORY}")" | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2021-03-03 10:22:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-13 20:32:20 +08:00
										 |  |  |   if [[ -d "${HOMEBREW_CASK_REPOSITORY}" ]] | 
					
						
							|  |  |  |   then | 
					
						
							| 
									
										
										
										
											2021-04-28 20:47:24 +09:00
										 |  |  |     echo "Homebrew/homebrew-cask $(version_string "${HOMEBREW_CASK_REPOSITORY}")" | 
					
						
							| 
									
										
										
										
											2021-03-03 10:22:54 +00:00
										 |  |  |   fi | 
					
						
							|  |  |  | } |