Merge test will be performed according to {@link #isForceUpdate()}.
This is the same as:
return update(new RevWalk(getRepository()));
423424425426427428429430431432433
@Test public void testUpdateRefNoChange() throws IOException { ObjectId pid = db.resolve("refs/heads/master"); RefUpdate updateRef = db.updateRef("refs/heads/master"); updateRef.setNewObjectId(pid); Result update = updateRef.update(); assertEquals(Result.NO_CHANGE, update); assertEquals(pid, db.resolve("refs/heads/master")); } /**
448449450451452453454455456457458
ObjectId newValue = db.resolve("HEAD^"); // first make HEAD refer to loose ref RefUpdate updateRef = db.updateRef(Constants.HEAD); updateRef.setForceUpdate(true); updateRef.setNewObjectId(newValue); Result update = updateRef.update(); assertEquals(Result.FORCED, update); // now update that ref updateRef = db.updateRef(Constants.HEAD); updateRef.setNewObjectId(oldValue);
454455456457458459460461462463464
assertEquals(Result.FORCED, update); // now update that ref updateRef = db.updateRef(Constants.HEAD); updateRef.setNewObjectId(oldValue); update = updateRef.update(); assertEquals(Result.FAST_FORWARD, update); allRefs = db.getAllRefs(); Ref master = allRefs.get("refs/heads/master"); Ref head = allRefs.get("HEAD");
484485486487488489490491492493494
ObjectId oldValue = db.resolve("HEAD"); writeSymref(Constants.HEAD, "refs/heads/newref"); RefUpdate updateRef = db.updateRef(Constants.HEAD); updateRef.setForceUpdate(true); updateRef.setNewObjectId(oldValue); Result update = updateRef.update(); assertEquals(Result.NEW, update); allRefs = db.getAllRefs(); Ref head = allRefs.get("HEAD"); Ref newref = allRefs.get("refs/heads/newref");
507508509510511512513514515516517
public void testUpdateRefLockFailureWrongOldValue() throws IOException { ObjectId pid = db.resolve("refs/heads/master"); RefUpdate updateRef = db.updateRef("refs/heads/master"); updateRef.setNewObjectId(pid); updateRef.setExpectedOldObjectId(db.resolve("refs/heads/master^")); Result update = updateRef.update(); assertEquals(Result.LOCK_FAILURE, update); assertEquals(pid, db.resolve("refs/heads/master")); } /**
525526527528529530531532533534535
ObjectId pid = db.resolve("refs/heads/master"); RefUpdate updateRef = db.updateRef("refs/heads/master"); updateRef.setNewObjectId(ppid); updateRef.setForceUpdate(true); Result update = updateRef.update(); assertEquals(Result.FORCED, update); assertEquals(ppid, db.resolve("refs/heads/master")); // real test RefUpdate updateRef2 = db.updateRef("refs/heads/master");
533534535536537538539540541542543
// real test RefUpdate updateRef2 = db.updateRef("refs/heads/master"); updateRef2.setExpectedOldObjectId(ppid); updateRef2.setNewObjectId(pid); Result update2 = updateRef2.update(); assertEquals(Result.FAST_FORWARD, update2); assertEquals(pid, db.resolve("refs/heads/master")); } /**
551552553554555556557558559560561
ObjectId pid = db.resolve("refs/heads/master"); RefUpdate updateRef = db.updateRef("refs/heads/master"); updateRef.setNewObjectId(ppid); updateRef.setForceUpdate(true); Result update = updateRef.update(); assertEquals(Result.FORCED, update); assertEquals(ppid, db.resolve("refs/heads/master")); // real test RevCommit old = new RevWalk(db).parseCommit(ppid);
560561562563564565566567568569570
// real test RevCommit old = new RevWalk(db).parseCommit(ppid); RefUpdate updateRef2 = db.updateRef("refs/heads/master"); updateRef2.setExpectedOldObjectId(old); updateRef2.setNewObjectId(pid); Result update2 = updateRef2.update(); assertEquals(Result.FAST_FORWARD, update2); assertEquals(pid, db.resolve("refs/heads/master")); } /**
580581582583584585586587588589590
updateRef.setNewObjectId(pid); LockFile lockFile1 = new LockFile(new File(db.getDirectory(), "refs/heads/master"), db.getFS()); try { assertTrue(lockFile1.lock()); // precondition to test Result update = updateRef.update(); assertEquals(Result.LOCK_FAILURE, update); assertEquals(opid, db.resolve("refs/heads/master")); LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"), db.getFS()); assertFalse(lockFile2.lock()); // was locked, still is