Browse Source

FS_POSIX: avoid prompt to install the XCode tools on OS X

OS X ships with a default /usr/bin/git that is just a wrapper that
at run-time delegates to the selected XCode toolchain, and that
prompts the user to install the XCode command line tools if not
already installed.

This is annoying for people who don't want to do so, since they'll
be prompted on each Eclipse start. Also, since on OS X the $PATH for
applications started via the GUI is not the same as the $PATH as set
via the shell profile, just using /usr/bin/git (which will normally
be found when JGit runs inside Eclipse) may give slightly surprising
results if the user has installed a non-Apple git and changed his
$PATH in the shell such that the non-Apple git is used in the shell.
(For instance by placing /usr/local/bin earlier on the path.) Eclipse
and the shell will use different git executables, and thus different
git system configs.

Therefore, try to find git via bash --login -c 'which git' not only
if we couldn't find it on $PATH but also if we found the default git
/usr/bin/git. If that finds some other git, use that. If the bash
approach also finds /usr/bin/git, double check via xcode-select -p
that an XCode git is present. If not, assume there is no git installed,
and work without any system config.

Bug: 564372
Change-Id: Ie9d010ebd9437a491ba5d92b4ffd1860c203f8ca
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
master
Thomas Wolf 4 years ago
parent
commit
9fe5406119
  1. 5
      org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
  2. 38
      org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java

5
org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java

@ -1356,7 +1356,7 @@ public abstract class FS {
String v;
try {
v = readPipe(gitExe.getParentFile(),
new String[] { "git", "--version" }, //$NON-NLS-1$ //$NON-NLS-2$
new String[] { gitExe.getPath(), "--version" }, //$NON-NLS-1$
Charset.defaultCharset().name());
} catch (CommandFailedException e) {
LOG.warn(e.getMessage());
@ -1375,7 +1375,8 @@ public abstract class FS {
String w;
try {
w = readPipe(gitExe.getParentFile(),
new String[] { "git", "config", "--system", "--edit" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { gitExe.getPath(), "config", "--system", //$NON-NLS-1$ //$NON-NLS-2$
"--edit" }, //$NON-NLS-1$
Charset.defaultCharset().name(), env);
} catch (CommandFailedException e) {
LOG.warn(e.getMessage());

38
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java

@ -54,6 +54,8 @@ import org.slf4j.LoggerFactory;
public class FS_POSIX extends FS {
private static final Logger LOG = LoggerFactory.getLogger(FS_POSIX.class);
private static final String DEFAULT_GIT_LOCATION = "/usr/bin/git"; //$NON-NLS-1$
private static final int DEFAULT_UMASK = 0022;
private volatile int umask = -1;
@ -138,24 +140,46 @@ public class FS_POSIX extends FS {
String path = SystemReader.getInstance().getenv("PATH"); //$NON-NLS-1$
File gitExe = searchPath(path, "git"); //$NON-NLS-1$
if (gitExe == null) {
if (SystemReader.getInstance().isMacOS()) {
if (SystemReader.getInstance().isMacOS()) {
if (gitExe == null
|| DEFAULT_GIT_LOCATION.equals(gitExe.getPath())) {
if (searchPath(path, "bash") != null) { //$NON-NLS-1$
// On MacOSX, PATH is shorter when Eclipse is launched from the
// Finder than from a terminal. Therefore try to launch bash as a
// login shell and search using that.
String w;
try {
w = readPipe(userHome(),
String w = readPipe(userHome(),
new String[]{"bash", "--login", "-c", "which git"}, // //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Charset.defaultCharset().name());
if (!StringUtils.isEmptyOrNull(w)) {
gitExe = new File(w);
}
} catch (CommandFailedException e) {
LOG.warn(e.getMessage());
return null;
}
if (!StringUtils.isEmptyOrNull(w)) {
gitExe = new File(w);
}
}
if (gitExe != null
&& DEFAULT_GIT_LOCATION.equals(gitExe.getPath())) {
// If we still have the default git exe, it's an XCode wrapper
// that may prompt the user to install the XCode command line
// tools if not already present. Avoid the prompt by returning
// null if no XCode git is there.
try {
String w = readPipe(userHome(),
new String[] { "xcode-select", "-p" }, //$NON-NLS-1$ //$NON-NLS-2$
Charset.defaultCharset().name());
if (StringUtils.isEmptyOrNull(w)) {
gitExe = null;
} else {
File realGitExe = new File(new File(w),
DEFAULT_GIT_LOCATION.substring(1));
if (!realGitExe.exists()) {
gitExe = null;
}
}
} catch (CommandFailedException e) {
gitExe = null;
}
}
}

Loading…
Cancel
Save