diff options
| author | Dariusz Luksza | 2010-08-12 21:22:16 +0000 |
|---|---|---|
| committer | Dariusz Luksza | 2010-08-12 21:37:16 +0000 |
| commit | 51fd48888c37b71e5bfa9b4084c805dc7bb5d745 (patch) | |
| tree | df63c7b2fbf633631c43f8185fb1aaf7f230b762 | |
| parent | 057173ac27c0724152f91869133dfa163d07fc6a (diff) | |
| download | egit-51fd48888c37b71e5bfa9b4084c805dc7bb5d745.tar.gz egit-51fd48888c37b71e5bfa9b4084c805dc7bb5d745.tar.xz egit-51fd48888c37b71e5bfa9b4084c805dc7bb5d745.zip | |
Fix for bug in GitResourceVariantComparator
When comparing local folder with folder that wasn't exist remotly
GitResourceVaraintCompare return that both resources are equal. I've
added additional condition for resource existence.
Change-Id: Ie8b97fffd1237723afce6aed3c116b280694b3ba
Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
2 files changed, 24 insertions, 5 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java index 31b6b4a355..a0048adf26 100644 --- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java +++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java @@ -36,6 +36,7 @@ import org.eclipse.egit.core.test.GitTestCase; import org.eclipse.egit.core.test.TestRepository; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.treewalk.TreeWalk; @@ -99,6 +100,25 @@ public class GitResourceVariantComparatorTest extends GitTestCase { verify(local); } + @Test + @SuppressWarnings("boxing") + public void shouldReturnFalseWhenRemoteDoesNotExist2() throws Exception{ + // when + GitResourceVariantComparator grvc = new GitResourceVariantComparator( + null); + + // given + IResource local = createMock(IResource.class); + expect(local.exists()).andReturn(false); + replay(local); + IResourceVariant remote = new GitFolderResourceVariant(repo, + ObjectId.zeroId(), "./"); + + // then + assertFalse(grvc.compare(local, remote)); + verify(local); + } + /** * It is possible to have a local file that has same name as a remote * folder. In some cases that two resources can be compared. In this case @@ -142,7 +162,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase { IPath localPath = createMock(IPath.class); replay(localPath); IContainer local = createMock(IContainer.class); - expect(local.exists()).andReturn(true); + expect(local.exists()).andReturn(true).times(2); expect(local.getFullPath()).andReturn(localPath); replay(local); @@ -183,7 +203,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase { IPath iPath = new Path(File.separator + path); IContainer local = createMock(IContainer.class); - expect(local.exists()).andReturn(true); + expect(local.exists()).andReturn(true).times(2); expect(local.getFullPath()).andReturn(iPath).anyTimes(); replay(local); diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparator.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparator.java index e648a9f594..58e36e2f0f 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparator.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparator.java @@ -84,11 +84,10 @@ class GitResourceVariantComparator implements IResourceVariantComparator { closeStream(remoteStream); } } else if (local instanceof IContainer) { - if (!remote.isContainer()) { + GitResourceVariant gitVariant = (GitResourceVariant) remote; + if (!remote.isContainer() || (local.exists() ^ gitVariant.exists())) return false; - } - GitResourceVariant gitVariant = (GitResourceVariant) remote; return local.getFullPath().equals(gitVariant.getFullPath()); } return false; |
