/** @return the $prefix directory C Git would use. */
protected abstract File discoverGitPrefix();
+ /**
+ * @param grandchild
+ * @return the parent directory of this file's parent directory or
+ * {@code null} in case there's no grandparent directory
+ * @since 4.0
+ */
+ protected static File resolveGrandparentFile(File grandchild) {
+ if (grandchild != null) {
+ File parent = grandchild.getParentFile();
+ if (parent != null)
+ return parent.getParentFile();
+ }
+ return null;
+ }
+
/**
* Set the $prefix directory C Git uses.
*
String path = SystemReader.getInstance().getenv("PATH"); //$NON-NLS-1$
File gitExe = searchPath(path, "git"); //$NON-NLS-1$
if (gitExe != null)
- return gitExe.getParentFile().getParentFile();
+ return resolveGrandparentFile(gitExe);
if (SystemReader.getInstance().isMacOS()) {
// On MacOSX, PATH is shorter when Eclipse is launched from the
Charset.defaultCharset().name());
if (w == null || w.length() == 0)
return null;
- File parentFile = new File(w).getParentFile();
- if (parentFile == null)
- return null;
- return parentFile.getParentFile();
+ return resolveGrandparentFile(new File(w));
}
return null;
return null;
}
- private static File resolveGrandparentFile(File grandchild) {
- if (grandchild != null) {
- File parent = grandchild.getParentFile();
- if (parent != null)
- return parent.getParentFile();
- }
- return null;
- }
-
@Override
protected File userHomeImpl() {
String home = SystemReader.getInstance().getenv("HOME"); //$NON-NLS-1$