diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java index 275b7adf7..2abed3adc 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java @@ -624,7 +624,7 @@ public FS newInstance() { return this; } - protected File discoverGitPrefix() { + protected File discoverGitExe() { return null; } @@ -669,7 +669,7 @@ public FS newInstance() { return this; } - protected File discoverGitPrefix() { + protected File discoverGitExe() { return null; } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java index 2c70a166e..54fbc6671 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java @@ -108,7 +108,7 @@ public FS newInstance() { return this; } - protected File discoverGitPrefix() { + protected File discoverGitExe() { return null; } @@ -153,7 +153,7 @@ public FS newInstance() { return this; } - protected File discoverGitPrefix() { + protected File discoverGitExe() { return null; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java index 762b36ecb..569a8864b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -504,8 +504,16 @@ public File gitPrefix() { return p.value; } + /** + * @return the path to the Git executable. + * @since 4.0 + */ + protected abstract File discoverGitExe(); + /** @return the $prefix directory C Git would use. */ - protected abstract File discoverGitPrefix(); + protected File discoverGitPrefix() { + return resolveGrandparentFile(discoverGitExe()); + } /** * @param grandchild diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java index e2f9bb826..b07f8594d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java @@ -134,28 +134,26 @@ private static int readUmask() { } @Override - protected File discoverGitPrefix() { + protected File discoverGitExe() { String path = SystemReader.getInstance().getenv("PATH"); //$NON-NLS-1$ File gitExe = searchPath(path, "git"); //$NON-NLS-1$ - if (gitExe != null) - return resolveGrandparentFile(gitExe); - if (SystemReader.getInstance().isMacOS()) { - 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 = 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 (w == null || w.length() == 0) - return null; - gitExe = new File(w); - return resolveGrandparentFile(gitExe); + if (gitExe == null) { + if (SystemReader.getInstance().isMacOS()) { + 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 = 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); + } } } - return null; + return gitExe; } @Override diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java index 5282733dd..5c652be18 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java @@ -105,27 +105,24 @@ public boolean retryFailedLockFileCommit() { } @Override - protected File discoverGitPrefix() { + protected File discoverGitExe() { String path = SystemReader.getInstance().getenv("PATH"); //$NON-NLS-1$ File gitExe = searchPath(path, "git.exe", "git.cmd"); //$NON-NLS-1$ //$NON-NLS-2$ - if (gitExe != null) - return resolveGrandparentFile(gitExe); - if (searchPath(path, "bash.exe") != null) { //$NON-NLS-1$ - // This isn't likely to work, but its worth trying: - // If bash is in $PATH, git should also be in $PATH. - 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 (w == null || w.length() == 0) - return null; - // The path may be in cygwin/msys notation so resolve it right away - gitExe = resolve(null, w); - if (gitExe != null) - return resolveGrandparentFile(gitExe); + if (gitExe == null) { + if (searchPath(path, "bash.exe") != null) { //$NON-NLS-1$ + // This isn't likely to work, but its worth trying: + // If bash is in $PATH, git should also be in $PATH. + 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)) + // The path may be in cygwin/msys notation so resolve it right away + gitExe = resolve(null, w); + } } - return null; + return gitExe; } @Override