aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java123
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java18
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java14
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java44
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogReaderTest.java14
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java132
13 files changed, 312 insertions, 54 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
index faaac55ea8..f66661a52f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
@@ -56,11 +56,11 @@ import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.dircache.DirCache;
-import org.eclipse.jgit.internal.storage.file.ReflogReader;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
+import org.eclipse.jgit.lib.ReflogReader;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.revwalk.RevCommit;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
index e5680273c0..79d8f60441 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
@@ -56,12 +56,12 @@ import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoMessageException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
-import org.eclipse.jgit.internal.storage.file.ReflogReader;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RefUpdate;
+import org.eclipse.jgit.lib.ReflogReader;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.FS;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
index abfbd1548d..56a1f38013 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com>
+ * Copyright (C) 2010, 2013 Chris Aniszczyk <caniszczyk@gmail.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -43,55 +43,154 @@
package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.net.URISyntaxException;
+import java.util.Collection;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.transport.FetchResult;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.jgit.transport.TagOpt;
+import org.eclipse.jgit.transport.TrackingRefUpdate;
import org.eclipse.jgit.transport.URIish;
+import org.junit.Before;
import org.junit.Test;
public class FetchCommandTest extends RepositoryTestCase {
- @Test
- public void testFetch() throws JGitInternalException, IOException,
- GitAPIException, URISyntaxException {
+ private Git git;
+ private Git remoteGit;
+
+ @Before
+ public void setupRemoteRepository() throws IOException, URISyntaxException {
+ git = new Git(db);
// create other repository
- Repository db2 = createWorkRepository();
- Git git2 = new Git(db2);
+ Repository remoteRepository = createWorkRepository();
+ remoteGit = new Git(remoteRepository);
// setup the first repository to fetch from the second repository
final StoredConfig config = db.getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
- URIish uri = new URIish(db2.getDirectory().toURI().toURL());
+ URIish uri = new URIish(remoteRepository.getDirectory().toURI().toURL());
remoteConfig.addURI(uri);
remoteConfig.update(config);
config.save();
+ }
- // create some refs via commits and tag
- RevCommit commit = git2.commit().setMessage("initial commit").call();
- Ref tagRef = git2.tag().setName("tag").call();
+ @Test
+ public void testFetch() throws JGitInternalException, IOException,
+ GitAPIException {
- Git git1 = new Git(db);
+ // create some refs via commits and tag
+ RevCommit commit = remoteGit.commit().setMessage("initial commit").call();
+ Ref tagRef = remoteGit.tag().setName("tag").call();
RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");
- git1.fetch().setRemote("test").setRefSpecs(spec)
+ git.fetch().setRemote("test").setRefSpecs(spec)
.call();
assertEquals(commit.getId(),
db.resolve(commit.getId().getName() + "^{commit}"));
assertEquals(tagRef.getObjectId(),
db.resolve(tagRef.getObjectId().getName()));
+ }
+
+ @Test
+ public void fetchShouldAutoFollowTag() throws Exception {
+ remoteGit.commit().setMessage("commit").call();
+ Ref tagRef = remoteGit.tag().setName("foo").call();
+
+ RefSpec spec = new RefSpec("refs/heads/*:refs/remotes/origin/*");
+ git.fetch().setRemote("test").setRefSpecs(spec)
+ .setTagOpt(TagOpt.AUTO_FOLLOW).call();
+
+ assertEquals(tagRef.getObjectId(), db.resolve("foo"));
+ }
+
+ @Test
+ public void fetchShouldAutoFollowTagForFetchedObjects() throws Exception {
+ remoteGit.commit().setMessage("commit").call();
+ Ref tagRef = remoteGit.tag().setName("foo").call();
+ remoteGit.commit().setMessage("commit2").call();
+ RefSpec spec = new RefSpec("refs/heads/*:refs/remotes/origin/*");
+ git.fetch().setRemote("test").setRefSpecs(spec)
+ .setTagOpt(TagOpt.AUTO_FOLLOW).call();
+ assertEquals(tagRef.getObjectId(), db.resolve("foo"));
+ }
+
+ @Test
+ public void fetchShouldNotFetchTagsFromOtherBranches() throws Exception {
+ remoteGit.commit().setMessage("commit").call();
+ remoteGit.checkout().setName("other").setCreateBranch(true).call();
+ remoteGit.commit().setMessage("commit2").call();
+ remoteGit.tag().setName("foo").call();
+ RefSpec spec = new RefSpec(
+ "refs/heads/master:refs/remotes/origin/master");
+ git.fetch().setRemote("test").setRefSpecs(spec)
+ .setTagOpt(TagOpt.AUTO_FOLLOW).call();
+ assertNull(db.resolve("foo"));
+ }
+
+ @Test
+ public void fetchWithUpdatedTagShouldNotTryToUpdateLocal() throws Exception {
+ final String tagName = "foo";
+ remoteGit.commit().setMessage("commit").call();
+ Ref tagRef = remoteGit.tag().setName(tagName).call();
+ ObjectId originalId = tagRef.getObjectId();
+
+ RefSpec spec = new RefSpec("refs/heads/*:refs/remotes/origin/*");
+ git.fetch().setRemote("test").setRefSpecs(spec)
+ .setTagOpt(TagOpt.AUTO_FOLLOW).call();
+ assertEquals(originalId, db.resolve(tagName));
+
+ remoteGit.commit().setMessage("commit 2").call();
+ remoteGit.tag().setName(tagName).setForceUpdate(true).call();
+ FetchResult result = git.fetch().setRemote("test").setRefSpecs(spec)
+ .setTagOpt(TagOpt.AUTO_FOLLOW).call();
+
+ Collection<TrackingRefUpdate> refUpdates = result
+ .getTrackingRefUpdates();
+ assertEquals(1, refUpdates.size());
+ TrackingRefUpdate update = refUpdates.iterator().next();
+ assertEquals("refs/heads/master", update.getRemoteName());
+
+ assertEquals(originalId, db.resolve(tagName));
}
+ @Test
+ public void fetchWithExplicitTagsShouldUpdateLocal() throws Exception {
+ final String tagName = "foo";
+ remoteGit.commit().setMessage("commit").call();
+ Ref tagRef1 = remoteGit.tag().setName(tagName).call();
+
+ RefSpec spec = new RefSpec("refs/heads/*:refs/remotes/origin/*");
+ git.fetch().setRemote("test").setRefSpecs(spec)
+ .setTagOpt(TagOpt.AUTO_FOLLOW).call();
+ assertEquals(tagRef1.getObjectId(), db.resolve(tagName));
+
+ remoteGit.commit().setMessage("commit 2").call();
+ Ref tagRef2 = remoteGit.tag().setName(tagName).setForceUpdate(true)
+ .call();
+
+ FetchResult result = git.fetch().setRemote("test").setRefSpecs(spec)
+ .setTagOpt(TagOpt.FETCH_TAGS).call();
+ TrackingRefUpdate update = result.getTrackingRefUpdate(Constants.R_TAGS
+ + tagName);
+ assertEquals(RefUpdate.Result.FORCED, update.getResult());
+ assertEquals(tagRef2.getObjectId(), db.resolve(tagName));
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java
index 318d1f98b9..b07c7033f5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java
@@ -47,10 +47,10 @@ import static org.junit.Assert.assertNotNull;
import java.util.Collection;
-import org.eclipse.jgit.internal.storage.file.ReflogEntry;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ReflogEntry;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Before;
import org.junit.Test;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
index 01aaa7bd71..bb3e7a92e8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
@@ -57,11 +57,11 @@ import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.dircache.DirCache;
-import org.eclipse.jgit.internal.storage.file.ReflogReader;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
+import org.eclipse.jgit.lib.ReflogReader;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.revwalk.RevCommit;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
index 322d47a091..030dc9f4a1 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
@@ -54,13 +54,13 @@ import java.util.List;
import org.eclipse.jgit.api.errors.UnmergedPathsException;
import org.eclipse.jgit.diff.DiffEntry;
-import org.eclipse.jgit.internal.storage.file.ReflogEntry;
-import org.eclipse.jgit.internal.storage.file.ReflogReader;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.ReflogEntry;
+import org.eclipse.jgit.lib.ReflogReader;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -442,7 +442,7 @@ public class StashCreateCommandTest extends RepositoryTestCase {
assertEquals("content", read(committedFile));
validateStashedCommit(stashed);
- ReflogReader reader = new ReflogReader(git.getRepository(),
+ ReflogReader reader = git.getRepository().getReflogReader(
Constants.R_STASH);
ReflogEntry entry = reader.getLastEntry();
assertNotNull(entry);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java
index 43f063f04d..cfad817d23 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java
@@ -52,12 +52,12 @@ import java.io.File;
import java.util.List;
import org.eclipse.jgit.api.errors.JGitInternalException;
-import org.eclipse.jgit.internal.storage.file.ReflogEntry;
-import org.eclipse.jgit.internal.storage.file.ReflogReader;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.ReflogEntry;
+import org.eclipse.jgit.lib.ReflogReader;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Before;
import org.junit.Test;
@@ -126,9 +126,9 @@ public class StashDropCommandTest extends RepositoryTestCase {
stashRef = git.getRepository().getRef(Constants.R_STASH);
assertNull(stashRef);
- ReflogReader reader = new ReflogReader(git.getRepository(),
+ ReflogReader reader = git.getRepository().getReflogReader(
Constants.R_STASH);
- assertTrue(reader.getReverseEntries().isEmpty());
+ assertNull(reader);
}
@Test
@@ -154,9 +154,9 @@ public class StashDropCommandTest extends RepositoryTestCase {
assertNull(git.stashDrop().setAll(true).call());
assertNull(git.getRepository().getRef(Constants.R_STASH));
- ReflogReader reader = new ReflogReader(git.getRepository(),
+ ReflogReader reader = git.getRepository().getReflogReader(
Constants.R_STASH);
- assertTrue(reader.getReverseEntries().isEmpty());
+ assertNull(reader);
}
@Test
@@ -184,7 +184,7 @@ public class StashDropCommandTest extends RepositoryTestCase {
assertNotNull(stashRef);
assertEquals(firstStash, stashRef.getObjectId());
- ReflogReader reader = new ReflogReader(git.getRepository(),
+ ReflogReader reader = git.getRepository().getReflogReader(
Constants.R_STASH);
List<ReflogEntry> entries = reader.getReverseEntries();
assertEquals(1, entries.size());
@@ -226,7 +226,7 @@ public class StashDropCommandTest extends RepositoryTestCase {
assertNotNull(stashRef);
assertEquals(thirdStash, stashRef.getObjectId());
- ReflogReader reader = new ReflogReader(git.getRepository(),
+ ReflogReader reader = git.getRepository().getReflogReader(
Constants.R_STASH);
List<ReflogEntry> entries = reader.getReverseEntries();
assertEquals(2, entries.size());
@@ -284,7 +284,7 @@ public class StashDropCommandTest extends RepositoryTestCase {
assertNotNull(stashRef);
assertEquals(thirdStash, stashRef.getObjectId());
- ReflogReader reader = new ReflogReader(git.getRepository(),
+ ReflogReader reader = git.getRepository().getReflogReader(
Constants.R_STASH);
List<ReflogEntry> entries = reader.getReverseEntries();
assertEquals(2, entries.size());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
index b9838b1712..061d29f502 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com>
+ * Copyright (C) 2010, 2013 Chris Aniszczyk <caniszczyk@gmail.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -81,6 +81,18 @@ public class TagCommandTest extends RepositoryTestCase {
}
@Test
+ public void testUnannotatedTagging() throws GitAPIException,
+ JGitInternalException {
+ Git git = new Git(db);
+ git.commit().setMessage("initial commit").call();
+ RevCommit commit = git.commit().setMessage("second commit").call();
+ git.commit().setMessage("third commit").call();
+ Ref tagRef = git.tag().setObjectId(commit).setName("tag")
+ .setAnnotated(false).call();
+ assertEquals(commit.getId(), tagRef.getObjectId());
+ }
+
+ @Test
public void testEmptyTagName() throws GitAPIException {
Git git = new Git(db);
git.commit().setMessage("initial commit").call();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
index 08e49d3dd5..21df179ad8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2008, Charles O'Farrell <charleso@charleso.org>
* Copyright (C) 2009-2010, Google Inc.
- * Copyright (C) 2008-2009, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2008-2013, Robin Rosenberg <robin.rosenberg@dewire.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -61,11 +61,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import org.eclipse.jgit.internal.storage.file.FileRepository;
-import org.eclipse.jgit.internal.storage.file.LockFile;
-import org.eclipse.jgit.internal.storage.file.RefDirectory;
-import org.eclipse.jgit.internal.storage.file.RefDirectoryUpdate;
-import org.eclipse.jgit.internal.storage.file.ReflogReader;
import org.eclipse.jgit.junit.SampleDataRepositoryTestCase;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
@@ -75,6 +70,8 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefRename;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RefUpdate.Result;
+import org.eclipse.jgit.lib.ReflogEntry;
+import org.eclipse.jgit.lib.ReflogReader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -127,14 +124,16 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
assertNotSame(newid, r.getObjectId());
assertSame(ObjectId.class, r.getObjectId().getClass());
assertEquals(newid, r.getObjectId());
- List<org.eclipse.jgit.internal.storage.file.ReflogEntry> reverseEntries1 = db.getReflogReader("refs/heads/abc").getReverseEntries();
- org.eclipse.jgit.internal.storage.file.ReflogEntry entry1 = reverseEntries1.get(0);
+ List<ReflogEntry> reverseEntries1 = db
+ .getReflogReader("refs/heads/abc").getReverseEntries();
+ ReflogEntry entry1 = reverseEntries1.get(0);
assertEquals(1, reverseEntries1.size());
assertEquals(ObjectId.zeroId(), entry1.getOldId());
assertEquals(r.getObjectId(), entry1.getNewId());
assertEquals(new PersonIdent(db).toString(), entry1.getWho().toString());
assertEquals("", entry1.getComment());
- List<org.eclipse.jgit.internal.storage.file.ReflogEntry> reverseEntries2 = db.getReflogReader("HEAD").getReverseEntries();
+ List<ReflogEntry> reverseEntries2 = db.getReflogReader("HEAD")
+ .getReverseEntries();
assertEquals(0, reverseEntries2.size());
}
@@ -285,6 +284,21 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
}
@Test
+ public void testDeleteWithoutHead() throws IOException {
+ // Prepare repository without HEAD
+ RefUpdate refUpdate = db.updateRef(Constants.HEAD, true);
+ refUpdate.setForceUpdate(true);
+ refUpdate.setNewObjectId(ObjectId.zeroId());
+ Result updateResult = refUpdate.update();
+ assertEquals(Result.FORCED, updateResult);
+ Result deleteHeadResult = db.updateRef(Constants.HEAD).delete();
+ assertEquals(Result.NO_CHANGE, deleteHeadResult);
+
+ // Any result is ok as long as it's not an NPE
+ db.updateRef(Constants.R_HEADS + "master").delete();
+ }
+
+ @Test
public void testRefKeySameAsName() {
Map<String, Ref> allRefs = db.getAllRefs();
for (Entry<String, Ref> e : allRefs.entrySet()) {
@@ -339,8 +353,8 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
// the branch HEAD referred to is left untouched
assertEquals(pid, db.resolve("refs/heads/master"));
- ReflogReader reflogReader = new ReflogReader(db, "HEAD");
- org.eclipse.jgit.internal.storage.file.ReflogEntry e = reflogReader.getReverseEntries().get(0);
+ ReflogReader reflogReader = db.getReflogReader("HEAD");
+ ReflogEntry e = reflogReader.getReverseEntries().get(0);
assertEquals(pid, e.getOldId());
assertEquals(ppid, e.getNewId());
assertEquals("GIT_COMMITTER_EMAIL", e.getWho().getEmailAddress());
@@ -369,8 +383,8 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
// the branch HEAD referred to is left untouched
assertNull(db.resolve("refs/heads/unborn"));
- ReflogReader reflogReader = new ReflogReader(db, "HEAD");
- org.eclipse.jgit.internal.storage.file.ReflogEntry e = reflogReader.getReverseEntries().get(0);
+ ReflogReader reflogReader = db.getReflogReader("HEAD");
+ ReflogEntry e = reflogReader.getReverseEntries().get(0);
assertEquals(ObjectId.zeroId(), e.getOldId());
assertEquals(ppid, e.getNewId());
assertEquals("GIT_COMMITTER_EMAIL", e.getWho().getEmailAddress());
@@ -706,9 +720,9 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
ObjectId oldfromId = db.resolve(fromName);
ObjectId oldHeadId = db.resolve(Constants.HEAD);
writeReflog(db, oldfromId, "Just a message", fromName);
- List<org.eclipse.jgit.internal.storage.file.ReflogEntry> oldFromLog = db
+ List<ReflogEntry> oldFromLog = db
.getReflogReader(fromName).getReverseEntries();
- List<org.eclipse.jgit.internal.storage.file.ReflogEntry> oldHeadLog = oldHeadId != null ? db
+ List<ReflogEntry> oldHeadLog = oldHeadId != null ? db
.getReflogReader(Constants.HEAD).getReverseEntries() : null;
assertTrue("internal check, we have a log", new File(db.getDirectory(),
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogReaderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogReaderTest.java
index 65367a8c18..a0dff7ee86 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogReaderTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogReaderTest.java
@@ -55,13 +55,13 @@ import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;
-import org.eclipse.jgit.internal.storage.file.CheckoutEntry;
-import org.eclipse.jgit.internal.storage.file.ReflogEntry;
-import org.eclipse.jgit.internal.storage.file.ReflogReader;
import org.eclipse.jgit.junit.SampleDataRepositoryTestCase;
+import org.eclipse.jgit.lib.CheckoutEntry;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.lib.ReflogEntry;
+import org.eclipse.jgit.lib.ReflogReader;
import org.junit.Test;
public class ReflogReaderTest extends SampleDataRepositoryTestCase {
@@ -97,7 +97,7 @@ public class ReflogReaderTest extends SampleDataRepositoryTestCase {
public void testReadOneLine() throws Exception {
setupReflog("logs/refs/heads/master", oneLine);
- ReflogReader reader = new ReflogReader(db, "refs/heads/master");
+ ReflogReader reader = new ReflogReaderImpl(db, "refs/heads/master");
ReflogEntry e = reader.getLastEntry();
assertEquals(ObjectId
.fromString("da85355dfc525c9f6f3927b876f379f46ccf826e"), e
@@ -124,7 +124,7 @@ public class ReflogReaderTest extends SampleDataRepositoryTestCase {
public void testReadTwoLine() throws Exception {
setupReflog("logs/refs/heads/master", twoLine);
- ReflogReader reader = new ReflogReader(db, "refs/heads/master");
+ ReflogReader reader = new ReflogReaderImpl(db, "refs/heads/master");
List<ReflogEntry> reverseEntries = reader.getReverseEntries();
assertEquals(2, reverseEntries.size());
ReflogEntry e = reverseEntries.get(0);
@@ -159,7 +159,7 @@ public class ReflogReaderTest extends SampleDataRepositoryTestCase {
@Test
public void testReadWhileAppendIsInProgress() throws Exception {
setupReflog("logs/refs/heads/master", twoLineWithAppendInProgress);
- ReflogReader reader = new ReflogReader(db, "refs/heads/master");
+ ReflogReader reader = new ReflogReaderImpl(db, "refs/heads/master");
List<ReflogEntry> reverseEntries = reader.getReverseEntries();
assertEquals(2, reverseEntries.size());
ReflogEntry e = reverseEntries.get(0);
@@ -236,7 +236,7 @@ public class ReflogReaderTest extends SampleDataRepositoryTestCase {
public void testSpecificEntryNumber() throws Exception {
setupReflog("logs/refs/heads/master", twoLine);
- ReflogReader reader = new ReflogReader(db, "refs/heads/master");
+ ReflogReader reader = new ReflogReaderImpl(db, "refs/heads/master");
ReflogEntry e = reader.getReverseEntry(0);
assertEquals(
ObjectId.fromString("c6734895958052a9dbc396cff4459dc1a25029ab"),
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java
index 1f70a71a11..05e552e419 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java
@@ -47,8 +47,10 @@ import static org.junit.Assert.assertNull;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.jgit.diff.DiffConfig;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.junit.TestRepository.CommitBuilder;
+import org.eclipse.jgit.lib.Config;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -74,7 +76,8 @@ public class RevWalkFollowFilterTest extends RevWalkTestCase {
}
protected FollowFilter follow(final String followPath) {
- FollowFilter followFilter = FollowFilter.create(followPath);
+ FollowFilter followFilter =
+ FollowFilter.create(followPath, new Config().get(DiffConfig.KEY));
followFilter.setRenameCallback(diffCollector);
rw.setTreeFilter(followFilter);
return followFilter;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java
index 479d9d304a..3e45d2eb9e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java
@@ -189,7 +189,7 @@ public class RevWalkShallowTest extends RevWalkTestCase {
final StringBuilder builder = new StringBuilder();
for (ObjectId commit : shallowCommits)
builder.append(commit.getName() + "\n");
- JGitTestUtil.write(new File(rw.repository.getDirectory(), "shallow"),
+ JGitTestUtil.write(new File(db.getDirectory(), "shallow"),
builder.toString());
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java
index 3cd01453a1..5c2f77c3c3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010, Matthias Sohn <matthias.sohn@sap.com>
+ * Copyright (C) 2010, 2013 Matthias Sohn <matthias.sohn@sap.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -119,6 +119,121 @@ public class FileUtilTest {
}
@Test
+
+ public void testDeleteRecursiveEmpty() throws IOException {
+ File f1 = new File(trash, "test/test/a");
+ File f2 = new File(trash, "test/a");
+ File d1 = new File(trash, "test");
+ File d2 = new File(trash, "test/test");
+ File d3 = new File(trash, "test/b");
+ FileUtils.mkdirs(f1.getParentFile());
+ FileUtils.createNewFile(f2);
+ FileUtils.createNewFile(f1);
+ FileUtils.mkdirs(d3);
+
+ // Cannot delete hierarchy since files exist
+ try {
+ FileUtils.delete(d1, FileUtils.EMPTY_DIRECTORIES_ONLY);
+ fail("delete should fail");
+ } catch (IOException e1) {
+ try {
+ FileUtils.delete(d1, FileUtils.EMPTY_DIRECTORIES_ONLY|FileUtils.RECURSIVE);
+ fail("delete should fail");
+ } catch (IOException e2) {
+ // Everything still there
+ assertTrue(f1.exists());
+ assertTrue(f2.exists());
+ assertTrue(d1.exists());
+ assertTrue(d2.exists());
+ assertTrue(d3.exists());
+ }
+ }
+
+ // setup: delete files, only directories left
+ assertTrue(f1.delete());
+ assertTrue(f2.delete());
+
+ // Shall not delete hierarchy without recursive
+ try {
+ FileUtils.delete(d1, FileUtils.EMPTY_DIRECTORIES_ONLY);
+ fail("delete should fail");
+ } catch (IOException e2) {
+ // Everything still there
+ assertTrue(d1.exists());
+ assertTrue(d2.exists());
+ assertTrue(d3.exists());
+ }
+
+ // Now delete the empty hierarchy
+ FileUtils.delete(d2, FileUtils.EMPTY_DIRECTORIES_ONLY
+ | FileUtils.RECURSIVE);
+ assertFalse(d2.exists());
+
+ // Will fail to delete non-existing without SKIP_MISSING
+ try {
+ FileUtils.delete(d2, FileUtils.EMPTY_DIRECTORIES_ONLY);
+ fail("Cannot delete non-existent entity");
+ } catch (IOException e) {
+ // ok
+ }
+
+ // ..with SKIP_MISSING there is no exception
+ FileUtils.delete(d2, FileUtils.EMPTY_DIRECTORIES_ONLY
+ | FileUtils.SKIP_MISSING);
+ FileUtils.delete(d2, FileUtils.EMPTY_DIRECTORIES_ONLY
+ | FileUtils.RECURSIVE | FileUtils.SKIP_MISSING);
+
+ // essentially the same, using IGNORE_ERRORS
+ FileUtils.delete(d2, FileUtils.EMPTY_DIRECTORIES_ONLY
+ | FileUtils.IGNORE_ERRORS);
+ FileUtils.delete(d2, FileUtils.EMPTY_DIRECTORIES_ONLY
+ | FileUtils.RECURSIVE | FileUtils.IGNORE_ERRORS);
+ }
+
+ @Test
+ public void testDeleteRecursiveEmptyNeedsToCheckFilesFirst()
+ throws IOException {
+ File d1 = new File(trash, "test");
+ File d2 = new File(trash, "test/a");
+ File d3 = new File(trash, "test/b");
+ File f1 = new File(trash, "test/c");
+ File d4 = new File(trash, "test/d");
+ FileUtils.mkdirs(d1);
+ FileUtils.mkdirs(d2);
+ FileUtils.mkdirs(d3);
+ FileUtils.mkdirs(d4);
+ FileUtils.createNewFile(f1);
+
+ // Cannot delete hierarchy since file exists
+ try {
+ FileUtils.delete(d1, FileUtils.EMPTY_DIRECTORIES_ONLY
+ | FileUtils.RECURSIVE);
+ fail("delete should fail");
+ } catch (IOException e) {
+ // Everything still there
+ assertTrue(f1.exists());
+ assertTrue(d1.exists());
+ assertTrue(d2.exists());
+ assertTrue(d3.exists());
+ assertTrue(d4.exists());
+ }
+ }
+
+ @Test
+ public void testDeleteRecursiveEmptyDirectoriesOnlyButIsFile()
+ throws IOException {
+ File f1 = new File(trash, "test/test/a");
+ FileUtils.mkdirs(f1.getParentFile());
+ FileUtils.createNewFile(f1);
+ try {
+ FileUtils.delete(f1, FileUtils.EMPTY_DIRECTORIES_ONLY);
+ fail("delete should fail");
+ } catch (IOException e) {
+ assertTrue(f1.exists());
+ }
+ }
+
+ @Test
public void testMkdir() throws IOException {
File d = new File(trash, "test");
FileUtils.mkdir(d);
@@ -305,4 +420,19 @@ public class FileUtilTest {
assertTrue(f2.exists());
assertEquals("f1", JGitTestUtil.read(f2));
}
+
+ @Test
+ public void testCreateSymlink() throws IOException {
+ FS fs = FS.DETECTED;
+ try {
+ fs.createSymLink(new File(trash, "x"), "y");
+ } catch (IOException e) {
+ if (fs.supportsSymlinks())
+ fail("FS claims to support symlinks but attempt to create symlink failed");
+ return;
+ }
+ assertTrue(fs.supportsSymlinks());
+ String target = fs.readSymLink(new File(trash, "x"));
+ assertEquals("y", target);
+ }
}