use of org.eclipse.jgit.transport.RemoteRefUpdate in project gerrit by GerritCodeReview.
the class AccountIT method deleteUserBranchWithAccessDatabaseCapability.
@Test
@Sandboxed
public void deleteUserBranchWithAccessDatabaseCapability() throws Exception {
allowGlobalCapabilities(REGISTERED_USERS, GlobalCapability.ACCESS_DATABASE);
grant(allUsers, RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", Permission.DELETE, true, REGISTERED_USERS);
TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
String userRef = RefNames.refsUsers(admin.id);
PushResult r = deleteRef(allUsersRepo, userRef);
RemoteRefUpdate refUpdate = r.getRemoteUpdate(userRef);
assertThat(refUpdate.getStatus()).isEqualTo(RemoteRefUpdate.Status.OK);
try (Repository repo = repoManager.openRepository(allUsers)) {
assertThat(repo.exactRef(userRef)).isNull();
}
// TODO(ekempin): assert that account was deleted from cache and index
}
use of org.eclipse.jgit.transport.RemoteRefUpdate in project gerrit by GerritCodeReview.
the class AccountIT method cannotDeleteUserBranch.
@Test
@Sandboxed
public void cannotDeleteUserBranch() throws Exception {
grant(allUsers, RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", Permission.DELETE, true, REGISTERED_USERS);
TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
String userRef = RefNames.refsUsers(admin.id);
PushResult r = deleteRef(allUsersRepo, userRef);
RemoteRefUpdate refUpdate = r.getRemoteUpdate(userRef);
assertThat(refUpdate.getStatus()).isEqualTo(RemoteRefUpdate.Status.REJECTED_OTHER_REASON);
assertThat(refUpdate.getMessage()).contains("Not allowed to delete user branch.");
try (Repository repo = repoManager.openRepository(allUsers)) {
assertThat(repo.exactRef(userRef)).isNotNull();
}
}
use of org.eclipse.jgit.transport.RemoteRefUpdate in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushForReview.
private static void pushForReview(TestRepository<?> testRepo, RemoteRefUpdate.Status expectedStatus, String expectedMessage) throws GitAPIException {
String ref = "refs/for/master";
PushResult r = pushHead(testRepo, ref);
RemoteRefUpdate refUpdate = r.getRemoteUpdate(ref);
assertThat(refUpdate.getStatus()).isEqualTo(expectedStatus);
if (expectedMessage != null) {
assertThat(refUpdate.getMessage()).contains(expectedMessage);
}
}
use of org.eclipse.jgit.transport.RemoteRefUpdate in project gerrit by GerritCodeReview.
the class AbstractSubmoduleSubscription method pushChangeTo.
protected ObjectId pushChangeTo(TestRepository<?> repo, String ref, String file, String content, String message, String topic) throws Exception {
ObjectId ret = repo.branch("HEAD").commit().insertChangeId().message(message).add(file, content).create();
String pushedRef = ref;
if (!topic.isEmpty()) {
pushedRef += "/" + name(topic);
}
String refspec = "HEAD:" + pushedRef;
Iterable<PushResult> res = repo.git().push().setRemote("origin").setRefSpecs(new RefSpec(refspec)).call();
RemoteRefUpdate u = Iterables.getOnlyElement(res).getRemoteUpdate(pushedRef);
assertThat(u).isNotNull();
assertThat(u.getStatus()).isEqualTo(Status.OK);
assertThat(u.getNewObjectId()).isEqualTo(ret);
return ret;
}
use of org.eclipse.jgit.transport.RemoteRefUpdate in project gerrit by GerritCodeReview.
the class PushTagIT method pushTag.
private String pushTag(TagType tagType, String tagName, boolean newCommit, boolean force, Status expectedStatus) throws Exception {
if (force) {
testRepo.reset(initialHead);
}
commit(user.getIdent(), "subject");
boolean createTag = tagName == null;
tagName = MoreObjects.firstNonNull(tagName, "v1_" + System.nanoTime());
switch(tagType) {
case LIGHTWEIGHT:
break;
case ANNOTATED:
if (createTag) {
createAnnotatedTag(testRepo, tagName, user.getIdent());
} else {
updateAnnotatedTag(testRepo, tagName, user.getIdent());
}
break;
default:
throw new IllegalStateException("unexpected tag type: " + tagType);
}
if (!newCommit) {
grant(project, "refs/for/refs/heads/master", Permission.SUBMIT, false, REGISTERED_USERS);
pushHead(testRepo, "refs/for/master%submit");
}
String tagRef = tagRef(tagName);
PushResult r = tagType == LIGHTWEIGHT ? pushHead(testRepo, tagRef, false, force) : GitUtil.pushTag(testRepo, tagName, !createTag);
RemoteRefUpdate refUpdate = r.getRemoteUpdate(tagRef);
assertThat(refUpdate.getStatus()).named(tagType.name()).isEqualTo(expectedStatus);
return tagName;
}
Aggregations