Support fixing corrupt changes in ConsistencyChecker

To fix changes, pass an appropriate input to the checker; for now this
is empty, but may include things like a strategy to choose when there
are multiple options. (For example, if multiple patch sets have the
same SHA-1, we could delete all but the newest, or all but the
oldest.)

Change-Id: I016a94e27b8f6b63b3662b46271c01ed86110ec3
This commit is contained in:
Dave Borowitz
2014-12-03 17:57:38 -08:00
parent 2bdbc1dec2
commit 3be39d0291
12 changed files with 254 additions and 24 deletions

View File

@@ -23,6 +23,7 @@ import static java.util.Collections.singleton;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.extensions.api.changes.FixInput;
import com.google.gerrit.extensions.common.ProblemInfo;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
@@ -43,6 +44,8 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
public class ConsistencyCheckerTest {
private InMemoryDatabase schemaFactory;
private ReviewDb db;
@@ -240,6 +243,30 @@ public class ConsistencyCheckerTest {
+ " master (" + commit.name() + "), but change status is NEW");
}
@Test
public void newChangeIsMergedWithFix() throws Exception {
Change c = newChange(project, userId);
db.changes().insert(singleton(c));
RevCommit commit = repo.branch(c.currentPatchSetId().toRefName()).commit()
.parent(tip).create();
PatchSet ps = newPatchSet(c.currentPatchSetId(), commit, userId);
db.patchSets().insert(singleton(ps));
repo.branch(c.getDest().get()).update(commit);
List<ProblemInfo> problems = checker.check(c, new FixInput()).problems();
assertThat(problems).hasSize(1);
ProblemInfo p = problems.get(0);
assertThat(p.message).isEqualTo(
"Patch set 1 (" + commit.name() + ") is merged into destination ref"
+ " master (" + commit.name() + "), but change status is NEW");
assertThat(p.status).isEqualTo(ProblemInfo.Status.FIXED);
assertThat(p.outcome).isEqualTo("Marked change as merged");
c = db.changes().get(c.getId());
assertThat(c.getStatus()).isEqualTo(Change.Status.MERGED);
assertProblems(c);
}
private void assertProblems(Change c, String... expected) {
assertThat(Lists.transform(checker.check(c).problems(),
new Function<ProblemInfo, String>() {