From da0770fdec64b00be7c4c22d5acebee622bbf5f3 Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Tue, 4 Jul 2017 16:39:28 +0200 Subject: [PATCH] Fix committing empty commits Allow to explicitly create an empty commit even if committing only certain files. Bug: 510685 Change-Id: If9bf664d7cd824f8e5bd6765fa6cc739af3d7721 --- .../tst/org/eclipse/jgit/api/CommitCommandTest.java | 5 +++++ org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java index 37fee402e..a0834e7e8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java @@ -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(); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java index 274ece6dc..e29fc0546 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java @@ -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);