From 6d09c486ed833484d9413e3c8f955d2afe27d397 Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Mon, 18 May 2015 12:48:08 +0200 Subject: [PATCH] Fix CommitCommand.setOnly() When CommitCommand.setOnly(path) is used a temporary index has to be created containing only modifications for the specified pathes. The process to fill this temporary index was broken because filling the index was stopped when we reached the first untracked file. Instead the process to fill the temporary index should continue until we processed all pathes. Bug: 451465 Change-Id: I22af50d70bd3b81e7c056358724956122b0d158d Signed-off-by: Matthias Sohn --- .../tst/org/eclipse/jgit/api/CommitCommandTest.java | 11 +++++++++++ .../src/org/eclipse/jgit/api/CommitCommand.java | 2 +- 2 files changed, 12 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 54fbc6671..060a5b65c 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 @@ -514,6 +514,17 @@ public void commitOnlyShouldCommitUnmergedPathAndNotAffectOthers() } } + @Test + public void commitOnlyShouldHandleIgnored() throws Exception { + try (Git git = new Git(db)) { + writeTrashFile("subdir/foo", "Hello World"); + writeTrashFile("subdir/bar", "Hello World"); + writeTrashFile(".gitignore", "bar"); + git.add().addFilepattern("subdir").call(); + git.commit().setOnly("subdir").setMessage("first commit").call(); + } + } + private static void addUnmergedEntry(String file, DirCacheBuilder builder) { DirCacheEntry stage1 = new DirCacheEntry(file, DirCacheEntry.STAGE_1); DirCacheEntry stage2 = new DirCacheEntry(file, DirCacheEntry.STAGE_2); 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 87efd7983..6174d48d3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java @@ -358,7 +358,7 @@ private DirCache createTemporaryIndex(ObjectId headId, DirCache index, // check if entry refers to a tracked file boolean tracked = dcTree != null || hTree != null; if (!tracked) - break; + continue; // for an unmerged path, DirCacheBuildIterator will yield 3 // entries, we only want to add one