Reputation: 3831
I can locate executables named git
in several ways (basically equivalent to which git
). But all of the solutions I know about are defeated by OS X's fake /usr/bin/git
program, which is a hook to a dialog offering to install Xcode's git
(I'll refer to it subsequently as the OS X git installer.)
I want to detect that situation and treat git
as not found if that is the only one. I don't want to have to execute it to determine that, because I don't want to trigger the installer dialog.
Context: I'd like to implement the following (as part of a larger software installation process):
git
, other than the OS X git installer, is on the PATH
),I am comfortable parsing PATH
if needed and searching for executables myself, if I can find a way to ignore the OS X git installer. I am comfortable with a heuristic if it gets this right almost all the time; I don't need to handle edge cases (like someone creating an executable or script called git
that is not git
-compatible).
What's the best (most robust, secondarily most convenient) way to determine whether a non-OS X git installer git
is installed on a system without executing /usr/bin/git
(and triggering the installer dialog)?
Upvotes: 2
Views: 90
Reputation: 3831
Alright, I think I have my answer, of the heuristic variety.
IF:
/Applications/Xcode.app/
does not exist,
AND:
/Library/Developer/CommandLineTools/
does not exist,
THEN:
/usr/bin/git
is the stub, and it can be ignored.
Obviously there are failure cases possible; people can move those files around, people can create executables named git
that are not git
-compatible, but this seems to be the 99% solution and turns out to be a little easier than I thought.
I haven't yet investigated what will happen if I install the git project's git
, and what will happen in the PATH
(will the Apple non-tool still be first?). If that changes anything substantial I'll report back; I am guessing if Apple's tool is still first in the PATH
, I'll have my installation process move or delete it, or possibly change the PATH
it uses, or something.
Upvotes: 1
Reputation: 43487
There is no best way. There are some things that defy automated discovery and I can certainly have $HOME/bin/git
which isn't git
but is in my path.
What you can do is make the path to git as a configurable item with a reasonable default and document it well. The git
program itself does this itself; it will look for configuration items in a few different places and finally allows git --file configfile
as a last option to override.
Upvotes: 1