Skip to content

Commit 963b5ef

Browse files
committed
Fix ChangeControl when adding patch-set to Change
In current Gerrit master we need a ChangeControl in order to add a new patch-set to an existing change. Change-Id: If0bc2b59fd3ca1a193c291c913bb42aec6182e2d
1 parent 6a1d87d commit 963b5ef

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestCreateChange.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
import com.google.gerrit.server.ChangeUtil;
2929
import com.google.gerrit.server.IdentifiedUser;
3030
import com.google.gerrit.server.IdentifiedUser.GenericFactory;
31-
import com.google.gerrit.server.Sequences;
3231
import com.google.gerrit.server.change.ChangeInserter;
3332
import com.google.gerrit.server.change.PatchSetInserter;
3433
import com.google.gerrit.server.git.BatchUpdate;
3534
import com.google.gerrit.server.git.IntegrationException;
3635
import com.google.gerrit.server.git.UpdateException;
3736
import com.google.gerrit.server.git.validators.CommitValidators.Policy;
37+
import com.google.gerrit.server.project.ChangeControl;
3838
import com.google.gerrit.server.project.InvalidChangeOperationException;
3939
import com.google.gerrit.server.project.NoSuchChangeException;
4040
import com.google.gerrit.server.project.NoSuchProjectException;
@@ -64,7 +64,6 @@
6464

6565
import java.io.IOException;
6666
import java.util.Collections;
67-
import java.util.Iterator;
6867
import java.util.List;
6968

7069
public class PullRequestCreateChange {
@@ -180,8 +179,11 @@ public Change.Id internalAddCommitToChange(ReviewDb db, BatchUpdate bu,
180179
// The change key exists on the destination branch: adding a new
181180
// patch-set
182181
Change destChange = destChanges.get(0).change();
183-
insertPatchSet(bu, repo, destChange, pullRequestCommit,
184-
refControl, pullRequestMesage);
182+
ChangeControl changeControl =
183+
projectControlFactory.controlFor(project.getNameKey())
184+
.controlForIndexedChange(destChange);
185+
insertPatchSet(bu, repo, destChange, pullRequestCommit, changeControl,
186+
pullRequestMesage);
185187
return destChange.getId();
186188
}
187189

@@ -205,15 +207,15 @@ private List<ChangeData> queryChangesForSha1(String pullRequestSha1) {
205207
}
206208

207209
private void insertPatchSet(BatchUpdate bu, Repository git, Change change,
208-
RevCommit cherryPickCommit, RefControl refControl,
210+
RevCommit cherryPickCommit, ChangeControl changeControl,
209211
String pullRequestMessage) throws IOException, UpdateException,
210212
RestApiException {
211213
try (RevWalk revWalk = new RevWalk(git)) {
212214
PatchSet.Id psId =
213215
ChangeUtil.nextPatchSetId(git, change.currentPatchSetId());
214216

215217
PatchSetInserter patchSetInserter =
216-
patchSetInserterFactory.create(refControl, psId, cherryPickCommit);
218+
patchSetInserterFactory.create(changeControl, psId, cherryPickCommit);
217219
patchSetInserter.setMessage(pullRequestMessage);
218220
patchSetInserter.setValidatePolicy(Policy.NONE);
219221

0 commit comments

Comments
 (0)