Merge "Merge branch 'stable-2.11'"

This commit is contained in:
Edwin Kempin
2015-08-04 12:00:45 +00:00
committed by Gerrit Code Review
8 changed files with 77 additions and 5 deletions

View File

@@ -30,6 +30,7 @@ import com.google.gerrit.extensions.api.GerritApi;
import com.google.gerrit.extensions.api.changes.ReviewInput; import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.api.changes.RevisionApi; import com.google.gerrit.extensions.api.changes.RevisionApi;
import com.google.gerrit.extensions.api.projects.ProjectInput; import com.google.gerrit.extensions.api.projects.ProjectInput;
import com.google.gerrit.extensions.client.InheritableBoolean;
import com.google.gerrit.extensions.client.ListChangesOption; import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.common.ActionInfo; import com.google.gerrit.extensions.common.ActionInfo;
import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.common.ChangeInfo;
@@ -490,6 +491,15 @@ public abstract class AbstractDaemonTest {
saveProjectConfig(allProjects, cfg); saveProjectConfig(allProjects, cfg);
} }
protected void setUseContributorAgreements(InheritableBoolean value)
throws Exception {
MetaDataUpdate md = metaDataUpdateFactory.create(project);
ProjectConfig config = ProjectConfig.read(md);
config.getProject().setUseContributorAgreements(value);
config.commit(md);
projectCache.evict(config.getProject());
}
protected void deny(String permission, AccountGroup.UUID id, String ref) protected void deny(String permission, AccountGroup.UUID id, String ref)
throws Exception { throws Exception {
ProjectConfig cfg = projectCache.checkedGet(project).getConfig(); ProjectConfig cfg = projectCache.checkedGet(project).getConfig();

View File

@@ -244,6 +244,8 @@ public class ChangeIT extends AbstractDaemonTest {
assertThat(info.project).isEqualTo(in.project); assertThat(info.project).isEqualTo(in.project);
assertThat(info.branch).isEqualTo(in.branch); assertThat(info.branch).isEqualTo(in.branch);
assertThat(info.subject).isEqualTo(in.subject); assertThat(info.subject).isEqualTo(in.subject);
assertThat(Iterables.getOnlyElement(info.messages).message)
.isEqualTo("Uploaded patch set 1.");
} }
@Test @Test

View File

@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.http.HttpStatus.SC_FORBIDDEN;
import static org.apache.http.HttpStatus.SC_CONFLICT; import static org.apache.http.HttpStatus.SC_CONFLICT;
import static org.apache.http.HttpStatus.SC_NOT_FOUND; import static org.apache.http.HttpStatus.SC_NOT_FOUND;
import static org.apache.http.HttpStatus.SC_NO_CONTENT; import static org.apache.http.HttpStatus.SC_NO_CONTENT;
@@ -35,6 +36,7 @@ import com.google.gerrit.acceptance.RestSession;
import com.google.gerrit.acceptance.TestProjectInput; import com.google.gerrit.acceptance.TestProjectInput;
import com.google.gerrit.common.data.LabelType; import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.extensions.api.changes.ReviewInput; import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.client.InheritableBoolean;
import com.google.gerrit.extensions.client.ListChangesOption; import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.common.ApprovalInfo; import com.google.gerrit.extensions.common.ApprovalInfo;
import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.common.ChangeInfo;
@@ -209,6 +211,22 @@ public class ChangeEditIT extends AbstractDaemonTest {
assertThat(edit.isPresent()).isFalse(); assertThat(edit.isPresent()).isFalse();
} }
@Test
public void publishEditRestWithoutCLA() throws Exception {
setUseContributorAgreements(InheritableBoolean.TRUE);
PatchSet oldCurrentPatchSet = getCurrentPatchSet(changeId);
assertThat(modifier.createEdit(change, oldCurrentPatchSet)).isEqualTo(
RefUpdate.Result.NEW);
assertThat(
modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME,
RestSession.newRawInput(CONTENT_NEW))).isEqualTo(RefUpdate.Result.FORCED);
RestResponse r = adminSession.post(urlPublish());
assertThat(r.getStatusCode()).isEqualTo(SC_FORBIDDEN);
setUseContributorAgreements(InheritableBoolean.FALSE);
r = adminSession.post(urlPublish());
assertThat(r.getStatusCode()).isEqualTo(SC_NO_CONTENT);
}
@Test @Test
public void rebaseEdit() throws Exception { public void rebaseEdit() throws Exception {
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW); assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);

View File

@@ -211,6 +211,7 @@ java_test(
'//gerrit-server/src/main/prolog:common', '//gerrit-server/src/main/prolog:common',
'//lib:args4j', '//lib:args4j',
'//lib:grappa', '//lib:grappa',
'//lib:guava',
'//lib:gwtorm', '//lib:gwtorm',
'//lib:truth', '//lib:truth',
'//lib/bouncycastle:bcprov', '//lib/bouncycastle:bcprov',

View File

@@ -32,6 +32,7 @@ import com.google.gerrit.extensions.restapi.TopLevelResource;
import com.google.gerrit.extensions.restapi.UnprocessableEntityException; import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
import com.google.gerrit.reviewdb.client.Branch; import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames; import com.google.gerrit.reviewdb.client.RefNames;
@@ -207,6 +208,15 @@ public class CreateChange implements
changeInserterFactory.create(refControl.getProjectControl(), changeInserterFactory.create(refControl.getProjectControl(),
change, c); change, c);
ChangeMessage msg = new ChangeMessage(new ChangeMessage.Key(change.getId(),
ChangeUtil.messageUUID(db.get())),
me.getAccountId(),
ins.getPatchSet().getCreatedOn(),
ins.getPatchSet().getId());
msg.setMessage(String.format("Uploaded patch set %s.",
ins.getPatchSet().getPatchSetId()));
ins.setMessage(msg);
validateCommit(git, refControl, c, me, ins); validateCommit(git, refControl, c, me, ins);
updateRef(git, rw, c, change, ins.getPatchSet()); updateRef(git, rw, c, change, ins.getPatchSet());

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.server.change; package com.google.gerrit.server.change;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.gerrit.common.data.Capable;
import com.google.gerrit.extensions.registration.DynamicMap; import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.extensions.restapi.AcceptsPost; import com.google.gerrit.extensions.restapi.AcceptsPost;
import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.AuthException;
@@ -84,6 +85,12 @@ public class PublishChangeEdit implements
public Response<?> apply(ChangeResource rsrc, Publish.Input in) public Response<?> apply(ChangeResource rsrc, Publish.Input in)
throws AuthException, ResourceConflictException, NoSuchChangeException, throws AuthException, ResourceConflictException, NoSuchChangeException,
IOException, OrmException { IOException, OrmException {
Capable r =
rsrc.getControl().getProjectControl().canPushToAtLeastOneRef();
if (r != Capable.OK) {
throw new AuthException(r.getMessage());
}
Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getChange()); Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getChange());
if (!edit.isPresent()) { if (!edit.isPresent()) {
throw new ResourceConflictException(String.format( throw new ResourceConflictException(String.format(

View File

@@ -84,6 +84,7 @@ public class SubmoduleSectionParser {
final String url = bbc.getString("submodule", id, "url"); final String url = bbc.getString("submodule", id, "url");
final String path = bbc.getString("submodule", id, "path"); final String path = bbc.getString("submodule", id, "path");
String branch = bbc.getString("submodule", id, "branch"); String branch = bbc.getString("submodule", id, "branch");
SubmoduleSubscription ss = null;
try { try {
if (url != null && url.length() > 0 && path != null && path.length() > 0 if (url != null && url.length() > 0 && path != null && path.length() > 0
@@ -116,8 +117,10 @@ public class SubmoduleSectionParser {
} }
Project.NameKey projectKey = new Project.NameKey(projectName); Project.NameKey projectKey = new Project.NameKey(projectName);
if (projectCache.get(projectKey) != null) { if (projectCache.get(projectKey) != null) {
return new SubmoduleSubscription(superProjectBranch, ss = new SubmoduleSubscription(
new Branch.NameKey(projectKey, branch), path); superProjectBranch,
new Branch.NameKey(new Project.NameKey(projectName), branch),
path);
} }
} }
} }
@@ -126,6 +129,6 @@ public class SubmoduleSectionParser {
// Error in url syntax (in fact it is uri syntax) // Error in url syntax (in fact it is uri syntax)
} }
return null; return ss;
} }
} }

View File

@@ -190,6 +190,28 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
expectedSubscriptions); expectedSubscriptions);
} }
@Test
public void testSubmodulesParseWithSubProjectFound() throws Exception {
Map<String, SubmoduleSection> sectionsToReturn = new TreeMap<>();
sectionsToReturn.put("a/b", new SubmoduleSection(
"ssh://localhost/a/b", "a/b", "."));
Map<String, String> reposToBeFound = new HashMap<>();
reposToBeFound.put("a/b", "a/b");
reposToBeFound.put("b", "b");
Branch.NameKey superBranchNameKey =
new Branch.NameKey(new Project.NameKey("super-project"),
"refs/heads/master");
Set<SubmoduleSubscription> expectedSubscriptions = Sets.newHashSet();
expectedSubscriptions
.add(new SubmoduleSubscription(superBranchNameKey, new Branch.NameKey(
new Project.NameKey("a/b"), "refs/heads/master"), "a/b"));
execute(superBranchNameKey, sectionsToReturn, reposToBeFound,
expectedSubscriptions);
}
private void execute(final Branch.NameKey superProjectBranch, private void execute(final Branch.NameKey superProjectBranch,
final Map<String, SubmoduleSection> sectionsToReturn, final Map<String, SubmoduleSection> sectionsToReturn,
final Map<String, String> reposToBeFound, final Map<String, String> reposToBeFound,
@@ -217,10 +239,9 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
projectNameCandidate = projectNameCandidate.substring(0, // projectNameCandidate = projectNameCandidate.substring(0, //
projectNameCandidate.length() - Constants.DOT_GIT_EXT.length()); projectNameCandidate.length() - Constants.DOT_GIT_EXT.length());
} }
if (projectNameCandidate.equals(reposToBeFound.get(id))) { if (reposToBeFound.containsValue(projectNameCandidate)) {
expect(projectCache.get(new Project.NameKey(projectNameCandidate))) expect(projectCache.get(new Project.NameKey(projectNameCandidate)))
.andReturn(createNiceMock(ProjectState.class)); .andReturn(createNiceMock(ProjectState.class));
break;
} else { } else {
expect(projectCache.get(new Project.NameKey(projectNameCandidate))) expect(projectCache.get(new Project.NameKey(projectNameCandidate)))
.andReturn(null); .andReturn(null);