diff options
author | Robin Stocker | 2012-10-22 22:28:30 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2013-01-11 20:34:24 +0000 |
commit | 4c42f5228cedb2407e698e315cbea30b616e0153 (patch) | |
tree | 73eccdd5ff5b67a6b52eed3ebe072e7dd92102e4 /org.eclipse.egit.core.test | |
parent | 5eafe034c2eacc150c34c1884e6a32d2c18ea07d (diff) | |
download | egit-4c42f5228cedb2407e698e315cbea30b616e0153.tar.gz egit-4c42f5228cedb2407e698e315cbea30b616e0153.tar.xz egit-4c42f5228cedb2407e698e315cbea30b616e0153.zip |
GitMoveDeleteHook: Cancel move if it would affect unmerged file
Before this change, the index entries belonging to the unmerged path
would get into a "funny" state.
The only good alternative to canceling the move would be to preserve the
index entries under the new path. C Git aborts with an error when doing
"git mv", so we do the same now.
Bug: 391857
Change-Id: I0477f62c9f4997890ea15f1228413f33473577c8
Diffstat (limited to 'org.eclipse.egit.core.test')
-rw-r--r-- | org.eclipse.egit.core.test/src/org/eclipse/egit/core/GitMoveDeleteHookTest.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/GitMoveDeleteHookTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/GitMoveDeleteHookTest.java index 382ceae280..da43c88b01 100644 --- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/GitMoveDeleteHookTest.java +++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/GitMoveDeleteHookTest.java @@ -21,12 +21,14 @@ import java.util.HashSet; import java.util.Set; import org.eclipse.core.filesystem.URIUtil; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.egit.core.op.AddToIndexOperation; import org.eclipse.egit.core.project.RepositoryMapping; @@ -34,9 +36,12 @@ import org.eclipse.egit.core.test.TestProject; import org.eclipse.egit.core.test.TestRepository; import org.eclipse.egit.core.test.TestUtils; import org.eclipse.jgit.dircache.DirCache; +import org.eclipse.jgit.dircache.DirCacheBuilder; +import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.storage.file.FileRepository; @@ -501,6 +506,77 @@ public class GitMoveDeleteHookTest { } } + @Test + public void testMoveFileWithConflictsShouldBeCanceled() throws Exception { + TestProject project = initRepoInsideProjectInsideWorkspace(); + String filePath = "file.txt"; + IFile file = testUtils.addFileToProject(project.getProject(), filePath, "some text"); + + Repository repo = testRepository.getRepository(); + DirCache index = repo.lockDirCache(); + DirCacheBuilder builder = index.builder(); + addUnmergedEntry(filePath, builder); + builder.commit(); + + try { + file.move(new Path("destination.txt"), false, null); + fail("Expected move of file with conflicts to fail."); + } catch (CoreException e) { + IStatus status = e.getStatus(); + assertNotNull(status); + assertEquals(IStatus.WARNING, status.getSeverity()); + } + + assertTrue("File should still exist at old location", file.exists()); + DirCache indexAfter = repo.readDirCache(); + DirCacheEntry entry = indexAfter.getEntry(filePath); + assertEquals("Expected entry to still be in non-zero (conflict) stage", + DirCacheEntry.STAGE_1, entry.getStage()); + } + + @Test + public void testMoveFolderWithFileWithConflictsShouldBeCanceled() throws Exception { + TestProject project = initRepoInsideProjectInsideWorkspace(); + String filePath = "folder/file.txt"; + IFile file = testUtils.addFileToProject(project.getProject(), filePath, "some text"); + + Repository repo = testRepository.getRepository(); + DirCache index = repo.lockDirCache(); + DirCacheBuilder builder = index.builder(); + addUnmergedEntry(filePath, builder); + builder.commit(); + + try { + project.getProject() + .getFolder("folder") + .move(project.getProject().getFolder("newfolder") + .getFullPath(), false, null); + fail("Expected move of folder with file with conflicts to fail."); + } catch (CoreException e) { + IStatus status = e.getStatus(); + assertNotNull(status); + assertEquals(IStatus.WARNING, status.getSeverity()); + } + + assertTrue("File should still exist at old location", file.exists()); + DirCache indexAfter = repo.readDirCache(); + DirCacheEntry entry = indexAfter.getEntry(filePath); + assertEquals("Expected entry to still be in non-zero (conflict) stage", + DirCacheEntry.STAGE_1, entry.getStage()); + } + + private static void addUnmergedEntry(String filePath, DirCacheBuilder builder) { + DirCacheEntry stage1 = new DirCacheEntry(filePath, DirCacheEntry.STAGE_1); + DirCacheEntry stage2 = new DirCacheEntry(filePath, DirCacheEntry.STAGE_2); + DirCacheEntry stage3 = new DirCacheEntry(filePath, DirCacheEntry.STAGE_3); + stage1.setFileMode(FileMode.REGULAR_FILE); + stage2.setFileMode(FileMode.REGULAR_FILE); + stage3.setFileMode(FileMode.REGULAR_FILE); + builder.add(stage1); + builder.add(stage2); + builder.add(stage3); + } + private void dotestMoveProjectWithinRepoWithinWorkspace(String srcParent, String srcProjectName, String dstParent, String dstProjecName, String gitDir) throws CoreException, IOException, Exception, |