@Given("^I have staged \"([^\"]*)\" on the \"([^\"]*)\" repo in the \"([^\"]*)\" transaction$") public void I_have_staged(String feature, String repoName, String txId) throws Throwable { TestData data = I_have_unstaged(feature, repoName, txId); data.add(); // add the repo to the set so it can be closed openedRepos.add(repoName); }
@Given("^There is a repository with multiple branches named ([^\"]*)$") public void setUpMultipleBranches(String name) throws Throwable { Repository repo = context.createRepo(name).init("webuser", "webuser@test.com").getRepo(); TestData data = new TestData(repo); data.addAndCommit("Added Point.1", TestData.point1); data.branch("non_conflicting"); data.branch("conflicting"); data.addAndCommit("Modified Point.1", TestData.point1_modified); data.branch("master_original"); data.checkout("conflicting"); data.remove(TestData.point1); data.add(); data.commit("Removed Point.1"); data.checkout("non_conflicting"); data.addAndCommit("Added Point.2", TestData.point2); data.checkout("master"); repo.close(); openedRepos.add(name); }
public TestData addAndCommit(String commitMessage, SimpleFeature... features) { return insert(features).add().commit(commitMessage); }
@Given("^There are conflicts on the \"([^\"]*)\" repo in the (@[^\"]*) transaction$") public void There_are_conflict(String repoName, String txId) throws Throwable { Repository repo = context.getRepo(repoName); TestData data = new TestData(repo); GeogigTransaction transaction = repo.command(TransactionResolve.class) .setId(UUID.fromString(context.getVariable(txId))).call().get(); data.setTransaction(transaction); data.addAndCommit("Added Point.1", TestData.point1); data.branch("branch1"); data.addAndCommit("Modified Point.1", TestData.point1_modified); data.checkout("branch1"); data.remove(TestData.point1); data.add(); data.commit("Removed Point.1"); data.checkout("master"); try { data.mergeNoFF("branch1", "Merge branch1"); } catch (MergeConflictsException e) { // Expected } assertEquals(1, transaction.command(ConflictsCountOp.class).call().longValue()); // add the repo to the set so it can be closed openedRepos.add(repoName); }
public TestData addAndCommit(String commitMessage, SimpleFeature... features) { return insert(features).add().commit(commitMessage); }
@Given("^I have committed \"([^\"]*)\" on the \"([^\"]*)\" repo in the \"([^\"]*)\" transaction$") public void I_have_committed(String feature, String repoName, String txId) throws Throwable { TestData data = I_have_unstaged(feature, repoName, txId); data.add(); data.commit("Added " + feature); // add the repo to the set so it can be closed openedRepos.add(repoName); }
private void createConflicts(SimpleFeature... features) { for (SimpleFeature base : features) { SimpleFeature toOrigin = TestData.clone(base); toOrigin.setAttribute("sp", "modified on origin"); origin.checkout("master").insert(toOrigin).add() .commit(String.format("change %s on origin", base.getID())); SimpleFeature toClone = TestData.clone(base); toClone.setAttribute("sp", "modified on fork"); clone.checkout("issuerBranch").insert(toClone).add() .commit(String.format("change %s on clone", base.getID())); } }
private void createConflicts(SimpleFeature... features) { for (SimpleFeature base : features) { SimpleFeature toOrigin = TestData.clone(base); toOrigin.setAttribute("sp", "modified on origin"); origin.checkout("master").insert(toOrigin).add() .commit(String.format("change %s on origin", base.getID())); SimpleFeature toClone = TestData.clone(base); toClone.setAttribute("sp", "modified on fork"); clone.checkout("issuerBranch").insert(toClone).add() .commit(String.format("change %s on clone", base.getID())); } }
@Given("^I have removed \"([^\"]*)\" on the \"([^\"]*)\" repo in the \"([^\"]*)\" transaction$") public void I_have_removed(String feature, String repoName, String txId) throws Exception { Repository repo = context.getRepo(repoName); TestData data = new TestData(repo); if (!txId.isEmpty()) { GeogigTransaction transaction = repo.command(TransactionResolve.class) .setId(UUID.fromString(context.getVariable(txId))).call().get(); data.setTransaction(transaction); } data.remove(parseFeature(feature)); data.add(); data.commit("Removed " + feature); // add the repo to the set so it can be closed openedRepos.add(repoName); }
public @Test void healthCheckBehindTargetBranch() { // fake PRPrepareOp fakeUpToDate(); origin.checkout("master").insert(TestData.line2).add().commit("l2").insert(TestData.line3) .add().commit("l3"); PRStatus status = origin.getRepo().command(PRHealthCheckOp.class).setId(request.getId()) .call(); assertNotNull(status); assertEquals(request, status.getRequest()); assertEquals(Sets.newHashSet("Lines", "Points", "Polygons"), Sets.newHashSet(status.getAffectedLayers())); Optional<ObjectId> mergeCommit = status.getMergeCommit(); assertFalse(mergeCommit.toString(), mergeCommit.isPresent()); assertEquals(0, status.getCommitsBehindRemoteBranch()); assertEquals(2, status.getCommitsBehindTargetBranch()); assertEquals(0, status.getNumConflicts()); }
public @Before void before() { origin = testSupport.newRepo("origin"); origin.loadDefaultData(); clone = testSupport.clone(origin, "clone"); commonAncestor = Iterators.getLast(origin.log("master")); origin.resetHard(commonAncestor.getId()); TestData.point1_modified.setAttribute("sp", "modified by clone"); clone.branchAndCheckout("issuerBranch")// .resetHard(commonAncestor.getId())// .remove(TestData.line1).add().commit("remove line1")// .insert(TestData.poly4).add().commit("add poly 4")// .insert(TestData.point1_modified).add().commit("modify point1"); PRInitOp prinit = PRInitOp.builder()// .id(1)// .remoteURI(clone.getRepo().getLocation())// .remoteBranch("issuerBranch")// .targetBranch("master")// .title("first PR")// .description(null)// .build(); prinit.setContext(origin.getContext()); request = prinit.call(); assertNotNull(request); }
public @Before void before() { origin = testSupport.newRepo("origin"); origin.loadDefaultData(); clone = testSupport.clone(origin, "clone"); commonAncestor = Iterators.getLast(origin.log("master")); origin.resetHard(commonAncestor.getId()); TestData.point1_modified.setAttribute("sp", "modified by clone"); clone.branchAndCheckout("issuerBranch")// .resetHard(commonAncestor.getId())// .remove(TestData.line1).add().commit("remove line1")// .insert(TestData.poly4).add().commit("add poly 4")// .insert(TestData.point1_modified).add().commit("modify point1"); PRInitOp prinit = PRInitOp.builder()// .id(1)// .remoteURI(clone.getRepo().getLocation())// .remoteBranch("issuerBranch")// .targetBranch("master")// .title("first PR")// .description(null)// .build(); prinit.setContext(origin.getContext()); request = prinit.call(); assertNotNull(request); }
public @Before void before() { origin = testSupport.newRepo("origin"); origin.loadDefaultData(); clone = testSupport.clone(origin, "clone"); commonAncestor = Iterators.getLast(origin.log("master")); origin.resetHard(commonAncestor.getId()); TestData.point1_modified.setAttribute("sp", "modified by clone"); clone.branchAndCheckout("issuerBranch")// .resetHard(commonAncestor.getId())// .remove(TestData.line1).add().commit("remove line1")// .insert(TestData.poly4).add().commit("add poly 4")// .insert(TestData.point1_modified).add().commit("modify point1"); PRInitOp prinit = PRInitOp.builder()// .id(1)// .remoteURI(clone.getRepo().getLocation())// .remoteBranch("issuerBranch")// .targetBranch("master")// .title("first PR")// .description(null)// .build(); prinit.setContext(origin.getRepo().context()); request = prinit.call(); assertNotNull(request); }
public @Test void prepareAndManuallyResolveAllConflicts() { createConflicts(TestData.point1, TestData.line1, TestData.poly1); PRStatus result = prepare(); assertEquals(3, result.getNumConflicts()); final UUID transactionId = request.getTransactionId(); origin.resumeTransaction(transactionId); assertEquals(request.getTargetBranch(), origin.getRef("HEAD").peel().localName()); //@formatter:off SimpleFeature c1 = TestData.clone(TestData.point1); c1.setAttribute("sp", "manually set"); SimpleFeature c2 = TestData.clone(TestData.line1); c2.setAttribute("sp", "manually set"); SimpleFeature c3 = TestData.clone(TestData.poly1); c3.setAttribute("sp", "manually set"); //@formatter:on Context context = clone.checkout("issuerBranch").getContext(); try { PullResult pres = context.command(PullOp.class).addRefSpec("master").call(); fail("Expected MergeConflictsException , got " + pres); } catch (MergeConflictsException e) { assertEquals(3, e.getReport().getConflicts()); clone.insert(c1, c2, c3).add().commit("manual conflict fix"); } result = prepare(); assertTrue(result.getMergeCommit().isPresent()); assertTrue(result.getReport().isPresent()); GeogigTransaction prtx = getTransaction(); Optional<Ref> mergeRef = request.resolveMergeRef(prtx); assertTrue(mergeRef.isPresent()); assertEquals(result.getMergeCommit().get(), mergeRef.get().getObjectId()); }
public @Test void testResolve() { origin.loadDefaultData()// .checkout("branch1")// .branchAndCheckout("issuerBranch")// .remove(TestData.line2).add().commit("remove line2"); PRInitOp prinit = PRInitOp.builder()// .id(1)// .remoteURI(origin.getRepo().getLocation())// .remoteBranch("issuerBranch")// .targetBranch("branch1")// .title("first PR")// .description(null)// .build(); prinit.setContext(origin.getRepo().context()); PR request = prinit.call(); Optional<PR> resolved = origin.getRepo().command(PRFindOp.class).setId(request.getId()) .call(); assertTrue(resolved.isPresent()); assertEquals(request, resolved.get()); assertFalse(origin.getRepo().command(PRFindOp.class).setId(1 + request.getId()).call() .isPresent()); } }
public @Test void healthCheckWithConflicts() { // fake PRPrepareOp fakeUpToDate(); TestData.point1_modified.setAttribute("sp", "changed on pr target repo"); origin.checkout("master").insert(TestData.point1_modified).add().commit("ci for conflict"); GeogigTransaction tx = request.getTransaction(origin.getRepo().context()); tx.command(UpdateRef.class).setName("refs/heads/" + request.getTargetBranch()) .setNewValue(origin.getRef(request.getTargetBranch()).getObjectId()); tx.command(CheckoutOp.class).setSource(request.getTargetBranch()).call(); tx.command(ResetOp.class).setCommit(origin.getRef(request.getTargetBranch()).getObjectId()) .setMode(ResetMode.HARD).call(); ObjectId localRemoteCommit = clone.getRef(request.getRemoteBranch()).getObjectId(); try { tx.command(MergeOp.class).addCommit(localRemoteCommit).call(); fail("Expected MergeConflictsException"); } catch (MergeConflictsException expected) { // } PRStatus status = origin.getRepo().command(PRHealthCheckOp.class).setId(request.getId()) .call(); assertNotNull(status); assertEquals(request, status.getRequest()); assertEquals(Sets.newHashSet("Lines", "Points", "Polygons"), Sets.newHashSet(status.getAffectedLayers())); Optional<ObjectId> mergeCommit = status.getMergeCommit(); assertFalse(mergeCommit.toString(), mergeCommit.isPresent()); assertEquals(0, status.getCommitsBehindRemoteBranch()); assertEquals(1, status.getCommitsBehindTargetBranch()); assertEquals(1, status.getNumConflicts()); }
public @Test void healthCheckTestMergeDoneButOutDated() { // fake PRPrepareOp fakeUpToDate(); GeogigTransaction tx = request.getTransaction(origin.getRepo().context()); tx.command(UpdateRef.class).setName("refs/heads/" + request.getTargetBranch()) .setNewValue(origin.getRef(request.getTargetBranch()).getObjectId()); tx.command(CheckoutOp.class).setSource(request.getTargetBranch()).call(); tx.command(ResetOp.class).setCommit(origin.getRef(request.getTargetBranch()).getObjectId()) .setMode(ResetMode.HARD).call(); ObjectId localRemoteCommit = clone.getRef(request.getRemoteBranch()).getObjectId(); RevCommit merge = tx.command(MergeOp.class).addCommit(localRemoteCommit).call() .getMergeCommit(); tx.command(UpdateRef.class).setName(request.getMergeRef()).setNewValue(merge.getId()) .call(); origin.checkout("master").insert(TestData.line2).add().commit("ahead commit"); PRStatus status = origin.getRepo().command(PRHealthCheckOp.class).setId(request.getId()) .call(); assertNotNull(status); assertEquals(request, status.getRequest()); assertEquals(Sets.newHashSet("Lines", "Points", "Polygons"), Sets.newHashSet(status.getAffectedLayers())); Optional<ObjectId> mergeCommit = status.getMergeCommit(); assertTrue(mergeCommit.toString(), mergeCommit.isPresent()); assertEquals(0, status.getCommitsBehindRemoteBranch()); assertEquals(1, status.getCommitsBehindTargetBranch()); assertEquals(0, status.getNumConflicts()); }