aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-01-09 18:56:45 -0800
committerShawn O. Pearce <spearce@spearce.org>2010-01-23 11:10:56 -0800
commit73b6efc9289d6f7b6c147f4c2e2c62d2134fd7f3 (patch)
treecac4f5481cabdbcb25a16e04df83917b22d462a4 /org.eclipse.jgit.test/tst/org/eclipse
parent01b5392cdbc12ce2e21fd1d1afbd61fdf97e1c38 (diff)
downloadjgit-73b6efc9289d6f7b6c147f4c2e2c62d2134fd7f3.tar.gz
jgit-73b6efc9289d6f7b6c147f4c2e2c62d2134fd7f3.zip
Replace writeSymref with RefUpdate.link
By using RefUpdate for symbolic reference creation we can reuse the logic related to updating the reflog with the event, without needing to expose something such as the legacy ReflogWriter class (which we no longer have). Applications using writeSymref must update their code to use the new pattern of changing the reference through the updateRef method: String refName = "refs/heads/master"; RefUpdate u = repository.updateRef(Constants.HEAD); u.setRefLogMessage("checkout: moving to " + refName, false); switch (u.link(refName)) { case NEW: case FORCED: case NO_CHANGE: // A successful update of the reference break; default: // Handle the failure, e.g. for older behavior throw new IOException(u.getResult()); } Change-Id: I1093e1ec2970147978a786cfdd0a75d0aebf8010 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java22
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java27
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);
}
}