diff options
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java | 22 | ||||
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java | 27 |
2 files changed, 37 insertions, 12 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java index 42c8a92b93..100b758e65 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java @@ -1,4 +1,5 @@ /* + * Copyright (C) 2009-2010, Google Inc. * Copyright (C) 2009, Robin Rosenberg * Copyright (C) 2009, Robin Rosenberg <robin.rosenberg@dewire.com> * and other copyright owners as documented in the project's IP log. @@ -58,15 +59,26 @@ import org.eclipse.jgit.lib.RefUpdate.Result; */ public class RefTest extends SampleDataRepositoryTestCase { + private void writeSymref(String src, String dst) throws IOException { + RefUpdate u = db.updateRef(src); + switch (u.link(dst)) { + case NEW: + case FORCED: + case NO_CHANGE: + break; + default: + fail("link " + src + " to " + dst); + } + } + public void testReadAllIncludingSymrefs() throws Exception { ObjectId masterId = db.resolve("refs/heads/master"); RefUpdate updateRef = db.updateRef("refs/remotes/origin/master"); updateRef.setNewObjectId(masterId); updateRef.setForceUpdate(true); updateRef.update(); - db - .writeSymref("refs/remotes/origin/HEAD", - "refs/remotes/origin/master"); + writeSymref("refs/remotes/origin/HEAD", + "refs/remotes/origin/master"); ObjectId r = db.resolve("refs/remotes/origin/HEAD"); assertEquals(masterId, r); @@ -85,7 +97,7 @@ public class RefTest extends SampleDataRepositoryTestCase { } public void testReadSymRefToPacked() throws IOException { - db.writeSymref("HEAD", "refs/heads/b"); + writeSymref("HEAD", "refs/heads/b"); Ref ref = db.getRef("HEAD"); assertEquals(Ref.Storage.LOOSE, ref.getStorage()); assertTrue("is symref", ref.isSymbolic()); @@ -102,7 +114,7 @@ public class RefTest extends SampleDataRepositoryTestCase { Result update = updateRef.update(); assertEquals(Result.FORCED, update); // internal - db.writeSymref("HEAD", "refs/heads/master"); + writeSymref("HEAD", "refs/heads/master"); Ref ref = db.getRef("HEAD"); assertEquals(Ref.Storage.LOOSE, ref.getStorage()); ref = ref.getTarget(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java index cb9111758a..c8a5b33f68 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java @@ -1,5 +1,6 @@ /* * 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> * and other copyright owners as documented in the project's IP log. * @@ -56,6 +57,18 @@ import org.eclipse.jgit.revwalk.RevWalk; public class RefUpdateTest extends SampleDataRepositoryTestCase { + private void writeSymref(String src, String dst) throws IOException { + RefUpdate u = db.updateRef(src); + switch (u.link(dst)) { + case NEW: + case FORCED: + case NO_CHANGE: + break; + default: + fail("link " + src + " to " + dst); + } + } + private RefUpdate updateRef(final String name) throws IOException { final RefUpdate ref = db.updateRef(name); ref.setNewObjectId(db.resolve(Constants.HEAD)); @@ -328,7 +341,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { */ public void testUpdateRefDetachedUnbornHead() throws Exception { ObjectId ppid = db.resolve("refs/heads/master^"); - db.writeSymref("HEAD", "refs/heads/unborn"); + writeSymref("HEAD", "refs/heads/unborn"); RefUpdate updateRef = db.updateRef("HEAD", true); updateRef.setForceUpdate(true); updateRef.setNewObjectId(ppid); @@ -437,7 +450,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { // Do not use the defalt repo for this case. Map<String, Ref> allRefs = db.getAllRefs(); ObjectId oldValue = db.resolve("HEAD"); - db.writeSymref(Constants.HEAD, "refs/heads/newref"); + writeSymref(Constants.HEAD, "refs/heads/newref"); RefUpdate updateRef = db.updateRef(Constants.HEAD); updateRef.setForceUpdate(true); updateRef.setNewObjectId(oldValue); @@ -601,7 +614,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { public void testRenameCurrentBranch() throws IOException { ObjectId rb = db.resolve("refs/heads/b"); - db.writeSymref(Constants.HEAD, "refs/heads/b"); + writeSymref(Constants.HEAD, "refs/heads/b"); ObjectId oldHead = db.resolve(Constants.HEAD); assertTrue("internal test condition, b == HEAD", rb.equals(oldHead)); writeReflog(db, rb, rb, "Just a message", "refs/heads/b"); @@ -659,7 +672,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { public void tryRenameWhenLocked(String toLock, String fromName, String toName, String headPointsTo) throws IOException { // setup - db.writeSymref(Constants.HEAD, headPointsTo); + writeSymref(Constants.HEAD, headPointsTo); ObjectId oldfromId = db.resolve(fromName); ObjectId oldHeadId = db.resolve(Constants.HEAD); writeReflog(db, oldfromId, oldfromId, "Just a message", @@ -753,7 +766,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { public void testRenameRefNameColission1avoided() throws IOException { // setup ObjectId rb = db.resolve("refs/heads/b"); - db.writeSymref(Constants.HEAD, "refs/heads/a"); + writeSymref(Constants.HEAD, "refs/heads/a"); RefUpdate updateRef = db.updateRef("refs/heads/a"); updateRef.setNewObjectId(rb); updateRef.setRefLogMessage("Setup", false); @@ -785,7 +798,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { public void testRenameRefNameColission2avoided() throws IOException { // setup ObjectId rb = db.resolve("refs/heads/b"); - db.writeSymref(Constants.HEAD, "refs/heads/prefix/a"); + writeSymref(Constants.HEAD, "refs/heads/prefix/a"); RefUpdate updateRef = db.updateRef("refs/heads/prefix/a"); updateRef.setNewObjectId(rb); updateRef.setRefLogMessage("Setup", false); @@ -823,6 +836,6 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { RefDirectoryUpdate update = refs.newUpdate(refName, true); update.setOldObjectId(oldId); update.setNewObjectId(newId); - refs.log(update, msg); + refs.log(update, msg, true); } } |