]> source.dussan.org Git - jgit.git/commitdiff
Split discoverGitPrefix() code out into discoverGitExe() 42/48142/3
authorSebastian Schuberth <sschuberth@gmail.com>
Tue, 19 May 2015 08:48:24 +0000 (10:48 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 21 May 2015 21:37:42 +0000 (23:37 +0200)
Change-Id: I700540eec06efb24eeb09bfcb40420820c32d156
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java

index 275b7adf7b2b80943bb211122a70abb30385c579..2abed3adc8b405904d3c51f1ad25eff47e4f11cd 100644 (file)
@@ -624,7 +624,7 @@ public class AddCommandTest extends RepositoryTestCase {
                                return this;
                        }
 
-                       protected File discoverGitPrefix() {
+                       protected File discoverGitExe() {
                                return null;
                        }
 
@@ -669,7 +669,7 @@ public class AddCommandTest extends RepositoryTestCase {
                                return this;
                        }
 
-                       protected File discoverGitPrefix() {
+                       protected File discoverGitExe() {
                                return null;
                        }
 
index 2c70a166e3564938bb8d9b8ad3dfcd9e8c1daf97..54fbc6671a7851526f6444eca4729a0b80a2f5dc 100644 (file)
@@ -108,7 +108,7 @@ public class CommitCommandTest extends RepositoryTestCase {
                                return this;
                        }
 
-                       protected File discoverGitPrefix() {
+                       protected File discoverGitExe() {
                                return null;
                        }
 
@@ -153,7 +153,7 @@ public class CommitCommandTest extends RepositoryTestCase {
                                return this;
                        }
 
-                       protected File discoverGitPrefix() {
+                       protected File discoverGitExe() {
                                return null;
                        }
 
index 762b36ecb929087eb51a0349d3730ff0a9500a2a..569a8864b122c94e2ae288780a982ebf41ddfcb3 100644 (file)
@@ -504,8 +504,16 @@ public abstract class FS {
                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
index e2f9bb8264680e5345175325f15a76baff7c9acb..b07f8594dbc96ae7432fda807edc3325f481014d 100644 (file)
@@ -134,28 +134,26 @@ public class FS_POSIX extends FS {
        }
 
        @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
index 5282733dd8cf27db9dd575064f5a0868a114cb6c..5c652be18ac16038f932e7e52cdf1dcaaf57642f 100644 (file)
@@ -105,27 +105,24 @@ public class FS_Win32 extends FS {
        }
 
        @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