]> source.dussan.org Git - jgit.git/commitdiff
Merge doesn't remove empty folders 56/3756/2
authorTomasz Zarna <Tomasz.Zarna@pl.ibm.com>
Mon, 20 Jun 2011 16:17:56 +0000 (18:17 +0200)
committerStefan Lay <stefan.lay@sap.com>
Wed, 13 Jul 2011 13:42:33 +0000 (15:42 +0200)
Bug: 349848
Change-Id: I2aa5a1a7259889428e4845046b900538262f3c84

org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java

index 39526e229a1b8ad454a123902bf1dabd79719423..7811706fc1a44867f88fb47f1d3727ec23e36936 100644 (file)
@@ -60,6 +60,7 @@ import org.eclipse.jgit.lib.RepositoryTestCase;
 import org.eclipse.jgit.merge.MergeStrategy;
 import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
 import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.util.FileUtils;
 import org.junit.Test;
 
 public class MergeCommandTest extends RepositoryTestCase {
@@ -916,6 +917,46 @@ public class MergeCommandTest extends RepositoryTestCase {
                                indexState, fileA);
        }
 
+       @Test
+       public void testMergeRemovingFolders() throws Exception {
+               File folder1 = new File(db.getWorkTree(), "folder1");
+               File folder2 = new File(db.getWorkTree(), "folder2");
+               FileUtils.mkdir(folder1);
+               FileUtils.mkdir(folder2);
+               File file = new File(folder1, "file1.txt");
+               write(file, "folder1--file1.txt");
+               file = new File(folder1, "file2.txt");
+               write(file, "folder1--file2.txt");
+               file = new File(folder2, "file1.txt");
+               write(file, "folder--file1.txt");
+               file = new File(folder2, "file2.txt");
+               write(file, "folder2--file2.txt");
+
+               Git git = new Git(db);
+               git.add().addFilepattern(folder1.getName())
+                               .addFilepattern(folder2.getName()).call();
+               RevCommit commit1 = git.commit().setMessage("adding folders").call();
+
+               recursiveDelete(folder1);
+               recursiveDelete(folder2);
+               git.rm().addFilepattern("folder1/file1.txt")
+                               .addFilepattern("folder1/file2.txt")
+                               .addFilepattern("folder2/file1.txt")
+                               .addFilepattern("folder2/file2.txt").call();
+               RevCommit commit2 = git.commit()
+                               .setMessage("removing folders on 'branch'").call();
+
+               git.checkout().setName(commit1.name()).call();
+
+               MergeResult result = git.merge().include(commit2.getId())
+                               .setStrategy(MergeStrategy.RESOLVE).call();
+               assertEquals(MergeResult.MergeStatus.FAST_FORWARD,
+                               result.getMergeStatus());
+               assertEquals(commit2, result.getNewHead());
+               assertFalse(folder1.exists());
+               assertFalse(folder2.exists());
+       }
+
        private RevCommit addAllAndCommit(final Git git) throws Exception {
                git.add().addFilepattern(".").call();
                return git.commit().setMessage("message").call();
index 6a1669b4f214cb776b732e66e0a4931bad246f5a..79f2297b2630db0d7cba823272f2fedaddcbe649 100644 (file)
@@ -414,7 +414,7 @@ public class DirCacheCheckout {
                                        toBeDeleted.add(r);
                        else {
                                if (!isSamePrefix(r, last))
-                                       removeEmptyParents(file);
+                                       removeEmptyParents(new File(repo.getWorkTree(), last));
                                last = r;
                        }
                }