]> source.dussan.org Git - jgit.git/commitdiff
Change FS not to throw NPE when facing InMemory databases 43/53843/1
authorChristian Halstrick <christian.halstrick@sap.com>
Fri, 10 Jul 2015 11:01:10 +0000 (13:01 +0200)
committerChristian Halstrick <christian.halstrick@sap.com>
Sun, 16 Aug 2015 20:20:06 +0000 (22:20 +0200)
The FS class and the subclasses FS_POSIX assumed in the findHook()
method that every repository has a valid gitDir. But in tests when using
in-memory-repositories this is not true and this method was generating
NPEs. Change the method to return null if no repository directory can be
determined.

Change-Id: I38a4d36dc6452b5dacae3d0dbf562b569ca3c19b

org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java

index 47c747e80dd242b0e18b54986ada8f306a3b2833..c1535fa1fbf2571cb865e6ae15ac4d658daf7bb4 100644 (file)
@@ -866,7 +866,10 @@ public abstract class FS {
         * @since 4.0
         */
        public File findHook(Repository repository, final String hookName) {
-               final File hookFile = new File(new File(repository.getDirectory(),
+               File gitDir = repository.getDirectory();
+               if (gitDir == null)
+                       return null;
+               final File hookFile = new File(new File(gitDir,
                                Constants.HOOKS), hookName);
                return hookFile.isFile() ? hookFile : null;
        }
index b07f8594dbc96ae7432fda807edc3325f481014d..80c729007372e0f7eab9597e2124c5b4e26e1efa 100644 (file)
@@ -335,6 +335,9 @@ public class FS_POSIX extends FS {
        @Override
        public File findHook(Repository repository, String hookName) {
                final File gitdir = repository.getDirectory();
+               if (gitdir == null) {
+                       return null;
+               }
                final Path hookPath = gitdir.toPath().resolve(Constants.HOOKS)
                                .resolve(hookName);
                if (Files.isExecutable(hookPath))