]> source.dussan.org Git - jgit.git/commitdiff
Fix NPE FS_Win32 when looking up git executable and home directory 49/9549/2
authorTobias Pfeifer <to.pfeifer@sap.com>
Wed, 9 Jan 2013 11:04:13 +0000 (12:04 +0100)
committerTobias Pfeifer <to.pfeifer@sap.com>
Thu, 10 Jan 2013 14:35:45 +0000 (15:35 +0100)
avoiding redundant code

Bug: 397336
Change-Id: I60e1baa52e00c5ec3915b859bfc6a4572611cc89

org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java

index ce62628e8556d862a9f4e8e08f370e5803233d58..73f9161ca3b8323e5e17d1c1a1f32d7b647eb5f0 100644 (file)
@@ -90,7 +90,7 @@ class FS_Win32 extends FS {
                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 gitExe.getParentFile().getParentFile();
+                       return resolveGrandparentFile(gitExe);
 
                // This isn't likely to work, if bash is in $PATH, git should
                // also be in $PATH. But its worth trying.
@@ -102,7 +102,16 @@ class FS_Win32 extends FS {
                        // The path may be in cygwin/msys notation so resolve it right away
                        gitExe = resolve(null, w);
                        if (gitExe != null)
-                               return gitExe.getParentFile().getParentFile();
+                               return resolveGrandparentFile(gitExe);
+               }
+               return null;
+       }
+
+       private static File resolveGrandparentFile(File grandchild) {
+               if (grandchild != null) {
+                       File parent = grandchild.getParentFile();
+                       if (parent != null)
+                               return parent.getParentFile();
                }
                return null;
        }
@@ -115,7 +124,8 @@ class FS_Win32 extends FS {
                String homeDrive = SystemReader.getInstance().getenv("HOMEDRIVE"); //$NON-NLS-1$
                if (homeDrive != null) {
                        String homePath = SystemReader.getInstance().getenv("HOMEPATH"); //$NON-NLS-1$
-                       return new File(homeDrive, homePath);
+                       if (homePath != null)
+                               return new File(homeDrive, homePath);
                }
 
                String homeShare = SystemReader.getInstance().getenv("HOMESHARE"); //$NON-NLS-1$