PushOneCommit: Move Git into constructor

It makes no sense to make multiple method calls on a single
PushOneCommit instance passing in different repositories each time.
Pass a single instance into the factory method instead.

Change-Id: I718aa01c9090bb0394c70626515693c37d3b8125
This commit is contained in:
Dave Borowitz
2015-03-11 16:52:43 -07:00
committed by David Pursehouse
parent e6992e76f6
commit b074c9f74f
20 changed files with 147 additions and 140 deletions

View File

@@ -277,8 +277,8 @@ public abstract class AbstractDaemonTest {
protected PushOneCommit.Result createChange() throws GitAPIException,
IOException {
PushOneCommit push = pushFactory.create(db, admin.getIdent());
return push.to(git, "refs/for/master");
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git);
return push.to("refs/for/master");
}
private static final List<Character> RANDOM =
@@ -292,9 +292,9 @@ public abstract class AbstractDaemonTest {
throws GitAPIException, IOException {
Collections.shuffle(RANDOM);
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), PushOneCommit.SUBJECT,
pushFactory.create(db, admin.getIdent(), git, PushOneCommit.SUBJECT,
PushOneCommit.FILE_NAME, new String(Chars.toArray(RANDOM)), changeId);
return push.to(git, ref);
return push.to(ref);
}
protected ChangeInfo getChange(String changeId, ListChangesOption... options)
@@ -416,7 +416,7 @@ public abstract class AbstractDaemonTest {
protected PushOneCommit.Result pushTo(String ref) throws GitAPIException,
IOException {
PushOneCommit push = pushFactory.create(db, admin.getIdent());
return push.to(git, ref);
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git);
return push.to(ref);
}
}

View File

@@ -65,11 +65,13 @@ public class PushOneCommit {
public interface Factory {
PushOneCommit create(
ReviewDb db,
PersonIdent i);
PersonIdent i,
Git git);
PushOneCommit create(
ReviewDb db,
PersonIdent i,
Git git,
@Assisted("subject") String subject,
@Assisted("fileName") String fileName,
@Assisted("content") String content);
@@ -77,6 +79,7 @@ public class PushOneCommit {
PushOneCommit create(
ReviewDb db,
PersonIdent i,
Git git,
@Assisted("subject") String subject,
@Assisted("fileName") String fileName,
@Assisted("content") String content,
@@ -107,6 +110,7 @@ public class PushOneCommit {
private final Provider<InternalChangeQuery> queryProvider;
private final ReviewDb db;
private final PersonIdent i;
private final Git git;
private final String subject;
private final String fileName;
@@ -120,9 +124,10 @@ public class PushOneCommit {
ApprovalsUtil approvalsUtil,
Provider<InternalChangeQuery> queryProvider,
@Assisted ReviewDb db,
@Assisted PersonIdent i) {
@Assisted PersonIdent i,
@Assisted Git git) {
this(notesFactory, approvalsUtil, queryProvider,
db, i, SUBJECT, FILE_NAME, FILE_CONTENT);
db, i, git, SUBJECT, FILE_NAME, FILE_CONTENT);
}
@AssistedInject
@@ -131,11 +136,12 @@ public class PushOneCommit {
Provider<InternalChangeQuery> queryProvider,
@Assisted ReviewDb db,
@Assisted PersonIdent i,
@Assisted Git git,
@Assisted("subject") String subject,
@Assisted("fileName") String fileName,
@Assisted("content") String content) {
this(notesFactory, approvalsUtil, queryProvider,
db, i, subject, fileName, content, null);
db, i, git, subject, fileName, content, null);
}
@AssistedInject
@@ -144,6 +150,7 @@ public class PushOneCommit {
Provider<InternalChangeQuery> queryProvider,
@Assisted ReviewDb db,
@Assisted PersonIdent i,
@Assisted Git git,
@Assisted("subject") String subject,
@Assisted("fileName") String fileName,
@Assisted("content") String content,
@@ -153,23 +160,24 @@ public class PushOneCommit {
this.approvalsUtil = approvalsUtil;
this.queryProvider = queryProvider;
this.i = i;
this.git = git;
this.subject = subject;
this.fileName = fileName;
this.content = content;
this.changeId = changeId;
}
public Result to(Git git, String ref) throws GitAPIException, IOException {
public Result to(String ref) throws GitAPIException, IOException {
add(git, fileName, content);
return execute(git, ref);
return execute(ref);
}
public Result rm(Git git, String ref) throws GitAPIException {
public Result rm(String ref) throws GitAPIException {
GitUtil.rm(git, fileName);
return execute(git, ref);
return execute(ref);
}
private Result execute(Git git, String ref) throws GitAPIException,
private Result execute(String ref) throws GitAPIException,
ConcurrentRefUpdateException, InvalidTagNameException, NoHeadException {
Commit c;
if (changeId != null) {

View File

@@ -214,9 +214,9 @@ public class RevisionIT extends AbstractDaemonTest {
String subject = "Test change\n\n" +
"Change-Id: Ideadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), subject,
pushFactory.create(db, admin.getIdent(), git, subject,
"another_file.txt", "another content");
PushOneCommit.Result r2 = push.to(git, "refs/for/master");
PushOneCommit.Result r2 = push.to("refs/for/master");
// Change 2's parent should be change 1
assertThat(r2.getCommit().getParents()[0].name())
@@ -283,9 +283,9 @@ public class RevisionIT extends AbstractDaemonTest {
.create(new BranchInput());
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), PushOneCommit.SUBJECT,
pushFactory.create(db, admin.getIdent(), git, PushOneCommit.SUBJECT,
PushOneCommit.FILE_NAME, "another content");
push.to(git, "refs/heads/foo");
push.to("refs/heads/foo");
ChangeApi orig = gApi.changes().id("p~master~" + r.getChangeId());
assertThat((Iterable<?>)orig.get().messages).hasSize(1);
@@ -300,12 +300,12 @@ public class RevisionIT extends AbstractDaemonTest {
@Test
public void canRebase() throws Exception {
PushOneCommit push = pushFactory.create(db, admin.getIdent());
PushOneCommit.Result r1 = push.to(git, "refs/for/master");
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git);
PushOneCommit.Result r1 = push.to("refs/for/master");
merge(r1);
push = pushFactory.create(db, admin.getIdent());
PushOneCommit.Result r2 = push.to(git, "refs/for/master");
push = pushFactory.create(db, admin.getIdent(), git);
PushOneCommit.Result r2 = push.to("refs/for/master");
boolean canRebase = gApi.changes()
.id(r2.getChangeId())
.revision(r2.getCommit().name())
@@ -314,8 +314,8 @@ public class RevisionIT extends AbstractDaemonTest {
merge(r2);
git.checkout().setName(r1.getCommit().name()).call();
push = pushFactory.create(db, admin.getIdent());
PushOneCommit.Result r3 = push.to(git, "refs/for/master");
push = pushFactory.create(db, admin.getIdent(), git);
PushOneCommit.Result r3 = push.to("refs/for/master");
canRebase = gApi.changes()
.id(r3.getChangeId())
@@ -326,8 +326,8 @@ public class RevisionIT extends AbstractDaemonTest {
@Test
public void setUnsetReviewedFlag() throws Exception {
PushOneCommit push = pushFactory.create(db, admin.getIdent());
PushOneCommit.Result r = push.to(git, "refs/for/master");
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git);
PushOneCommit.Result r = push.to("refs/for/master");
gApi.changes()
.id(r.getChangeId())
@@ -354,10 +354,10 @@ public class RevisionIT extends AbstractDaemonTest {
ObjectId initial = git.getRepository().getRef(HEAD).getLeaf().getObjectId();
PushOneCommit push1 =
pushFactory.create(db, admin.getIdent(), PushOneCommit.SUBJECT,
pushFactory.create(db, admin.getIdent(), git, PushOneCommit.SUBJECT,
PushOneCommit.FILE_NAME, "push 1 content");
PushOneCommit.Result r1 = push1.to(git, "refs/for/master");
PushOneCommit.Result r1 = push1.to("refs/for/master");
assertMergeable(r1.getChangeId(), true);
merge(r1);
@@ -367,9 +367,9 @@ public class RevisionIT extends AbstractDaemonTest {
assertThat(ru.forceUpdate()).isEqualTo(RefUpdate.Result.FORCED);
PushOneCommit push2 =
pushFactory.create(db, admin.getIdent(), PushOneCommit.SUBJECT,
pushFactory.create(db, admin.getIdent(), git, PushOneCommit.SUBJECT,
PushOneCommit.FILE_NAME, "push 2 content");
PushOneCommit.Result r2 = push2.to(git, "refs/for/master");
PushOneCommit.Result r2 = push2.to("refs/for/master");
assertMergeable(r2.getChangeId(), false);
// TODO(dborowitz): Test for other-branches.
}
@@ -522,14 +522,14 @@ public class RevisionIT extends AbstractDaemonTest {
private PushOneCommit.Result updateChange(PushOneCommit.Result r,
String content) throws GitAPIException, IOException {
PushOneCommit push = pushFactory.create(db, admin.getIdent(),
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git,
"test commit", "a.txt", content, r.getChangeId());
return push.to(git, "refs/for/master");
return push.to("refs/for/master");
}
private PushOneCommit.Result createDraft() throws GitAPIException,
IOException {
PushOneCommit push = pushFactory.create(db, admin.getIdent());
return push.to(git, "refs/drafts/master");
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git);
return push.to("refs/drafts/master");
}
}

View File

@@ -244,9 +244,9 @@ public class ChangeEditIT extends AbstractDaemonTest {
assertThat(edit.getBasePatchSet().getPatchSetId()).isEqualTo(
current.getPatchSetId());
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), PushOneCommit.SUBJECT, FILE_NAME,
pushFactory.create(db, admin.getIdent(), git, PushOneCommit.SUBJECT, FILE_NAME,
new String(CONTENT_NEW2), changeId2);
push.to(git, "refs/for/master").assertOkStatus();
push.to("refs/for/master").assertOkStatus();
RestResponse r = adminSession.post(urlRebase());
assertThat(r.getStatusCode()).isEqualTo(SC_CONFLICT);
}
@@ -655,23 +655,23 @@ public class ChangeEditIT extends AbstractDaemonTest {
private String newChange(Git git, PersonIdent ident) throws Exception {
PushOneCommit push =
pushFactory.create(db, ident, PushOneCommit.SUBJECT, FILE_NAME,
pushFactory.create(db, ident, git, PushOneCommit.SUBJECT, FILE_NAME,
new String(CONTENT_OLD));
return push.to(git, "refs/for/master").getChangeId();
return push.to("refs/for/master").getChangeId();
}
private String amendChange(Git git, PersonIdent ident, String changeId) throws Exception {
PushOneCommit push =
pushFactory.create(db, ident, PushOneCommit.SUBJECT, FILE_NAME2,
pushFactory.create(db, ident, git, PushOneCommit.SUBJECT, FILE_NAME2,
new String(CONTENT_NEW2), changeId);
return push.to(git, "refs/for/master").getChangeId();
return push.to("refs/for/master").getChangeId();
}
private String newChange2(Git git, PersonIdent ident) throws Exception {
PushOneCommit push =
pushFactory.create(db, ident, PushOneCommit.SUBJECT, FILE_NAME,
pushFactory.create(db, ident, git, PushOneCommit.SUBJECT, FILE_NAME,
new String(CONTENT_OLD));
return push.rm(git, "refs/for/master").getChangeId();
return push.rm("refs/for/master").getChangeId();
}
private Change getChange(String changeId) throws Exception {

View File

@@ -190,9 +190,9 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
assertThat(cr.all.get(0).value).is(1);
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), PushOneCommit.SUBJECT,
pushFactory.create(db, admin.getIdent(), git, PushOneCommit.SUBJECT,
"b.txt", "anotherContent", r.getChangeId());
r = push.to(git, "refs/for/master/%l=Code-Review+2");
r = push.to("refs/for/master/%l=Code-Review+2");
ci = get(r.getChangeId());
cr = ci.labels.get("Code-Review");
@@ -207,9 +207,9 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
PushOneCommit.Result r = pushTo("refs/for/master");
r.assertOkStatus();
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), PushOneCommit.SUBJECT,
pushFactory.create(db, admin.getIdent(), git, PushOneCommit.SUBJECT,
"b.txt", "anotherContent", r.getChangeId());
r = push.to(git, "refs/changes/" + r.getChange().change().getId().get());
r = push.to("refs/changes/" + r.getChange().change().getId().get());
r.assertOkStatus();
}
@@ -255,9 +255,9 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
// specify a single hashtag as option in new patch set
String hashtag2 = "tag2";
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), PushOneCommit.SUBJECT,
pushFactory.create(db, admin.getIdent(), git, PushOneCommit.SUBJECT,
"b.txt", "anotherContent", r.getChangeId());
r = push.to(git, "refs/for/master/%hashtag=" + hashtag2);
r = push.to("refs/for/master/%hashtag=" + hashtag2);
r.assertOkStatus();
expected = ImmutableSet.of(hashtag1, hashtag2);
hashtags = gApi.changes().id(r.getChangeId()).getHashtags();
@@ -287,10 +287,9 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
String hashtag3 = "tag3";
String hashtag4 = "tag4";
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), PushOneCommit.SUBJECT,
pushFactory.create(db, admin.getIdent(), git, PushOneCommit.SUBJECT,
"b.txt", "anotherContent", r.getChangeId());
r = push.to(git,
"refs/for/master%hashtag=" + hashtag3 + ",hashtag=" + hashtag4);
r = push.to("refs/for/master%hashtag=" + hashtag3 + ",hashtag=" + hashtag4);
r.assertOkStatus();
expected = ImmutableSet.of(hashtag1, hashtag2, hashtag3, hashtag4);
hashtags = gApi.changes().id(r.getChangeId()).getHashtags();

View File

@@ -31,8 +31,8 @@ public class ForcePushIT extends AbstractDaemonTest {
public void forcePushNotAllowed() throws Exception {
ObjectId initial = git.getRepository().getRef(HEAD).getLeaf().getObjectId();
PushOneCommit push1 =
pushFactory.create(db, admin.getIdent(), "change1", "a.txt", "content");
PushOneCommit.Result r1 = push1.to(git, "refs/heads/master");
pushFactory.create(db, admin.getIdent(), git, "change1", "a.txt", "content");
PushOneCommit.Result r1 = push1.to("refs/heads/master");
r1.assertOkStatus();
// Reset HEAD to initial so the new change is a non-fast forward
@@ -41,9 +41,9 @@ public class ForcePushIT extends AbstractDaemonTest {
assertThat(ru.forceUpdate()).isEqualTo(RefUpdate.Result.FORCED);
PushOneCommit push2 =
pushFactory.create(db, admin.getIdent(), "change2", "b.txt", "content");
pushFactory.create(db, admin.getIdent(), git, "change2", "b.txt", "content");
push2.setForce(true);
PushOneCommit.Result r2 = push2.to(git, "refs/heads/master");
PushOneCommit.Result r2 = push2.to("refs/heads/master");
r2.assertErrorStatus("non-fast forward");
}
@@ -52,8 +52,8 @@ public class ForcePushIT extends AbstractDaemonTest {
ObjectId initial = git.getRepository().getRef(HEAD).getLeaf().getObjectId();
grant(Permission.PUSH, project, "refs/*", true);
PushOneCommit push1 =
pushFactory.create(db, admin.getIdent(), "change1", "a.txt", "content");
PushOneCommit.Result r1 = push1.to(git, "refs/heads/master");
pushFactory.create(db, admin.getIdent(), git, "change1", "a.txt", "content");
PushOneCommit.Result r1 = push1.to("refs/heads/master");
r1.assertOkStatus();
// Reset HEAD to initial so the new change is a non-fast forward
@@ -62,9 +62,9 @@ public class ForcePushIT extends AbstractDaemonTest {
assertThat(ru.forceUpdate()).isEqualTo(RefUpdate.Result.FORCED);
PushOneCommit push2 =
pushFactory.create(db, admin.getIdent(), "change2", "b.txt", "content");
pushFactory.create(db, admin.getIdent(), git, "change2", "b.txt", "content");
push2.setForce(true);
PushOneCommit.Result r2 = push2.to(git, "refs/heads/master");
PushOneCommit.Result r2 = push2.to("refs/heads/master");
r2.assertOkStatus();
}
}

View File

@@ -73,9 +73,9 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
grant(Permission.CREATE, project, "refs/tags/*");
grant(Permission.PUSH, project, "refs/tags/*");
PushOneCommit.Tag tag = new PushOneCommit.Tag("v1.0");
PushOneCommit push = pushFactory.create(db, admin.getIdent());
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git);
push.setTag(tag);
PushOneCommit.Result r = push.to(git, "refs/for/master%submit");
PushOneCommit.Result r = push.to("refs/for/master%submit");
r.assertOkStatus();
r.assertChange(Change.Status.MERGED, null, admin);
assertSubmitApproval(r.getPatchSetId());
@@ -90,9 +90,9 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
grant(Permission.PUSH, project, "refs/tags/*");
PushOneCommit.AnnotatedTag tag =
new PushOneCommit.AnnotatedTag("v1.0", "annotation", admin.getIdent());
PushOneCommit push = pushFactory.create(db, admin.getIdent());
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git);
push.setTag(tag);
PushOneCommit.Result r = push.to(git, "refs/for/master%submit");
PushOneCommit.Result r = push.to("refs/for/master%submit");
r.assertOkStatus();
r.assertChange(Change.Status.MERGED, null, admin);
assertSubmitApproval(r.getPatchSetId());
@@ -273,15 +273,15 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
private PushOneCommit.Result push(String ref, String subject,
String fileName, String content) throws GitAPIException, IOException {
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), subject, fileName, content);
return push.to(git, ref);
pushFactory.create(db, admin.getIdent(), git, subject, fileName, content);
return push.to(ref);
}
private PushOneCommit.Result push(String ref, String subject,
String fileName, String content, String changeId) throws GitAPIException,
IOException {
PushOneCommit push = pushFactory.create(db, admin.getIdent(), subject,
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git, subject,
fileName, content, changeId);
return push.to(git, ref);
return push.to(ref);
}
}

View File

@@ -91,11 +91,11 @@ public class VisibleRefFilterIT extends AbstractDaemonTest {
.create(new BranchInput());
allow(Permission.SUBMIT, admins, "refs/for/refs/heads/*");
PushOneCommit.Result mr = pushFactory.create(db, admin.getIdent())
.to(git, "refs/for/master%submit");
PushOneCommit.Result mr = pushFactory.create(db, admin.getIdent(), git)
.to("refs/for/master%submit");
mr.assertOkStatus();
PushOneCommit.Result br = pushFactory.create(db, admin.getIdent())
.to(git, "refs/for/branch%submit");
PushOneCommit.Result br = pushFactory.create(db, admin.getIdent(), git)
.to("refs/for/branch%submit");
br.assertOkStatus();
Repository repo = repoManager.openRepository(project);

View File

@@ -175,23 +175,23 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
protected PushOneCommit.Result createChange(Git git) throws GitAPIException,
IOException {
PushOneCommit push = pushFactory.create(db, admin.getIdent());
return push.to(git, "refs/for/master");
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git);
return push.to("refs/for/master");
}
protected PushOneCommit.Result createChange(Git git, String subject,
String fileName, String content) throws GitAPIException, IOException {
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), subject, fileName, content);
return push.to(git, "refs/for/master");
pushFactory.create(db, admin.getIdent(), git, subject, fileName, content);
return push.to("refs/for/master");
}
protected PushOneCommit.Result createChange(Git git, String subject,
String fileName, String content, String topic)
throws GitAPIException, IOException {
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), subject, fileName, content);
return push.to(git, "refs/for/master/" + topic);
pushFactory.create(db, admin.getIdent(), git, subject, fileName, content);
return push.to("refs/for/master/" + topic);
}
protected void submit(String changeId) throws IOException {

View File

@@ -129,9 +129,9 @@ public class ActionsIT extends AbstractDaemonTest {
private PushOneCommit.Result createChangeWithTopic(String topic) throws GitAPIException,
IOException {
PushOneCommit push = pushFactory.create(db, admin.getIdent());
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git);
assertThat(topic).isNotEmpty();
return push.to(git, "refs/for/master/" + topic);
return push.to("refs/for/master/" + topic);
}
static void approve(RestSession adminSession, String changeId)

View File

@@ -104,7 +104,7 @@ public class ChangeOwnerIT extends AbstractDaemonTest {
private String createMyChange() throws GitAPIException,
IOException {
PushOneCommit push = pushFactory.create(db, user.getIdent());
return push.to(git, "refs/for/master").getChangeId();
PushOneCommit push = pushFactory.create(db, user.getIdent(), git);
return push.to("refs/for/master").getChangeId();
}
}

View File

@@ -63,10 +63,10 @@ public class ConflictsOperatorIT extends AbstractDaemonTest {
checkout(git, "origin/master");
String file = conflicting ? "test.txt" : "test-" + count + ".txt";
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), "Change " + count, file,
pushFactory.create(db, admin.getIdent(), git, "Change " + count, file,
"content " + count);
count++;
return push.to(git, "refs/for/master");
return push.to("refs/for/master");
}
private Set<String> queryConflictingChanges(PushOneCommit.Result change)

View File

@@ -81,11 +81,11 @@ public class DeleteDraftPatchSetIT extends AbstractDaemonTest {
private String createDraftChangeWith2PS() throws GitAPIException,
IOException {
PushOneCommit push = pushFactory.create(db, admin.getIdent());
Result result = push.to(git, "refs/drafts/master");
push = pushFactory.create(db, admin.getIdent(), PushOneCommit.SUBJECT,
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git);
Result result = push.to("refs/drafts/master");
push = pushFactory.create(db, admin.getIdent(), git, PushOneCommit.SUBJECT,
"b.txt", "4711", result.getChangeId());
return push.to(git, "refs/drafts/master").getChangeId();
return push.to("refs/drafts/master").getChangeId();
}
private PatchSet getCurrentPatchSet(String changeId) throws OrmException {

View File

@@ -51,8 +51,8 @@ public class ListChangesOptionsIT extends AbstractDaemonTest {
String subject = "Change subject";
String fileName = "a.txt";
PushOneCommit push = pushFactory.create(
db, admin.getIdent(), subject, fileName, content, baseChangeId);
PushOneCommit.Result r = push.to(git, "refs/for/master");
db, admin.getIdent(), git, subject, fileName, content, baseChangeId);
PushOneCommit.Result r = push.to("refs/for/master");
r.assertOkStatus();
return r;
}

View File

@@ -99,8 +99,8 @@ public class GetCommitIT extends AbstractDaemonTest {
@Test
public void getOpenChange_Found() throws Exception {
allow(Permission.READ, REGISTERED_USERS, "refs/heads/*");
PushOneCommit.Result r = pushFactory.create(db, admin.getIdent())
.to(git, "refs/for/master");
PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), git)
.to("refs/for/master");
r.assertOkStatus();
CommitInfo info = getCommit(r.getCommitId());
@@ -123,8 +123,8 @@ public class GetCommitIT extends AbstractDaemonTest {
@Test
public void getOpenChange_NotFound() throws Exception {
PushOneCommit.Result r = pushFactory.create(db, admin.getIdent())
.to(git, "refs/for/master");
PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), git)
.to("refs/for/master");
r.assertOkStatus();
assertNotFound(r.getCommitId());
}

View File

@@ -43,9 +43,9 @@ public class ProjectLevelConfigIT extends AbstractDaemonTest {
cfg.setString("s1", null, "k1", "v1");
cfg.setString("s2", "ss", "k2", "v2");
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), "Create Project Level Config",
pushFactory.create(db, admin.getIdent(), git, "Create Project Level Config",
configName, cfg.toText());
push.to(git, RefNames.REFS_CONFIG);
push.to(RefNames.REFS_CONFIG);
ProjectState state = projectCache.get(project);
assertThat(state.getConfig(configName).get().toText()).isEqualTo(
@@ -73,16 +73,16 @@ public class ProjectLevelConfigIT extends AbstractDaemonTest {
fetch(parentGit, RefNames.REFS_CONFIG + ":refs/heads/config");
checkout(parentGit, "refs/heads/config");
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), "Create Project Level Config",
pushFactory.create(db, admin.getIdent(), parentGit, "Create Project Level Config",
configName, parentCfg.toText());
push.to(parentGit, RefNames.REFS_CONFIG);
push.to(RefNames.REFS_CONFIG);
Config cfg = new Config();
cfg.setString("s1", null, "k1", "childValue1");
cfg.setString("s2", "ss", "k3", "childValue2");
push = pushFactory.create(db, admin.getIdent(), "Create Project Level Config",
push = pushFactory.create(db, admin.getIdent(), git, "Create Project Level Config",
configName, cfg.toText());
push.to(git, RefNames.REFS_CONFIG);
push.to(RefNames.REFS_CONFIG);
ProjectState state = projectCache.get(project);

View File

@@ -50,16 +50,16 @@ public class TagsIT extends AbstractDaemonTest {
grant(Permission.PUSH, project, "refs/tags/*");
PushOneCommit.Tag tag1 = new PushOneCommit.Tag("v1.0");
PushOneCommit push1 = pushFactory.create(db, admin.getIdent());
PushOneCommit push1 = pushFactory.create(db, admin.getIdent(), git);
push1.setTag(tag1);
PushOneCommit.Result r1 = push1.to(git, "refs/for/master%submit");
PushOneCommit.Result r1 = push1.to("refs/for/master%submit");
r1.assertOkStatus();
PushOneCommit.AnnotatedTag tag2 =
new PushOneCommit.AnnotatedTag("v2.0", "annotation", admin.getIdent());
PushOneCommit push2 = pushFactory.create(db, admin.getIdent());
PushOneCommit push2 = pushFactory.create(db, admin.getIdent(), git);
push2.setTag(tag2);
PushOneCommit.Result r2 = push2.to(git, "refs/for/master%submit");
PushOneCommit.Result r2 = push2.to("refs/for/master%submit");
r2.assertOkStatus();
List<TagInfo> result =
@@ -86,16 +86,16 @@ public class TagsIT extends AbstractDaemonTest {
grant(Permission.PUSH, project, "refs/tags/*");
PushOneCommit.Tag tag1 = new PushOneCommit.Tag("v1.0");
PushOneCommit push1 = pushFactory.create(db, admin.getIdent());
PushOneCommit push1 = pushFactory.create(db, admin.getIdent(), git);
push1.setTag(tag1);
PushOneCommit.Result r1 = push1.to(git, "refs/for/master%submit");
PushOneCommit.Result r1 = push1.to("refs/for/master%submit");
r1.assertOkStatus();
pushTo("refs/heads/hidden");
PushOneCommit.Tag tag2 = new PushOneCommit.Tag("v2.0");
PushOneCommit push2 = pushFactory.create(db, admin.getIdent());
PushOneCommit push2 = pushFactory.create(db, admin.getIdent(), git);
push2.setTag(tag2);
PushOneCommit.Result r2 = push2.to(git, "refs/for/hidden%submit");
PushOneCommit.Result r2 = push2.to("refs/for/hidden%submit");
r2.assertOkStatus();
List<TagInfo> result =
@@ -121,9 +121,9 @@ public class TagsIT extends AbstractDaemonTest {
grant(Permission.PUSH, project, "refs/tags/*");
PushOneCommit.Tag tag1 = new PushOneCommit.Tag("v1.0");
PushOneCommit push1 = pushFactory.create(db, admin.getIdent());
PushOneCommit push1 = pushFactory.create(db, admin.getIdent(), git);
push1.setTag(tag1);
PushOneCommit.Result r1 = push1.to(git, "refs/for/master%submit");
PushOneCommit.Result r1 = push1.to("refs/for/master%submit");
r1.assertOkStatus();
RestResponse response =

View File

@@ -87,9 +87,9 @@ public class CommentsIT extends AbstractDaemonTest {
for (Integer line : lines) {
String file = "file";
String contents = "contents " + line;
PushOneCommit push = pushFactory.create(db, admin.getIdent(),
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git,
"first subject", file, contents);
PushOneCommit.Result r = push.to(git, "refs/for/master");
PushOneCommit.Result r = push.to("refs/for/master");
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
ReviewInput input = new ReviewInput();
@@ -161,9 +161,9 @@ public class CommentsIT extends AbstractDaemonTest {
for (Integer line : lines) {
String file = "file";
String contents = "contents " + line;
PushOneCommit push = pushFactory.create(db, admin.getIdent(),
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git,
"first subject", file, contents);
PushOneCommit.Result r = push.to(git, "refs/for/master");
PushOneCommit.Result r = push.to("refs/for/master");
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
ReviewInput input = new ReviewInput();

View File

@@ -50,8 +50,8 @@ public class GetRelatedIT extends AbstractDaemonTest {
@Test
public void getRelatedNoResult() throws Exception {
PushOneCommit push = pushFactory.create(db, admin.getIdent());
PatchSet.Id ps = push.to(git, "refs/for/master").getPatchSetId();
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git);
PatchSet.Id ps = push.to("refs/for/master").getPatchSetId();
List<ChangeAndCommit> related = getRelated(ps);
assertThat(related).isEmpty();
}

View File

@@ -127,15 +127,15 @@ public class LabelTypeIT extends AbstractDaemonTest {
String file = "a.txt";
String contents = "contents";
PushOneCommit push = pushFactory.create(db, admin.getIdent(),
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git,
"first subject", file, contents);
PushOneCommit.Result r = push.to(git, "refs/for/master");
PushOneCommit.Result r = push.to("refs/for/master");
revision(r).review(ReviewInput.recommend());
assertApproval(r, 1);
push = pushFactory.create(db, admin.getIdent(),
push = pushFactory.create(db, admin.getIdent(), git,
"second subject", file, contents, r.getChangeId());
r = push.to(git, "refs/for/master");
r = push.to("refs/for/master");
assertApproval(r, 0);
}
@@ -146,15 +146,15 @@ public class LabelTypeIT extends AbstractDaemonTest {
codeReview.setCopyAllScoresIfNoCodeChange(true);
saveLabelConfig();
PushOneCommit push = pushFactory.create(db, admin.getIdent(),
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git,
"first subject", file, contents);
PushOneCommit.Result r = push.to(git, "refs/for/master");
PushOneCommit.Result r = push.to("refs/for/master");
revision(r).review(ReviewInput.recommend());
assertApproval(r, 1);
push = pushFactory.create(db, admin.getIdent(),
push = pushFactory.create(db, admin.getIdent(), git,
"second subject", file, contents, r.getChangeId());
r = push.to(git, "refs/for/master");
r = push.to("refs/for/master");
assertApproval(r, 1);
}
@@ -164,18 +164,18 @@ public class LabelTypeIT extends AbstractDaemonTest {
String file = "a.txt";
String contents = "contents";
PushOneCommit push = pushFactory.create(db, admin.getIdent());
PushOneCommit.Result r1 = push.to(git, "refs/for/master");
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git);
PushOneCommit.Result r1 = push.to("refs/for/master");
merge(r1);
push = pushFactory.create(db, admin.getIdent(),
push = pushFactory.create(db, admin.getIdent(), git,
"non-conflicting", "b.txt", "other contents");
PushOneCommit.Result r2 = push.to(git, "refs/for/master");
PushOneCommit.Result r2 = push.to("refs/for/master");
merge(r2);
git.checkout().setName(r1.getCommit().name()).call();
push = pushFactory.create(db, admin.getIdent(), subject, file, contents);
PushOneCommit.Result r3 = push.to(git, "refs/for/master");
push = pushFactory.create(db, admin.getIdent(), git, subject, file, contents);
PushOneCommit.Result r3 = push.to("refs/for/master");
revision(r3).review(ReviewInput.recommend());
assertApproval(r3, 1);
@@ -191,18 +191,18 @@ public class LabelTypeIT extends AbstractDaemonTest {
codeReview.setCopyAllScoresOnTrivialRebase(true);
saveLabelConfig();
PushOneCommit push = pushFactory.create(db, admin.getIdent());
PushOneCommit.Result r1 = push.to(git, "refs/for/master");
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git);
PushOneCommit.Result r1 = push.to("refs/for/master");
merge(r1);
push = pushFactory.create(db, admin.getIdent(),
push = pushFactory.create(db, admin.getIdent(), git,
"non-conflicting", "b.txt", "other contents");
PushOneCommit.Result r2 = push.to(git, "refs/for/master");
PushOneCommit.Result r2 = push.to("refs/for/master");
merge(r2);
git.checkout().setName(r1.getCommit().name()).call();
push = pushFactory.create(db, admin.getIdent(), subject, file, contents);
PushOneCommit.Result r3 = push.to(git, "refs/for/master");
push = pushFactory.create(db, admin.getIdent(), git, subject, file, contents);
PushOneCommit.Result r3 = push.to("refs/for/master");
revision(r3).review(ReviewInput.recommend());
assertApproval(r3, 1);
@@ -218,9 +218,9 @@ public class LabelTypeIT extends AbstractDaemonTest {
PushOneCommit.Result r1 = createChange();
git.checkout().setName(r1.getCommit().name()).call();
PushOneCommit push = pushFactory.create(db, admin.getIdent(),
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git,
PushOneCommit.SUBJECT, "b.txt", "other contents");
PushOneCommit.Result r2 = push.to(git, "refs/for/master");
PushOneCommit.Result r2 = push.to("refs/for/master");
revision(r2).review(ReviewInput.recommend());
@@ -248,9 +248,9 @@ public class LabelTypeIT extends AbstractDaemonTest {
git.checkout().setName(r1.getCommit().name()).call();
PushOneCommit push = pushFactory.create(db, admin.getIdent(),
PushOneCommit push = pushFactory.create(db, admin.getIdent(), git,
PushOneCommit.SUBJECT, "b.txt", "other contents");
PushOneCommit.Result r2 = push.to(git, "refs/for/master");
PushOneCommit.Result r2 = push.to("refs/for/master");
revision(r2).review(ReviewInput.recommend());