use of org.eclipse.jgit.transport.RemoteRefUpdate in project gerrit by GerritCodeReview.
the class AbstractPushForReview method errorMessageFormat.
@Test
public void errorMessageFormat() throws Exception {
RevCommit c = createCommit(testRepo, "Message without Change-Id");
assertThat(GitUtil.getChangeId(testRepo, c)).isEmpty();
String ref = "refs/for/master";
PushResult r = pushHead(testRepo, ref);
RemoteRefUpdate refUpdate = r.getRemoteUpdate(ref);
assertThat(refUpdate.getStatus()).isEqualTo(RemoteRefUpdate.Status.REJECTED_OTHER_REASON);
String reason = String.format("commit %s: missing Change-Id in message footer", abbreviateName(c));
assertThat(refUpdate.getMessage()).isEqualTo(reason);
assertThat(r.getMessages()).contains("\nERROR: " + reason);
}
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 += "%topic=" + 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 AccountIT method deleteUserBranchWithAccessDatabaseCapability.
@Test
public void deleteUserBranchWithAccessDatabaseCapability() throws Exception {
projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
projectOperations.project(allUsers).forUpdate().add(allow(Permission.DELETE).ref(RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}").group(REGISTERED_USERS).force(true)).update();
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();
}
assertThat(accountCache.get(admin.id())).isEmpty();
assertThat(accountQueryProvider.get().byDefault(admin.id().toString(), true)).isEmpty();
}
use of org.eclipse.jgit.transport.RemoteRefUpdate in project gerrit by GerritCodeReview.
the class AccountIT method cannotDeleteUserBranch.
@Test
public void cannotDeleteUserBranch() throws Exception {
projectOperations.project(allUsers).forUpdate().add(allow(Permission.DELETE).ref(RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}").group(REGISTERED_USERS).force(true)).update();
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();
}
}
Aggregations