use of org.eclipse.jgit.transport.PushResult in project gitblit by gitblit.
the class TicketReferenceTest method assertForcePushSuccess.
private void assertForcePushSuccess(String commitSha, String branchName) throws Exception {
Iterable<PushResult> results = git.push().setForce(true).setRemote("origin").setCredentialsProvider(cp).call();
for (PushResult result : results) {
RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/" + branchName);
assertEquals(Status.OK, ref.getStatus());
assertEquals(commitSha, ref.getNewObjectId().name());
}
}
use of org.eclipse.jgit.transport.PushResult in project gitblit by gitblit.
the class TicketReferenceTest method configure.
@BeforeClass
public static void configure() throws Exception {
File repositoryName = new File("TicketReferenceTest.git");
;
GitBlitSuite.close(repositoryName);
if (repositoryName.exists()) {
FileUtils.delete(repositoryName, FileUtils.RECURSIVE | FileUtils.RETRY);
}
repo = new RepositoryModel("TicketReferenceTest.git", null, null, null);
if (gitblit().hasRepository(repo.name)) {
gitblit().deleteRepositoryModel(repo);
}
gitblit().updateRepositoryModel(repo.name, repo, true);
user = new UserModel(account);
user.displayName = account;
user.emailAddress = account + "@example.com";
user.password = password;
cp = new UsernamePasswordCredentialsProvider(user.username, user.password);
if (gitblit().getUserModel(user.username) != null) {
gitblit().deleteUser(user.username);
}
repo.authorizationControl = AuthorizationControl.NAMED;
repo.accessRestriction = AccessRestrictionType.PUSH;
gitblit().updateRepositoryModel(repo.name, repo, false);
// grant user push permission
user.setRepositoryPermission(repo.name, AccessPermission.REWIND);
gitblit().updateUserModel(user);
ticketService = gitblit().getTicketService();
assertTrue(ticketService.deleteAll(repo));
GitBlitSuite.close(workingCopy);
if (workingCopy.exists()) {
FileUtils.delete(workingCopy, FileUtils.RECURSIVE | FileUtils.RETRY);
}
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/{1}", url, repo.name));
clone.setDirectory(workingCopy);
clone.setBare(false);
clone.setBranch("master");
clone.setCredentialsProvider(cp);
GitBlitSuite.close(clone.call());
git = Git.open(workingCopy);
git.getRepository().getConfig().setString("user", null, "name", user.displayName);
git.getRepository().getConfig().setString("user", null, "email", user.emailAddress);
git.getRepository().getConfig().save();
final RevCommit revCommit1 = makeCommit("initial commit");
final String initialSha = revCommit1.name();
Iterable<PushResult> results = git.push().setPushAll().setCredentialsProvider(cp).call();
GitBlitSuite.close(git);
for (PushResult result : results) {
for (RemoteRefUpdate update : result.getRemoteUpdates()) {
assertEquals(Status.OK, update.getStatus());
assertEquals(initialSha, update.getNewObjectId().name());
}
}
}
use of org.eclipse.jgit.transport.PushResult 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.PushResult 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.PushResult in project gerrit by GerritCodeReview.
the class ChangeIT method changeNoParentToOneParent.
@Test
@TestProjectInput(createEmptyCommit = false)
public void changeNoParentToOneParent() throws Exception {
// create initial commit with no parent and push it as change, so that patch
// set 1 has no parent
RevCommit c = testRepo.commit().message("Initial commit").insertChangeId().create();
String id = GitUtil.getChangeId(testRepo, c).get();
testRepo.reset(c);
PushResult pr = pushHead(testRepo, "refs/for/master", false);
assertPushOk(pr, "refs/for/master");
ChangeInfo change = gApi.changes().id(id).get();
assertThat(change.revisions.get(change.currentRevision).commit.parents).isEmpty();
// create another initial commit with no parent and push it directly into
// the remote repository
c = testRepo.amend(c.getId()).message("Initial Empty Commit").create();
testRepo.reset(c);
pr = pushHead(testRepo, "refs/heads/master", false);
assertPushOk(pr, "refs/heads/master");
// create a successor commit and push it as second patch set to the change,
// so that patch set 2 has 1 parent
RevCommit c2 = testRepo.commit().message("Initial commit").parent(c).insertChangeId(id.substring(1)).create();
testRepo.reset(c2);
pr = pushHead(testRepo, "refs/for/master", false);
assertPushOk(pr, "refs/for/master");
change = gApi.changes().id(id).get();
RevisionInfo rev = change.revisions.get(change.currentRevision);
assertThat(rev.commit.parents).hasSize(1);
assertThat(rev.commit.parents.get(0).commit).isEqualTo(c.name());
// check that change kind is correctly detected as REWORK
assertThat(rev.kind).isEqualTo(ChangeKind.REWORK);
}
Aggregations