Merge branch 'stable-3.0' into stable-3.1
* stable-3.0: Test cherry-pick to a non-existing branch CherryPick: Do not fail with ISE if non-existing commit is specified as base Change-Id: I51e9be4a80f10e3c86c4665e9e12ad71763bd840
This commit is contained in:
@@ -70,6 +70,7 @@ import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.InvalidObjectIdException;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.ObjectInserter;
|
||||
import org.eclipse.jgit.lib.ObjectReader;
|
||||
@@ -381,7 +382,14 @@ public class CherryPickChange {
|
||||
throw new BadRequestException(String.format("Base %s doesn't represent a valid SHA-1", base));
|
||||
}
|
||||
|
||||
RevCommit baseCommit = revWalk.parseCommit(baseObjectId);
|
||||
RevCommit baseCommit;
|
||||
try {
|
||||
baseCommit = revWalk.parseCommit(baseObjectId);
|
||||
} catch (MissingObjectException e) {
|
||||
throw new UnprocessableEntityException(
|
||||
String.format("Base %s doesn't exist", baseObjectId.name()), e);
|
||||
}
|
||||
|
||||
InternalChangeQuery changeQuery = queryProvider.get();
|
||||
changeQuery.enforceVisibility(true);
|
||||
List<ChangeData> changeDatas = changeQuery.byBranchCommit(project, destRef.getName(), base);
|
||||
|
@@ -53,6 +53,7 @@ import com.google.gerrit.entities.Account;
|
||||
import com.google.gerrit.entities.BranchNameKey;
|
||||
import com.google.gerrit.entities.Change;
|
||||
import com.google.gerrit.entities.PatchSetApproval;
|
||||
import com.google.gerrit.entities.RefNames;
|
||||
import com.google.gerrit.extensions.api.changes.ChangeApi;
|
||||
import com.google.gerrit.extensions.api.changes.CherryPickInput;
|
||||
import com.google.gerrit.extensions.api.changes.DraftApi;
|
||||
@@ -973,6 +974,42 @@ public class RevisionIT extends AbstractDaemonTest {
|
||||
assertCherryPickResult(changeInfo, input, srcChange.getChangeId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cherryPickToNonExistingBranch() throws Exception {
|
||||
PushOneCommit.Result result = createChange();
|
||||
|
||||
CherryPickInput input = new CherryPickInput();
|
||||
input.message = "foo bar";
|
||||
input.destination = "non-existing";
|
||||
// TODO(ekempin): This should rather result in an UnprocessableEntityException.
|
||||
BadRequestException thrown =
|
||||
assertThrows(
|
||||
BadRequestException.class,
|
||||
() -> gApi.changes().id(result.getChangeId()).current().cherryPick(input));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo(
|
||||
String.format("Branch %s does not exist.", RefNames.REFS_HEADS + input.destination));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cherryPickToNonExistingBaseCommit() throws Exception {
|
||||
createBranch(BranchNameKey.create(project, "foo"));
|
||||
PushOneCommit.Result result = createChange();
|
||||
|
||||
CherryPickInput input = new CherryPickInput();
|
||||
input.message = "foo bar";
|
||||
input.destination = "foo";
|
||||
input.base = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
|
||||
UnprocessableEntityException thrown =
|
||||
assertThrows(
|
||||
UnprocessableEntityException.class,
|
||||
() -> gApi.changes().id(result.getChangeId()).current().cherryPick(input));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo(String.format("Base %s doesn't exist", input.base));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canRebase() throws Exception {
|
||||
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
|
||||
|
Reference in New Issue
Block a user