TestRepository: Add delete() method

Change-Id: Ib4841397ceab44bd38cf2f154314ac36ded73ae0
This commit is contained in:
Jonathan Nieder 2016-05-04 15:48:36 -07:00
parent e89393ba3e
commit bc9df9c63c
1 changed files with 34 additions and 0 deletions

View File

@ -586,6 +586,31 @@ public <T extends AnyObjectId> T update(String ref, T obj) throws Exception {
}
}
/**
* Delete a reference.
*
* @param ref
* the name of the reference to delete. This is normalized
* in the same way as {@link #update(String, T)}.
* @throws Exception
* @since 4.4
*/
public void delete(String ref) throws Exception {
ref = normalizeRef(ref);
RefUpdate u = db.updateRef(ref);
switch (u.delete()) {
case FAST_FORWARD:
case FORCED:
case NEW:
case NO_CHANGE:
updateServerInfo();
return;
default:
throw new IOException("Cannot delete " + ref + " " + u.getResult());
}
}
private static String normalizeRef(String ref) {
if (Constants.HEAD.equals(ref)) {
// nothing
@ -959,6 +984,15 @@ public RevCommit update(CommitBuilder to) throws Exception {
public RevCommit update(RevCommit to) throws Exception {
return TestRepository.this.update(ref, to);
}
/**
* Delete this branch.
* @throws Exception
* @since 4.4
*/
public void delete() throws Exception {
TestRepository.this.delete(ref);
}
}
/** Helper to generate a commit. */