Split discoverGitPrefix() code out into discoverGitExe()

Change-Id: I700540eec06efb24eeb09bfcb40420820c32d156
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Sebastian Schuberth 2015-05-19 10:48:24 +02:00 committed by Matthias Sohn
parent 4ca2fc5ce7
commit 6fdd214349
5 changed files with 40 additions and 37 deletions

View File

@ -624,7 +624,7 @@ public FS newInstance() {
return this; return this;
} }
protected File discoverGitPrefix() { protected File discoverGitExe() {
return null; return null;
} }
@ -669,7 +669,7 @@ public FS newInstance() {
return this; return this;
} }
protected File discoverGitPrefix() { protected File discoverGitExe() {
return null; return null;
} }

View File

@ -108,7 +108,7 @@ public FS newInstance() {
return this; return this;
} }
protected File discoverGitPrefix() { protected File discoverGitExe() {
return null; return null;
} }
@ -153,7 +153,7 @@ public FS newInstance() {
return this; return this;
} }
protected File discoverGitPrefix() { protected File discoverGitExe() {
return null; return null;
} }

View File

@ -504,8 +504,16 @@ public File gitPrefix() {
return p.value; 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. */ /** @return the $prefix directory C Git would use. */
protected abstract File discoverGitPrefix(); protected File discoverGitPrefix() {
return resolveGrandparentFile(discoverGitExe());
}
/** /**
* @param grandchild * @param grandchild

View File

@ -134,28 +134,26 @@ private static int readUmask() {
} }
@Override @Override
protected File discoverGitPrefix() { protected File discoverGitExe() {
String path = SystemReader.getInstance().getenv("PATH"); //$NON-NLS-1$ String path = SystemReader.getInstance().getenv("PATH"); //$NON-NLS-1$
File gitExe = searchPath(path, "git"); //$NON-NLS-1$ File gitExe = searchPath(path, "git"); //$NON-NLS-1$
if (gitExe != null)
return resolveGrandparentFile(gitExe);
if (SystemReader.getInstance().isMacOS()) { if (gitExe == null) {
if (searchPath(path, "bash") != null) { //$NON-NLS-1$ if (SystemReader.getInstance().isMacOS()) {
// On MacOSX, PATH is shorter when Eclipse is launched from the if (searchPath(path, "bash") != null) { //$NON-NLS-1$
// Finder than from a terminal. Therefore try to launch bash as a // On MacOSX, PATH is shorter when Eclipse is launched from the
// login shell and search using that. // Finder than from a terminal. Therefore try to launch bash as a
String w = readPipe(userHome(), // login shell and search using that.
new String[] { "bash", "--login", "-c", "which git" }, // //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ String w = readPipe(userHome(),
Charset.defaultCharset().name()); new String[]{"bash", "--login", "-c", "which git"}, // //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
if (w == null || w.length() == 0) Charset.defaultCharset().name());
return null; if (!StringUtils.isEmptyOrNull(w))
gitExe = new File(w); gitExe = new File(w);
return resolveGrandparentFile(gitExe); }
} }
} }
return null; return gitExe;
} }
@Override @Override

View File

@ -105,27 +105,24 @@ public boolean retryFailedLockFileCommit() {
} }
@Override @Override
protected File discoverGitPrefix() { protected File discoverGitExe() {
String path = SystemReader.getInstance().getenv("PATH"); //$NON-NLS-1$ String path = SystemReader.getInstance().getenv("PATH"); //$NON-NLS-1$
File gitExe = searchPath(path, "git.exe", "git.cmd"); //$NON-NLS-1$ //$NON-NLS-2$ 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$ if (gitExe == null) {
// This isn't likely to work, but its worth trying: if (searchPath(path, "bash.exe") != null) { //$NON-NLS-1$
// If bash is in $PATH, git should also be in $PATH. // This isn't likely to work, but its worth trying:
String w = readPipe(userHome(), // If bash is in $PATH, git should also be in $PATH.
new String[] { "bash", "--login", "-c", "which git" }, // //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ String w = readPipe(userHome(),
Charset.defaultCharset().name()); new String[]{"bash", "--login", "-c", "which git"}, // //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
if (w == null || w.length() == 0) Charset.defaultCharset().name());
return null; if (!StringUtils.isEmptyOrNull(w))
// The path may be in cygwin/msys notation so resolve it right away // The path may be in cygwin/msys notation so resolve it right away
gitExe = resolve(null, w); gitExe = resolve(null, w);
if (gitExe != null) }
return resolveGrandparentFile(gitExe);
} }
return null; return gitExe;
} }
@Override @Override