]> source.dussan.org Git - jgit.git/commitdiff
Make sure checkout doesn't report conflicts on ignored paths 63/36063/3
authorChristian Halstrick <christian.halstrick@sap.com>
Thu, 6 Nov 2014 18:01:23 +0000 (19:01 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 6 Nov 2014 20:27:46 +0000 (15:27 -0500)
In a situation where a certain path was ignored but a working tree file
with this path existed jgit didn't allow to checkout a branch which
didn't ignore this path but contained different content. JGit considered
this to be a checkout conflict to prevent overwriting the file in the
working tree and raised an error. This commit fixes this by ensuring
that ignored dirty working tree files don't lead to a checkout conflict.

Bug: 450169
Change-Id: I90288d314ffac73c24a9c70a5181f8243bd4679a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java

index f7e6fa9b79fbf1065aaff6fe8ca1ec47491df528..48debae93223de297b33badf82f203baada3af11 100644 (file)
@@ -985,6 +985,38 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
                }
        }
 
+       @Test
+       public void testOverwriteUntrackedIgnoredFile() throws IOException,
+                       GitAPIException {
+               String fname="file.txt";
+               Git git = Git.wrap(db);
+
+               // Add a file
+               writeTrashFile(fname, "a");
+               git.add().addFilepattern(fname).call();
+               git.commit().setMessage("create file").call();
+
+               // Create branch
+               git.branchCreate().setName("side").call();
+
+               // Modify file
+               writeTrashFile(fname, "b");
+               git.add().addFilepattern(fname).call();
+               git.commit().setMessage("modify file").call();
+
+               // Switch branches
+               git.checkout().setName("side").call();
+               git.rm().addFilepattern(fname).call();
+               writeTrashFile(".gitignore", fname);
+               git.add().addFilepattern(".gitignore").call();
+               git.commit().setMessage("delete and ignore file").call();
+
+               writeTrashFile(fname, "Something different");
+               git.checkout().setName("master").call();
+               assertWorkDir(mkmap(fname, "b"));
+               assertTrue(git.status().call().isClean());
+       }
+
        @Test
        public void testFileModeChangeWithNoContentChangeUpdate() throws Exception {
                if (!FS.DETECTED.supportsExecute())
index 4b0d58600f29b6f5a34a5d63ca57ffa61ff22771..9f340c11913532600f2632911f47802047d1361c 100644 (file)
@@ -698,7 +698,7 @@ public class DirCacheCheckout {
                        // Nothing in Index
                        // At least one of Head, Index, Merge is not empty
                        // make sure not to overwrite untracked files
-                       if (f != null) {
+                       if (f != null && !f.isEntryIgnored()) {
                                // A submodule is not a file. We should ignore it
                                if (!FileMode.GITLINK.equals(mMode)) {
                                        // a dirty worktree: the index is empty but we have a