aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Contributions/cmds/git
diff options
context:
space:
mode:
authorMax Howell2012-08-28 09:50:03 -0400
committerMax Howell2012-08-29 12:41:36 -0400
commit672388d4f71e810d0f742518b5cd4a5aa7de6e04 (patch)
treec9763f6ddbd51ffd7933816c7ed95d0f05a11c9b /Library/Contributions/cmds/git
parent0ac3e83a7abbf0fe06206d4da145f2cd724b2a87 (diff)
downloadbrew-672388d4f71e810d0f742518b5cd4a5aa7de6e04.tar.bz2
Always find git and svn without trying hard
Two wrapper scripts that find git and svn using the ENV variables we support and then searching through the PATH and looking inside Xcode.app if necessary. Now just calling git or svn in Homebrew code will find and exec the right tool and we can stop fussing. Apologies to @adamv who is probably unimpressed that the cmds directory has non-commands in it now. If it's consolation these are temporary pending some more work on superenv whereby some more directories are created under the superenv root.
Diffstat (limited to 'Library/Contributions/cmds/git')
-rwxr-xr-xLibrary/Contributions/cmds/git51
1 files changed, 51 insertions, 0 deletions
diff --git a/Library/Contributions/cmds/git b/Library/Contributions/cmds/git
new file mode 100755
index 000000000..7539ecfc0
--- /dev/null
+++ b/Library/Contributions/cmds/git
@@ -0,0 +1,51 @@
+#!/usr/bin/ruby -W0
+# This script because we support $GIT, $HOMEBREW_SVN, etc. and Xcode-only
+# configurations. Order is careful to be what the user would want.
+
+F = File.basename(__FILE__).freeze
+D = File.expand_path(File.dirname(__FILE__)).freeze
+
+def exec *args
+ # prevent fork-bombs
+ arg0 = if args.size == 1
+ args.first.split(' ')
+ else
+ args
+ end.first
+ return if arg0 =~ /^#{F}/i
+ return if File.expand_path(arg0) == File.expand_path(__FILE__)
+
+ if args[1] == '-print-path' and File.executable? args[0]
+ puts args[0]
+ exit 0
+ else
+ Kernel.exec *args
+ end
+end
+
+case F.downcase
+ when 'git' then %W{HOMEBREW_GIT GIT}
+ when 'svn' then "HOMEBREW_SVN"
+ else []
+end.each do |key|
+ exec ENV[key], *ARGV if ENV[key] and File.executable? ENV[key]
+end
+
+brew_version = File.expand_path("#{D}/../../../bin/#{F}")
+exec brew_version, *ARGV if File.executable? brew_version
+
+`/usr/bin/which -a #{F} 2>/dev/null`.split("\n").each do |path|
+ exec path, *ARGV
+end
+
+# xcrun hangs if xcode-select is set to "/"
+path = `/usr/bin/xcode-select -print-path 2>/dev/null`.chomp
+if path != "/"
+ path = `/usr/bin/xcrun -find #{F} 2>/dev/null`.chomp
+ exec path, *ARGV if File.executable? path
+end
+
+path = "/Applications/Xcode.app/Contents/Developer/usr/bin/#{F}"
+exec path, *ARGV if File.executable? path
+
+abort "You must: brew install #{F}"