Fix committing empty commits

Allow to explicitly create an empty commit even if committing only
certain files.

Bug: 510685 
Change-Id: If9bf664d7cd824f8e5bd6765fa6cc739af3d7721
This commit is contained in:
Christian Halstrick 2017-07-04 16:39:28 +02:00 committed by David Pursehouse
parent 7e4946626e
commit da0770fdec
2 changed files with 6 additions and 1 deletions

View File

@ -557,6 +557,11 @@ public void commitEmptyCommits() throws Exception {
} catch (EmtpyCommitException e) {
// expect this exception
}
// Allow empty commits also when setOnly was set
git.commit().setAuthor("New Author", "newauthor@example.org")
.setMessage("again no change").setOnly("file1")
.setAllowEmpty(true).call();
}
}

View File

@ -482,7 +482,7 @@ private DirCache createTemporaryIndex(ObjectId headId, DirCache index,
JGitText.get().entryNotFoundByPath, only.get(i)));
// there must be at least one change
if (emptyCommit)
if (emptyCommit && !allowEmpty.booleanValue())
// Would like to throw a EmptyCommitException. But this would break the API
// TODO(ch): Change this in the next release
throw new JGitInternalException(JGitText.get().emptyCommit);