Search in sources :

Example 71 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class MoveChangeIT method moveChangeWithFullRef.

@Test
public void moveChangeWithFullRef() throws Exception {
    // Move change to a different branch using full ref name
    PushOneCommit.Result r = createChange();
    BranchNameKey newBranch = BranchNameKey.create(r.getChange().change().getProject(), "moveTest");
    createBranch(newBranch);
    move(r.getChangeId(), newBranch.branch());
    assertThat(r.getChange().change().getDest()).isEqualTo(newBranch);
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 72 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class MoveChangeIT method moveChangeToSameChangeId.

@Test
public void moveChangeToSameChangeId() throws Exception {
    // Move change to a branch with existing change with same change ID
    PushOneCommit.Result r = createChange();
    BranchNameKey newBranch = BranchNameKey.create(r.getChange().change().getProject(), "moveTest");
    createBranch(newBranch);
    int changeNum = r.getChange().change().getChangeId();
    createChange(newBranch.branch(), r.getChangeId());
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> move(changeNum, newBranch.branch()));
    assertThat(thrown).hasMessageThat().contains("Destination " + newBranch.shortName() + " has a different change with same change key " + r.getChangeId());
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 73 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class SubmitByMergeIfNecessaryIT method dependencyOnChangeForNonVisibleBranchPreventsMerge.

@Test
public void dependencyOnChangeForNonVisibleBranchPreventsMerge() throws Throwable {
    projectOperations.project(project).forUpdate().add(allowLabel(LabelId.CODE_REVIEW).ref("refs/heads/*").group(REGISTERED_USERS).range(-2, 2)).add(allow(Permission.SUBMIT).ref("refs/*").group(REGISTERED_USERS)).update();
    // Create a change
    PushOneCommit change = pushFactory.create(admin.newIdent(), testRepo, "fix", "a.txt", "foo");
    PushOneCommit.Result changeResult = change.to("refs/for/master");
    approve(changeResult.getChangeId());
    // Create a successor change.
    PushOneCommit change2 = pushFactory.create(admin.newIdent(), testRepo, "feature", "b.txt", "bar");
    PushOneCommit.Result change2Result = change2.to("refs/for/master");
    // Move the first change to a destination branch that is non-visible to user so that user cannot
    // this change anymore.
    BranchNameKey secretBranch = BranchNameKey.create(project, "secretBranch");
    gApi.projects().name(secretBranch.project().get()).branch(secretBranch.branch()).create(new BranchInput());
    gApi.changes().id(changeResult.getChangeId()).move(secretBranch.branch());
    projectOperations.project(project).forUpdate().add(block(READ).ref(secretBranch.branch()).group(ANONYMOUS_USERS)).update();
    requestScopeOperations.setApiUser(user.id());
    // Verify that user cannot see the first change.
    ResourceNotFoundException thrown = assertThrows(ResourceNotFoundException.class, () -> gApi.changes().id(changeResult.getChangeId()).get());
    assertThat(thrown).hasMessageThat().isEqualTo("Not found: " + changeResult.getChangeId());
    // Submit is expected to fail.
    submitWithConflict(change2Result.getChangeId(), "Failed to submit 1 change due to the following problems:\n" + "Change " + change2Result.getChange().getId() + ": Depends on change that was not submitted." + " Commit " + change2Result.getCommit().name() + " depends on commit " + changeResult.getCommit().name() + " which cannot be merged." + " Is the change of this commit not visible to '" + user.username() + "' or was it deleted?");
    assertRefUpdatedEvents();
    assertChangeMergedEvents();
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test)

Example 74 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class BranchNameKeyProtoConverterTest method allValuesConvertedToProtoAndBackAgain.

@Test
public void allValuesConvertedToProtoAndBackAgain() {
    BranchNameKey nameKey = BranchNameKey.create(Project.nameKey("project-52"), "branch 14");
    BranchNameKey convertedNameKey = branchNameKeyProtoConverter.fromProto(branchNameKeyProtoConverter.toProto(nameKey));
    assertThat(convertedNameKey).isEqualTo(nameKey);
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) Test(org.junit.Test)

Example 75 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class ChangeNotesTest method branchChangeNotes.

@Test
public void branchChangeNotes() throws Exception {
    Change c = newChange();
    ChangeNotes notes = newNotes(c);
    BranchNameKey expectedBranch = BranchNameKey.create(project, "refs/heads/master");
    assertThat(notes.getChange().getDest()).isEqualTo(expectedBranch);
    // An update doesn't affect the branch
    ChangeUpdate update = newUpdate(c, changeOwner);
    // Change something to get a new commit.
    update.setTopic("topic");
    update.commit();
    assertThat(newNotes(c).getChange().getDest()).isEqualTo(expectedBranch);
    // Set another branch
    String otherBranch = "refs/heads/stable";
    update = newUpdate(c, changeOwner);
    update.setBranch(otherBranch);
    update.commit();
    assertThat(newNotes(c).getChange().getDest()).isEqualTo(BranchNameKey.create(project, otherBranch));
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Aggregations

BranchNameKey (com.google.gerrit.entities.BranchNameKey)75 Test (org.junit.Test)48 Project (com.google.gerrit.entities.Project)26 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)25 Config (org.eclipse.jgit.lib.Config)19 SubmoduleSubscription (com.google.gerrit.entities.SubmoduleSubscription)18 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 RevCommit (org.eclipse.jgit.revwalk.RevCommit)16 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)15 AuthException (com.google.gerrit.extensions.restapi.AuthException)13 Change (com.google.gerrit.entities.Change)12 IOException (java.io.IOException)11 ObjectId (org.eclipse.jgit.lib.ObjectId)11 StorageException (com.google.gerrit.exceptions.StorageException)10 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 Repository (org.eclipse.jgit.lib.Repository)9 PatchSet (com.google.gerrit.entities.PatchSet)8 CodeReviewCommit (com.google.gerrit.server.git.CodeReviewCommit)8 HashMap (java.util.HashMap)7 Ref (org.eclipse.jgit.lib.Ref)7