From 4fea450fd3edfba6bb9e2c3c0a9231c6d227a09c Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 23 Feb 2012 19:49:46 -0500
Subject: [PATCH] Fixed nullpointer on pushing to an empty repository (issue 69)
---
src/com/gitblit/utils/JGitUtils.java | 40 ++++++++++++++++++----------------------
1 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java
index a9b99a9..5f193d0 100644
--- a/src/com/gitblit/utils/JGitUtils.java
+++ b/src/com/gitblit/utils/JGitUtils.java
@@ -423,11 +423,9 @@
* last modified date of the repository folder is returned.
*
* @param repository
- * @param branch
- * if unspecified, all branches are checked.
* @return
*/
- public static Date getLastChange(Repository repository, String branch) {
+ public static Date getLastChange(Repository repository) {
if (!hasCommits(repository)) {
// null repository
if (repository == null) {
@@ -436,26 +434,21 @@
// fresh repository
return new Date(repository.getDirectory().lastModified());
}
- if (StringUtils.isEmpty(branch)) {
- List<RefModel> branchModels = getLocalBranches(repository, true, -1);
- if (branchModels.size() > 0) {
- // find most recent branch update
- Date lastChange = new Date(0);
- for (RefModel branchModel : branchModels) {
- if (branchModel.getDate().after(lastChange)) {
- lastChange = branchModel.getDate();
- }
- }
- return lastChange;
- } else {
- // try to find head
- branch = Constants.HEAD;
- }
- }
- // lookup specified branch
- RevCommit commit = getCommit(repository, branch);
- return getCommitDate(commit);
+ List<RefModel> branchModels = getLocalBranches(repository, true, -1);
+ if (branchModels.size() > 0) {
+ // find most recent branch update
+ Date lastChange = new Date(0);
+ for (RefModel branchModel : branchModels) {
+ if (branchModel.getDate().after(lastChange)) {
+ lastChange = branchModel.getDate();
+ }
+ }
+ return lastChange;
+ }
+
+ // default to the repository folder modification date
+ return new Date(repository.getDirectory().lastModified());
}
/**
@@ -962,6 +955,9 @@
} else {
branchObject = repository.resolve(objectId);
}
+ if (branchObject == null) {
+ return list;
+ }
RevWalk rw = new RevWalk(repository);
rw.markStart(rw.parseCommit(branchObject));
--
Gitblit v1.9.1