Merge "SubmittedTogether: Only show tab if there is more than one change"

This commit is contained in:
Shawn Pearce
2015-07-22 15:43:33 +00:00
committed by Gerrit Code Review
3 changed files with 59 additions and 13 deletions

View File

@@ -1073,7 +1073,11 @@ message is contained in the response body.
--
Returns a list of all changes which are submitted when
link:#submit-change[\{submit\}] is called for this change.
link:#submit-change[\{submit\}] is called for this change,
including the current change itself.
An empty list is returned if this change will be submitted
by itself (no other changes).
.Request
----

View File

@@ -51,14 +51,14 @@ public class SubmittedTogetherIT extends AbstractDaemonTest {
String id2 = getChangeId(c2_1);
pushHead(testRepo, "refs/for/master", false);
assertSubmittedTogether(id1, id1);
assertSubmittedTogether(id1);
assertSubmittedTogether(id2, id2, id1);
}
@Test
public void respectsWholeTopicAndAncestors() throws Exception {
RevCommit initialHead = getRemoteHead();
// Create two independant commits and push.
// Create two independent commits and push.
RevCommit c1_1 = commitBuilder()
.add("a.txt", "1")
.message("subject: 1")
@@ -78,8 +78,45 @@ public class SubmittedTogetherIT extends AbstractDaemonTest {
assertSubmittedTogether(id1, id2, id1);
assertSubmittedTogether(id2, id2, id1);
} else {
assertSubmittedTogether(id1, id1);
assertSubmittedTogether(id2, id2);
assertSubmittedTogether(id1);
assertSubmittedTogether(id2);
}
}
@Test
public void testTopicChaining() throws Exception {
RevCommit initialHead = getRemoteHead();
// Create two independent commits and push.
RevCommit c1_1 = commitBuilder()
.add("a.txt", "1")
.message("subject: 1")
.create();
String id1 = getChangeId(c1_1);
pushHead(testRepo, "refs/for/master/" + name("connectingTopic"), false);
testRepo.reset(initialHead);
RevCommit c2_1 = commitBuilder()
.add("b.txt", "2")
.message("subject: 2")
.create();
String id2 = getChangeId(c2_1);
pushHead(testRepo, "refs/for/master/" + name("connectingTopic"), false);
RevCommit c3_1 = commitBuilder()
.add("b.txt", "2")
.message("subject: 2")
.create();
String id3 = getChangeId(c3_1);
pushHead(testRepo, "refs/for/master/" + name("unrelated-topic"), false);
if (isSubmitWholeTopicEnabled()) {
assertSubmittedTogether(id1, id2, id1);
assertSubmittedTogether(id2, id2, id1);
assertSubmittedTogether(id3, id3, id2, id1);
} else {
assertSubmittedTogether(id1);
assertSubmittedTogether(id2);
assertSubmittedTogether(id3, id3, id2);
}
}
@@ -102,8 +139,8 @@ public class SubmittedTogetherIT extends AbstractDaemonTest {
String id2 = getChangeId(c2_1);
pushHead(testRepo, "refs/for/master", false);
assertSubmittedTogether(id1, id1);
assertSubmittedTogether(id2, id2);
assertSubmittedTogether(id1);
assertSubmittedTogether(id2);
}
private void assertSubmittedTogether(String chId, String... expected)

View File

@@ -32,6 +32,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
@@ -60,12 +61,16 @@ public class SubmittedTogether implements RestReadView<ChangeResource> {
try {
ChangeSet cs = mergeSuperSet.completeChangeSet(dbProvider.get(),
ChangeSet.create(resource.getChange()));
if (cs.ids().size() > 1) {
return json.create(EnumSet.of(
ListChangesOption.CURRENT_REVISION,
ListChangesOption.CURRENT_COMMIT,
ListChangesOption.DETAILED_LABELS,
ListChangesOption.LABELS))
.format(cs.ids());
} else {
return Collections.emptyList();
}
} catch (OrmException | IOException e) {
log.error("Error on getting a ChangeSet", e);
throw e;