summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorthallgren2011-08-30 10:54:00 (EDT)
committer Matthias Sohn2011-08-30 10:54:00 (EDT)
commit4da79c1b456475765193193d8c81285ddcaf0304 (patch)
treef536989a51343897f51bc729f913097f33f4a0c7
parent3d933fe2234b13a85a55dd9b9dd7532f47feb60c (diff)
downloadegit-4da79c1b456475765193193d8c81285ddcaf0304.zip
egit-4da79c1b456475765193193d8c81285ddcaf0304.tar.gz
egit-4da79c1b456475765193193d8c81285ddcaf0304.tar.bz2
Fixes problem with single project repositories and GitFileHistoryrefs/changes/80/4080/5
The GitFileHistory class must consider empty relative path to project for repositories that contain one single project and the project contains the .git folder. This patch adds the necessary check to the GitFileHistory class and a JUnit test that verifies that the fix works as expected. Bug: 356020 Change-Id: I1b4fc3d6e818f39a7c7e5450b7325cea0dcdcce4 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/storage/BlobStorageTest.java55
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/GitFileHistory.java10
2 files changed, 62 insertions, 3 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/storage/BlobStorageTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/storage/BlobStorageTest.java
index 83c6995..c1d8313 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/storage/BlobStorageTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/storage/BlobStorageTest.java
@@ -8,15 +8,33 @@
*******************************************************************************/
package org.eclipse.egit.core.internal.storage;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.util.Collections;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.egit.core.Activator;
+import org.eclipse.egit.core.op.ConnectProviderOperation;
+import org.eclipse.egit.core.op.DisconnectProviderOperation;
import org.eclipse.egit.core.test.GitTestCase;
+import org.eclipse.egit.core.test.TestProject;
+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.storage.file.FileRepository;
+import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.team.core.history.IFileHistory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -49,6 +67,43 @@ public class BlobStorageTest extends GitTestCase {
}
@Test
+ public void testGitFileHistorySingleProjectOk() throws Exception {
+ IProgressMonitor progress = new NullProgressMonitor();
+ TestProject singleRepoProject = new TestProject(true, "Project-2");
+ IProject proj = singleRepoProject.getProject();
+ File singleProjectGitDir = new File(proj.getLocation().toFile(), Constants.DOT_GIT);
+ if (singleProjectGitDir.exists())
+ FileUtils.delete(singleProjectGitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
+
+ Repository singleProjectRepo = new FileRepository(singleProjectGitDir);
+ singleProjectRepo.create();
+
+ // Repository must be mapped in order to test the GitFileHistory
+ Activator.getDefault().getRepositoryUtil().addConfiguredRepository(singleProjectGitDir);
+ ConnectProviderOperation connectOp = new ConnectProviderOperation(proj, singleProjectGitDir);
+ connectOp.execute(progress);
+
+ try {
+ IFile file = proj.getFile("file");
+ file.create(new ByteArrayInputStream("data".getBytes()), 0, progress);
+ Git git = new Git(singleProjectRepo);
+ git.add().addFilepattern(".").call();
+ RevCommit commit = git.commit().setAuthor("JUnit", "junit@jgit.org").setAll(true).setMessage("First commit").call();
+
+ GitFileHistoryProvider fhProvider = new GitFileHistoryProvider();
+ IFileHistory fh = fhProvider.getFileHistoryFor(singleRepoProject.getProject(), 0, null);
+ assertNotNull(fh);
+ assertEquals(fh.getFileRevisions().length, 1);
+ assertNotNull(fh.getFileRevision(commit.getId().getName()));
+ } finally {
+ DisconnectProviderOperation disconnectOp = new DisconnectProviderOperation(Collections.singletonList(proj));
+ disconnectOp.execute(progress);
+ Activator.getDefault().getRepositoryUtil().removeDir(singleProjectGitDir);
+ singleProjectRepo.close();
+ }
+ }
+
+ @Test
public void testFailNotFound() throws Exception {
BlobStorage blobStorage = new BlobStorage(repository, "file", ObjectId.fromString("0123456789012345678901234567890123456789"));
assertEquals("file", blobStorage.getName());
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/GitFileHistory.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/GitFileHistory.java
index 451ca85..5ee328d 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/GitFileHistory.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/GitFileHistory.java
@@ -66,9 +66,13 @@ class GitFileHistory extends FileHistory implements IAdaptable {
db = rm.getRepository();
walk = new KidWalk(db);
gitPath = rm.getRepoRelativePath(resource);
- walk.setTreeFilter(AndTreeFilter.create(PathFilterGroup
- .createFromStrings(Collections.singleton(gitPath)),
- TreeFilter.ANY_DIFF));
+ if(gitPath == null || gitPath.isEmpty()) {
+ walk.setTreeFilter(TreeFilter.ANY_DIFF);
+ } else {
+ walk.setTreeFilter(AndTreeFilter.create(PathFilterGroup
+ .createFromStrings(Collections.singleton(gitPath)),
+ TreeFilter.ANY_DIFF));
+ }
}
revisions = buildRevisions(monitor, flags);