]> source.dussan.org Git - gitblit.git/commitdiff
Fixed nullpointer on pushing to an empty repository (issue 69)
authorJames Moger <james.moger@gitblit.com>
Fri, 24 Feb 2012 00:49:46 +0000 (19:49 -0500)
committerJames Moger <james.moger@gitblit.com>
Fri, 24 Feb 2012 00:49:46 +0000 (19:49 -0500)
docs/04_releases.mkd
src/com/gitblit/GitBlit.java
src/com/gitblit/utils/JGitUtils.java
src/com/gitblit/wicket/pages/SummaryPage.java
tests/com/gitblit/tests/JGitUtilsTest.java

index 2208b5737dafd74db4059759d4253577c3f6d3a9..3f5eb39dc4fbbdbf2da087c4911b42b2963434f1 100644 (file)
@@ -30,6 +30,7 @@ Push requests to these repositories will be rejected.
 \r
 #### fixes \r
 \r
+- Fixed (harmless) nullpointer on pushing to an empty repository (issue 69)\r
 - Fixed possible nullpointer from the servlet container on startup (issue 67)\r
 - Fixed UTF-8 encoding bug on diff page (issue 66)\r
 - Fixed timezone bug on the activity page (issue 54)\r
index 7fb325c6e6a3bee0ef2e91d54a02fe1dc3cfa36d..a57e6055e82463425e9ff4ba9030b6cad1d35323 100644 (file)
@@ -780,7 +780,7 @@ public class GitBlit implements ServletContextListener {
                RepositoryModel model = new RepositoryModel();\r
                model.name = repositoryName;\r
                model.hasCommits = JGitUtils.hasCommits(r);\r
-               model.lastChange = JGitUtils.getLastChange(r, null);\r
+               model.lastChange = JGitUtils.getLastChange(r);\r
                model.isBare = r.isBare();\r
                StoredConfig config = JGitUtils.readConfig(r);\r
                if (config != null) {\r
index a9b99a93721bad4b0a4ee109bc151530e6c9a08b..5f193d02426bbdd0375bb278ca0b703a708ac021 100644 (file)
@@ -423,11 +423,9 @@ public class JGitUtils {
         * last modified date of the repository folder is returned.\r
         * \r
         * @param repository\r
-        * @param branch\r
-        *            if unspecified, all branches are checked.\r
         * @return\r
         */\r
-       public static Date getLastChange(Repository repository, String branch) {\r
+       public static Date getLastChange(Repository repository) {\r
                if (!hasCommits(repository)) {\r
                        // null repository\r
                        if (repository == null) {\r
@@ -436,26 +434,21 @@ public class JGitUtils {
                        // fresh repository\r
                        return new Date(repository.getDirectory().lastModified());\r
                }\r
-               if (StringUtils.isEmpty(branch)) {\r
-                       List<RefModel> branchModels = getLocalBranches(repository, true, -1);\r
-                       if (branchModels.size() > 0) {\r
-                               // find most recent branch update\r
-                               Date lastChange = new Date(0);\r
-                               for (RefModel branchModel : branchModels) {\r
-                                       if (branchModel.getDate().after(lastChange)) {\r
-                                               lastChange = branchModel.getDate();\r
-                                       }\r
+\r
+               List<RefModel> branchModels = getLocalBranches(repository, true, -1);\r
+               if (branchModels.size() > 0) {\r
+                       // find most recent branch update\r
+                       Date lastChange = new Date(0);\r
+                       for (RefModel branchModel : branchModels) {\r
+                               if (branchModel.getDate().after(lastChange)) {\r
+                                       lastChange = branchModel.getDate();\r
                                }\r
-                               return lastChange;\r
-                       } else {\r
-                               // try to find head\r
-                               branch = Constants.HEAD;\r
                        }\r
+                       return lastChange;\r
                }\r
-\r
-               // lookup specified branch\r
-               RevCommit commit = getCommit(repository, branch);\r
-               return getCommitDate(commit);\r
+               \r
+               // default to the repository folder modification date\r
+               return new Date(repository.getDirectory().lastModified());\r
        }\r
 \r
        /**\r
@@ -962,6 +955,9 @@ public class JGitUtils {
                        } else {\r
                                branchObject = repository.resolve(objectId);\r
                        }\r
+                       if (branchObject == null) {\r
+                               return list;\r
+                       }\r
 \r
                        RevWalk rw = new RevWalk(repository);\r
                        rw.markStart(rw.parseCommit(branchObject));\r
index acb41808f2d075a23e7c8c21719138e255662716..12371f7701bbf7dbf4ed179c3debcdd398f9e0d1 100644 (file)
@@ -84,7 +84,7 @@ public class SummaryPage extends RepositoryPage {
                add(new Label("repositoryOwner", getRepositoryModel().owner));\r
 \r
                add(WicketUtils.createTimestampLabel("repositoryLastChange",\r
-                               JGitUtils.getLastChange(r, null), getTimeZone()));\r
+                               JGitUtils.getLastChange(r), getTimeZone()));\r
                if (metricsTotal == null) {\r
                        add(new Label("branchStats", ""));\r
                } else {\r
index e649769e015fdfa283643a393f12db764f01ed10..74531fa43a35df9b1fe79b5051e9d77f44855af0 100644 (file)
@@ -97,11 +97,11 @@ public class JGitUtilsTest {
 \r
        @Test\r
        public void testLastCommit() throws Exception {\r
-               assertEquals(new Date(0), JGitUtils.getLastChange(null, null));\r
+               assertEquals(new Date(0), JGitUtils.getLastChange(null));\r
 \r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                assertTrue(JGitUtils.getCommit(repository, null) != null);\r
-               Date date = JGitUtils.getLastChange(repository, null);\r
+               Date date = JGitUtils.getLastChange(repository);\r
                repository.close();\r
                assertNotNull("Could not get last repository change date!", date);\r
        }\r
@@ -119,7 +119,7 @@ public class JGitUtilsTest {
                        assertNull(JGitUtils.getFirstCommit(repository, null));\r
                        assertEquals(folder.lastModified(), JGitUtils.getFirstChange(repository, null)\r
                                        .getTime());\r
-                       assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository, null).getTime());\r
+                       assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository).getTime());\r
                        assertNull(JGitUtils.getCommit(repository, null));\r
                        repository.close();\r
                        assertTrue(GitBlit.self().deleteRepository(repositoryName));\r