public static void verifySameContents(Repository source, Repository copy) { Set<ObjectId> sourceIds = verifyRepositoryContents(source); Set<ObjectId> copyIds = verifyRepositoryContents(copy); if (!copyIds.containsAll(sourceIds)) { Set<ObjectId> missing = Sets.difference(sourceIds, copyIds); fail(missing.size() + " missing ids on copy:"); } }
public static void verifySameContents(Repository source, Repository copy) { Set<ObjectId> sourceIds = verifyRepositoryContents(source); Set<ObjectId> copyIds = verifyRepositoryContents(copy); if (!copyIds.containsAll(sourceIds)) { Set<ObjectId> missing = Sets.difference(sourceIds, copyIds); fail(missing.size() + " missing ids on copy:"); } }
@Test public void testCloneEmptyRepo() throws Exception { CloneOp clone = cloneOp(); // clone.setRepositoryURL(remoteGeogig.envHome.toURI().toString()).call(); clone.setRemoteURI(remoteGeogig.envHome.toURI()).setCloneURI(localGeogig.envHome.toURI()) .call(); TestSupport.verifyRepositoryContents(cloneRepo); }
@Test public void testCloneEmptyRepo() throws Exception { CloneOp clone = cloneOp(); // clone.setRepositoryURL(remoteGeogig.envHome.toURI().toString()).call(); clone.setRemoteURI(remoteGeogig.envHome.toURI()).setCloneURI(localGeogig.envHome.toURI()) .call(); TestSupport.verifyRepositoryContents(cloneRepo); }
private void verifyFetch() throws Exception { // Make sure the local repository got all of the commits from master localGeogig.geogig.command(CheckoutOp.class).setSource("refs/remotes/origin/master").call(); Iterator<RevCommit> logs = localGeogig.geogig.command(LogOp.class).call(); List<RevCommit> logged = Lists.newArrayList(logs); assertEquals(expectedMaster, logged); // Make sure the local repository got all of the commits from Branch1 localGeogig.geogig.command(CheckoutOp.class).setSource("refs/remotes/origin/Branch1") .call(); logs = localGeogig.geogig.command(LogOp.class).call(); logged = Lists.newArrayList(logs); assertEquals(expectedBranch, logged); List<RevTag> tags = localGeogig.geogig.command(TagListOp.class).call(); assertEquals(1, tags.size()); TestSupport.verifyRepositoryContents(localGeogig.geogig.getRepository()); }
private void verifyFetch() throws Exception { // Make sure the local repository got all of the commits from master localGeogig.geogig.command(CheckoutOp.class).setSource("refs/remotes/origin/master").call(); Iterator<RevCommit> logs = localGeogig.geogig.command(LogOp.class).call(); List<RevCommit> logged = Lists.newArrayList(logs); assertEquals(expectedMaster, logged); // Make sure the local repository got all of the commits from Branch1 localGeogig.geogig.command(CheckoutOp.class).setSource("refs/remotes/origin/Branch1") .call(); logs = localGeogig.geogig.command(LogOp.class).call(); logged = Lists.newArrayList(logs); assertEquals(expectedBranch, logged); List<RevTag> tags = localGeogig.geogig.command(TagListOp.class).call(); assertEquals(1, tags.size()); TestSupport.verifyRepositoryContents(localGeogig.geogig.getRepository()); }
assertTrue(localTags.contains(tag)); TestSupport.verifyRepositoryContents(cloneRepo);
@Test public void testPushNewBranch() throws Exception { localRepo.command(BranchCreateOp.class).setName("newbranch").call(); localRepo.command(CheckoutOp.class).setSource("newbranch").call(); // Add a commit to the local repository insertAndAdd(localRepo, lines3); insertAndAdd(localRepo, points1_modified); localRepo.command(CommitOp.class).call(); final Ref branch1 = getRef(localRepo, "newbranch").get(); // Push the commit PushOp push = pushOp(); push.addRefSpec("newbranch"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), absent(), Optional.of(new Ref("refs/heads/newbranch", branch1.getObjectId()))); TestSupport.verifyRepositoryContents(remoteRepo); }
@Test public void testPushWithMultipleRefSpecs() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); final Ref master = getRef(localRepo, "master").get(); final Ref branch1 = getRef(localRepo, "Branch1").get(); // Push the commit PushOp push = pushOp(); push.addRefSpec("master:NewRemoteBranch"); push.addRefSpec("Branch1:NewRemoteBranch2"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), absent(), Optional.of(new Ref("refs/heads/NewRemoteBranch", master.getObjectId()))); assertSummary(summary, remote.getPushURL(), absent(), Optional.of(new Ref("refs/heads/NewRemoteBranch2", branch1.getObjectId()))); assertTrue( remoteRepo.command(RefParse.class).setName("NewRemoteBranch").call().isPresent()); assertTrue( remoteRepo.command(RefParse.class).setName("NewRemoteBranch2").call().isPresent()); // verify that the remote got the commit remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch2").call(); logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedBranch, logged); TestSupport.verifyRepositoryContents(remoteRepo); }
assertTrue(localTags.contains(tag)); TestSupport.verifyRepositoryContents(cloneRepo);
@Test public void testPushNewBranch() throws Exception { localRepo.command(BranchCreateOp.class).setName("newbranch").call(); localRepo.command(CheckoutOp.class).setSource("newbranch").call(); // Add a commit to the local repository insertAndAdd(localRepo, lines3); insertAndAdd(localRepo, points1_modified); localRepo.command(CommitOp.class).call(); final Ref branch1 = getRef(localRepo, "newbranch").get(); // Push the commit PushOp push = pushOp(); push.addRefSpec("newbranch"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), absent(), Optional.of(new Ref("refs/heads/newbranch", branch1.getObjectId()))); TestSupport.verifyRepositoryContents(remoteRepo); }
@Test public void testPushWithMultipleRefSpecs() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); final Ref master = getRef(localRepo, "master").get(); final Ref branch1 = getRef(localRepo, "Branch1").get(); // Push the commit PushOp push = pushOp(); push.addRefSpec("master:NewRemoteBranch"); push.addRefSpec("Branch1:NewRemoteBranch2"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), absent(), Optional.of(new Ref("refs/heads/NewRemoteBranch", master.getObjectId()))); assertSummary(summary, remote.getPushURL(), absent(), Optional.of(new Ref("refs/heads/NewRemoteBranch2", branch1.getObjectId()))); assertTrue( remoteRepo.command(RefParse.class).setName("NewRemoteBranch").call().isPresent()); assertTrue( remoteRepo.command(RefParse.class).setName("NewRemoteBranch2").call().isPresent()); // verify that the remote got the commit remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch2").call(); logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedBranch, logged); TestSupport.verifyRepositoryContents(remoteRepo); }
@Test public void testPushWithRefSpec() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); // Push the commit PushOp push = pushOp(); push.addRefSpec("master:NewRemoteBranch"); TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call(); assertSummary(summary, remote.getPushURL(), null, new Ref("refs/heads/NewRemoteBranch", commit.getId())); assertTrue(getRef(remoteRepo, "NewRemoteBranch").isPresent()); // verify that the remote got the commit remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); // verify that the local reference of the remote master is updated Optional<Ref> ref = localRepo.command(RefParse.class) .setName(Ref.append(Ref.REMOTES_PREFIX, "origin/NewRemoteBranch")).call(); assertTrue(ref.isPresent()); assertEquals(logged.get(0).getId(), ref.get().getObjectId()); TestSupport.verifyRepositoryContents(remoteRepo); }
public @Test void testFetchRespectsTargeRef() throws Exception { final Repository remote = this.originRepo; final Repository local = this.localRepo; remote.command(BranchCreateOp.class).setName("branch2").setAutoCheckout(true).call(); insertAndAdd(remote, lines1_modified, lines2_modified, lines3_modified); RevCommit branch2Tip = commit(remote, "modified lines on branch2"); checkout(remote, "master"); remote.command(BranchCreateOp.class).setName("branch3").setAutoCheckout(true).call(); insertAndAdd(remote, points1_modified, points2_modified, points3_modified); RevCommit branch3Tip = commit(remote, "modified points on branch3"); checkout(remote, "master"); // fetch from the remote, fetching remote's branch2 to local's refs/custom/branch2 and // branch3 to refs/custom/branch3 explicitly FetchOp fetch = fetchOp().setAutofetchTags(false); final String refSpec = "refs/heads/branch2:refs/custom/branch2;refs/heads/branch3:refs/custom/branch3;"; Remote singleRefOrigin = origin.fetch(refSpec); TransferSummary summary = fetch.addRemote(singleRefOrigin).call(); assertFalse(getRef(local, "refs/heads/branch2").isPresent()); assertFalse(getRef(local, "refs/heads/branch3").isPresent()); assertFalse(getRef(local, "refs/remotes/origin/branch2").isPresent()); assertFalse(getRef(local, "refs/remotes/origin/branch3").isPresent()); assertTrue(getRef(local, "refs/custom/branch2").isPresent()); assertTrue(getRef(local, "refs/custom/branch2").isPresent()); assertEquals(branch2Tip.getId(), getRef(local, "refs/custom/branch2").get().getObjectId()); assertEquals(branch3Tip.getId(), getRef(local, "refs/custom/branch3").get().getObjectId()); assertEquals(1, summary.getRefDiffs().size()); assertTrue(summary.getRefDiffs().containsKey(origin.getFetchURL())); assertEquals(2, summary.getRefDiffs().get(origin.getFetchURL()).size()); TestSupport.verifyRepositoryContents(local, "refs/custom/branch2", "refs/custom/branch3"); }
@Test public void testPushWithRefSpec() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); // Push the commit PushOp push = pushOp(); push.addRefSpec("master:NewRemoteBranch"); TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call(); assertSummary(summary, remote.getPushURL(), null, new Ref("refs/heads/NewRemoteBranch", commit.getId())); assertTrue(getRef(remoteRepo, "NewRemoteBranch").isPresent()); // verify that the remote got the commit remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); // verify that the local reference of the remote master is updated Optional<Ref> ref = localRepo.command(RefParse.class) .setName(Ref.append(Ref.REMOTES_PREFIX, "origin/NewRemoteBranch")).call(); assertTrue(ref.isPresent()); assertEquals(logged.get(0).getId(), ref.get().getObjectId()); TestSupport.verifyRepositoryContents(remoteRepo); }
@Test public void testFetchSingleRef() throws Exception { final Repository remote = this.originRepo; final Repository local = this.localRepo; remote.command(BranchCreateOp.class).setName("branch2").setAutoCheckout(true).call(); insertAndAdd(remote, lines1_modified, lines2_modified, lines3_modified); RevCommit branch2Tip = commit(remote, "modified lines on branch2"); checkout(remote, "master"); remote.command(BranchCreateOp.class).setName("branch3").setAutoCheckout(true).call(); insertAndAdd(remote, points1_modified, points2_modified, points3_modified); RevCommit branch3Tip = commit(remote, "modified points on branch3"); checkout(remote, "master"); Optional<Ref> originBranch2 = Optional .of(toRemote(origin, getRef(remote, "branch2").get())); // fetch from the remote FetchOp fetch = fetchOp().setAutofetchTags(false); Remote singleRefOrigin = origin.fetch("refs/heads/branch2"); TransferSummary summary = fetch.addRemote(singleRefOrigin).call(); assertFalse(getRef(local, "refs/heads/branch2").isPresent()); assertTrue(getRef(local, "refs/remotes/origin/branch2").isPresent()); assertFalse(getRef(local, "branch3").isPresent()); assertEquals(branch2Tip.getId(), getRef(local, "refs/remotes/origin/branch2").get().getObjectId()); assertEquals(1, summary.getRefDiffs().size()); assertTrue(summary.getRefDiffs().containsKey(origin.getFetchURL())); assertEquals(1, summary.getRefDiffs().get(origin.getFetchURL()).size()); assertSummary(summary, origin.getFetchURL(), absent(), originBranch2); TestSupport.verifyRepositoryContents(local, "refs/remotes/origin/branch2"); }
TestSupport.verifyRepositoryContents(cloneRepo);
TestSupport.verifyRepositoryContents(cloneRepo);
@Test public void testPushBranchForce() throws Exception { // Add a commit to the remote repository remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); insertAndAdd(remoteRepo, points1_modified); remoteRepo.command(CommitOp.class).call(); // Add a commit to the local repository localRepo.command(CheckoutOp.class).setSource("Branch1").call(); insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedBranch.addFirst(commit); localRepo.command(CheckoutOp.class).setSource("master").call(); Optional<Ref> oldBranch = getRef(remoteRepo, "Branch1"); // Push the commit PushOp push = pushOp(); push.addRefSpec("+Branch1"); TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call(); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "Branch1")); // verify that the remote got the commit remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedBranch, logged); TestSupport.verifyRepositoryContents(remoteRepo); }
@Test public void testPushBranchForce() throws Exception { // Add a commit to the remote repository remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); insertAndAdd(remoteRepo, points1_modified); remoteRepo.command(CommitOp.class).call(); // Add a commit to the local repository localRepo.command(CheckoutOp.class).setSource("Branch1").call(); insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedBranch.addFirst(commit); localRepo.command(CheckoutOp.class).setSource("master").call(); Optional<Ref> oldBranch = getRef(remoteRepo, "Branch1"); // Push the commit PushOp push = pushOp(); push.addRefSpec("+Branch1"); TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call(); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "Branch1")); // verify that the remote got the commit remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedBranch, logged); TestSupport.verifyRepositoryContents(remoteRepo); }