private void testDeleteRemoteRef(String refSpec) throws Exception { Preconditions.checkArgument(refSpec.startsWith(":") && refSpec.length() > 1); String refName = refSpec.substring(1); Optional<Ref> ref = getRef(remoteRepo, refName); assertTrue(ref.isPresent()); PushOp push = pushOp(); push.addRefSpec(refSpec); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), ref, absent()); assertFalse(remoteRepo.command(RefParse.class).setName(refName).call().isPresent()); }
private void testDeleteRemoteRef(String refSpec) throws Exception { Preconditions.checkArgument(refSpec.startsWith(":") && refSpec.length() > 1); String refName = refSpec.substring(1); Optional<Ref> ref = getRef(remoteRepo, refName); assertTrue(ref.isPresent()); PushOp push = pushOp(); push.addRefSpec(refSpec); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), ref, absent()); assertFalse(remoteRepo.command(RefParse.class).setName(refName).call().isPresent()); }
@Test public void testPushTooManyRefArgs() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedBranch.addFirst(commit); // Push the commit PushOp push = pushOp(); push.addRefSpec("Branch1:master:HEAD"); exception.expect(IllegalArgumentException.class); push.call(); } }
@Test public void testPushTooManyRefArgs() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedBranch.addFirst(commit); // Push the commit PushOp push = pushOp(); push.addRefSpec("Branch1:master:HEAD"); exception.expect(IllegalArgumentException.class); push.call(); } }
@Test public void testPushWithDefaultRefSpec() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); Optional<Ref> oldBranch = getRef(remoteRepo, "master"); // Push the commit PushOp push = pushOp(); push.addRefSpec(":"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "master")); // verify that the remote got the commit List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); }
@Test public void testPushWithDefaultRefSpec() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); Optional<Ref> oldBranch = getRef(remoteRepo, "master"); // Push the commit PushOp push = pushOp(); push.addRefSpec(":"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "master")); // verify that the remote got the commit List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); }
@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 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 testPushToRemoteHEAD() throws Exception { insertAndAdd(localRepo, lines3); localRepo.command(CommitOp.class).call(); PushOp push = pushOp(); try { push.setRemote("origin").addRefSpec("HEAD").call(); fail(); } catch (SynchronizationException e) { assertEquals(SynchronizationException.StatusCode.CANNOT_PUSH_TO_SYMBOLIC_REF, e.statusCode); } }
@Test public void testPushToRemoteHEAD() throws Exception { insertAndAdd(localRepo, lines3); localRepo.command(CommitOp.class).call(); PushOp push = pushOp(); try { push.setRemote("origin").addRefSpec("HEAD").call(); fail(); } catch (SynchronizationException e) { assertEquals(SynchronizationException.StatusCode.CANNOT_PUSH_TO_SYMBOLIC_REF, e.statusCode); } }
@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 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 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 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 testPushBranch() throws Exception { // 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.call(); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "Branch1")); // verify that the remote got the commit Optional<Ref> remoteRef = remoteRepo.command(RefParse.class).setName("Branch1").call(); assertTrue(remoteRef.isPresent()); assertTrue(remoteRef.get().getName().startsWith(Ref.HEADS_PREFIX)); remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedBranch, logged); }
@Test public void testPushBranch() throws Exception { // 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.call(); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "Branch1")); // verify that the remote got the commit Optional<Ref> remoteRef = remoteRepo.command(RefParse.class).setName("Branch1").call(); assertTrue(remoteRef.isPresent()); assertTrue(remoteRef.get().getName().startsWith(Ref.HEADS_PREFIX)); remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedBranch, logged); }
@Test public void testPushBranchNoForce() throws Exception { // Add a commit to the remote repository remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); insertAndAdd(remoteRepo, points1_modified); RevCommit remotesTip = remoteRepo.command(CommitOp.class).call(); // Add a commit to the local repository localRepo.command(CheckoutOp.class).setSource("Branch1").call(); insertAndAdd(localRepo, lines3); localRepo.command(CommitOp.class).call(); // Push the commit PushOp push = pushOp(); push.addRefSpec("Branch1"); try { push.setProgressListener(SIMPLE_PROGRESS).call(); fail(); } catch (SynchronizationException e) { assertEquals(StatusCode.REMOTE_HAS_CHANGES, e.statusCode); } // verify that the remote got the commit remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals("remote shouldn't have changed", remotesTip, logged.get(0)); }
@Test public void testPushBranchNoForce() throws Exception { // Add a commit to the remote repository remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); insertAndAdd(remoteRepo, points1_modified); RevCommit remotesTip = remoteRepo.command(CommitOp.class).call(); // Add a commit to the local repository localRepo.command(CheckoutOp.class).setSource("Branch1").call(); insertAndAdd(localRepo, lines3); localRepo.command(CommitOp.class).call(); // Push the commit PushOp push = pushOp(); push.addRefSpec("Branch1"); try { push.setProgressListener(SIMPLE_PROGRESS).call(); fail(); } catch (SynchronizationException e) { assertEquals(StatusCode.REMOTE_HAS_CHANGES, e.statusCode); } // verify that the remote got the commit remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals("remote shouldn't have changed", remotesTip, logged.get(0)); }
@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); }