diff options
author | James Moger <james.moger@gitblit.com> | 2012-02-23 19:49:46 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2012-02-23 19:49:46 -0500 |
commit | 4fea450fd3edfba6bb9e2c3c0a9231c6d227a09c (patch) | |
tree | 31a028c588124f8ba39f2e8ecdfb446d99cb6e4f /src/com/gitblit/utils | |
parent | 18d398e3ab5227fe10fe3f322798a51ce0cd10ca (diff) | |
download | gitblit-4fea450fd3edfba6bb9e2c3c0a9231c6d227a09c.tar.gz gitblit-4fea450fd3edfba6bb9e2c3c0a9231c6d227a09c.zip |
Fixed nullpointer on pushing to an empty repository (issue 69)
Diffstat (limited to 'src/com/gitblit/utils')
-rw-r--r-- | src/com/gitblit/utils/JGitUtils.java | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java index a9b99a93..5f193d02 100644 --- a/src/com/gitblit/utils/JGitUtils.java +++ b/src/com/gitblit/utils/JGitUtils.java @@ -423,11 +423,9 @@ public class JGitUtils { * 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 @@ public class JGitUtils { // 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();
- }
+
+ 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;
}
+ return lastChange;
}
-
- // lookup specified branch
- RevCommit commit = getCommit(repository, branch);
- return getCommitDate(commit);
+
+ // default to the repository folder modification date
+ return new Date(repository.getDirectory().lastModified());
}
/**
@@ -962,6 +955,9 @@ public class JGitUtils { } else {
branchObject = repository.resolve(objectId);
}
+ if (branchObject == null) {
+ return list;
+ }
RevWalk rw = new RevWalk(repository);
rw.markStart(rw.parseCommit(branchObject));
|