Skip to content

Commit

Permalink
Handle missing git on macOS properly
Browse files Browse the repository at this point in the history
We need to ignore the default CLT shim for git and find the _real_ path ourselves to properly skip git fetches before git is available. Otherwise, it _seems_ present, but is actually missing and will pop up the Xcode CLT installer dialog and fail to fetch git resources
  • Loading branch information
maxfierke committed Apr 28, 2024
1 parent dda0e8d commit 14d1429
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mstrap/platform.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module MStrap

# Indicates whether the host platform has Git installed
def self.has_git?
ENV["MSTRAP_IGNORE_GIT"]? != "true" && has_command?("git")
ENV["MSTRAP_IGNORE_GIT"]? != "true" && platform.has_git?
end

# Indicates whether the host platform has a given command available
Expand Down
29 changes: 29 additions & 0 deletions src/mstrap/platform/darwin/macos.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,35 @@ module MStrap
module MacOS
extend DSL

XCODE_CLT_GIT_PATH = "/Library/Developer/CommandLineTools/usr/bin/git"

@@git_path : String = ""

# :nodoc:
def self.has_git?
git_path = @@git_path
return true if git_path != ""

git_path = Process.find_executable("git")

# Ignore the XCode CLT shim trickery!
if git_path && git_path == "/usr/bin/git"
# Try and look it up with xcrun
if has_command?("xcrun")
xcrun_git_path = `xcrun -find git 2>/dev/null`.chomp
git_path = Process.find_executable(xcrun_git_path) if $?.success?
end

# Fallback to default CLT path
git_path ||= Process.find_executable(XCODE_CLT_GIT_PATH)
end

return false if git_path.nil?

@@git_path = git_path
true
end

def self.install_packages!(packages : Array(String))
cmd("brew", ["install"] + packages)
end
Expand Down
4 changes: 4 additions & 0 deletions src/mstrap/platform/linux.cr
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ module MStrap
distro_family == DISTRO_UNKNOWN
end

def has_git?
has_command?("git")
end

# :nodoc:
def platform
if arch_distro?
Expand Down

0 comments on commit 14d1429

Please sign in to comment.