use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class PRED_change_branch_1 method exec.
@Override
public Operation exec(Prolog engine) throws PrologException {
engine.setB0();
Term a1 = arg1.dereference();
BranchNameKey name = StoredValues.getChange(engine).getDest();
if (!a1.unify(SymbolTerm.create(name.branch()), engine.trail)) {
return engine.fail();
}
return cont;
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class AbstractSubmitByRebase method submitChangesAfterBranchOnSecond.
@Test
public void submitChangesAfterBranchOnSecond() throws Throwable {
RevCommit initialHead = projectOperations.project(project).getHead("master");
PushOneCommit.Result change = createChange();
approve(change.getChangeId());
PushOneCommit.Result change2 = createChange();
approve(change2.getChangeId());
Project.NameKey project = change2.getChange().change().getProject();
BranchNameKey branch = BranchNameKey.create(project, "branch");
createBranchWithRevision(branch, change2.getCommit().getName());
gApi.changes().id(change2.getChangeId()).current().submit();
assertMerged(change2.getChangeId());
assertMerged(change.getChangeId());
RevCommit newHead = projectOperations.project(this.project).getHead("master");
assertRefUpdatedEvents(initialHead, newHead);
assertChangeMergedEvents(change.getChangeId(), newHead.name(), change2.getChangeId(), newHead.name());
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class ReceiveCommits method parseCreate.
private void parseCreate(ReceiveCommand cmd) throws PermissionBackendException, NoSuchProjectException, IOException {
try (TraceTimer traceTimer = newTimer("parseCreate")) {
if (repo.resolve(cmd.getRefName()) != null) {
reject(cmd, String.format("Cannot create ref '%s' because it already exists.", cmd.getRefName()));
return;
}
RevObject obj;
try {
obj = receivePack.getRevWalk().parseAny(cmd.getNewId());
} catch (IOException e) {
throw new StorageException(String.format("Invalid object %s for %s creation", cmd.getNewId().name(), cmd.getRefName()), e);
}
logger.atFine().log("Creating %s", cmd);
if (isHead(cmd) && !isCommit(cmd)) {
return;
}
BranchNameKey branch = BranchNameKey.create(project.getName(), cmd.getRefName());
try {
// Must pass explicit user instead of injecting a provider into CreateRefControl, since
// Provider<CurrentUser> within ReceiveCommits will always return anonymous.
createRefControl.checkCreateRef(Providers.of(user), receivePack.getRepository(), branch, obj);
} catch (AuthException denied) {
rejectProhibited(cmd, denied);
return;
} catch (ResourceConflictException denied) {
reject(cmd, "prohibited by Gerrit: " + denied.getMessage());
return;
}
if (validRefOperation(cmd)) {
validateRegularPushCommits(BranchNameKey.create(project.getNameKey(), cmd.getRefName()), cmd);
}
}
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class Move method apply.
@Override
public Response<ChangeInfo> apply(ChangeResource rsrc, MoveInput input) throws RestApiException, UpdateException, PermissionBackendException, IOException {
if (!moveEnabled) {
// behavior. See: https://bugs.chromium.org/p/gerrit/issues/detail?id=9877
throw new MethodNotAllowedException("move changes endpoint is disabled");
}
Change change = rsrc.getChange();
Project.NameKey project = rsrc.getProject();
IdentifiedUser caller = rsrc.getUser().asIdentifiedUser();
if (input.destinationBranch == null) {
throw new BadRequestException("destination branch is required");
}
input.destinationBranch = RefNames.fullName(input.destinationBranch);
if (!change.isNew()) {
throw new ResourceConflictException("Change is " + ChangeUtil.status(change));
}
BranchNameKey newDest = BranchNameKey.create(project, input.destinationBranch);
if (change.getDest().equals(newDest)) {
throw new ResourceConflictException("Change is already destined for the specified branch");
}
// Not allowed to move if the current patch set is locked.
psUtil.checkPatchSetNotLocked(rsrc.getNotes());
// Only administrators are allowed to keep all labels at their own risk.
try {
if (input.keepAllVotes) {
permissionBackend.user(caller).check(GlobalPermission.ADMINISTRATE_SERVER);
}
} catch (AuthException denied) {
throw new AuthException("move is not permitted with keepAllVotes option", denied);
}
// Move requires abandoning this change, and creating a new change.
try {
rsrc.permissions().check(ABANDON);
permissionBackend.user(caller).ref(newDest).check(CREATE_CHANGE);
} catch (AuthException denied) {
throw new AuthException("move not permitted", denied);
}
projectCache.get(project).orElseThrow(illegalState(project)).checkStatePermitsWrite();
Op op = new Op(input);
try (BatchUpdate u = updateFactory.create(project, caller, TimeUtil.now())) {
u.addOp(change.getId(), op);
u.execute();
}
return Response.ok(json.noOptions().format(op.getChange()));
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class ChangeIT method customCommitFooters.
@Test
public void customCommitFooters() throws Exception {
PushOneCommit.Result change = createChange();
ChangeInfo actual;
ChangeMessageModifier link = new ChangeMessageModifier() {
@Override
public String onSubmit(String newCommitMessage, RevCommit original, RevCommit mergeTip, BranchNameKey destination) {
assertThat(original.getName()).isNotEqualTo(mergeTip.getName());
return newCommitMessage + "Custom: " + destination.branch();
}
};
try (Registration registration = extensionRegistry.newRegistration().add(link)) {
actual = gApi.changes().id(change.getChangeId()).get(ALL_REVISIONS, COMMIT_FOOTERS);
}
List<String> footers = new ArrayList<>(Arrays.asList(actual.revisions.get(change.getCommit().getName()).commitWithFooters.split("\\n")));
// remove subject + blank line
footers.remove(0);
footers.remove(0);
List<String> expectedFooters = Arrays.asList("Change-Id: " + change.getChangeId(), "Reviewed-on: " + canonicalWebUrl.get() + "c/" + project.get() + "/+/" + change.getChange().getId(), "Custom: refs/heads/master");
assertThat(footers).containsExactlyElementsIn(expectedFooters);
}
Aggregations