private PushOperation createInvalidPushOperation() throws Exception {
   // set up push with invalid URI to provoke an exception
   PushOperationSpecification spec = new PushOperationSpecification();
   // the remote is invalid
   URIish remote = new URIish(INVALID_URI);
   // update master upon master
   Repository local = repository1;
   RemoteRefUpdate update =
       new RemoteRefUpdate(local, "HEAD", "refs/heads/test", false, null, null);
   spec.addURIRefUpdates(remote, Collections.singletonList(update));
   // now we can construct the push operation
   PushOperation pop = new PushOperation(local, spec, false, 0);
   return pop;
 }
  @Test
  public void testUpdateTrackingBranchIfSpecifiedInRemoteRefUpdate() throws Exception {
    // Commit on repository 2
    //		RevCommit commit = repository2.addAndCommit(project, new File(workdir2, "test.txt"), "Commit
    // in repository 2");
    System.out.println(repository2.getBranch());
    new Git(repository2).checkout().setName("refs/heads/test").call();
    System.out.println(repository2.getBranch());
    ArrayList<String> files = new ArrayList<String>();
    File file = new File(workdir2, "test.txt");
    FileUtils.createNewFile(file);
    repositoryUtil.appendFileContent(file, "create file of test.txt in repository 2");
    files.add(repositoryUtil.getRepoRelativePath(file.getAbsolutePath()));

    AddToIndexOperation trop = new AddToIndexOperation(files, repository2);
    trop.execute();

    CommitOperation cop =
        new CommitOperation(repository2, files, files, AUTHOR, COMMITTER, "Commit in repository 2");
    cop.execute();
    // We want to push from repository 2 to 1 (because repository 2 already
    // has tracking set up)
    //		URIish remote = repository1.getUri();
    URIish remote = new URIish("file:///" + repository1.getDirectory().toString());

    String trackingRef = "refs/remotes/origin/master";
    RemoteRefUpdate update =
        new RemoteRefUpdate(repository2, "HEAD", "refs/heads/master", false, trackingRef, null);
    PushOperationSpecification spec = new PushOperationSpecification();
    spec.addURIRefUpdates(remote, Arrays.asList(update));

    PushOperation push = new PushOperation(repository2, spec, false, 0);
    push.execute();

    PushOperationResult result = push.getOperationResult();
    PushResult pushResult = result.getPushResult(remote);
    TrackingRefUpdate trf = pushResult.getTrackingRefUpdate(trackingRef);
    System.out.println(trf.getLocalName());
    System.out.println(trf.getRemoteName());
    assertNotNull(
        "Expected result to have tracking ref update",
        pushResult.getTrackingRefUpdate(trackingRef));

    ObjectId trackingId = repository2.resolve(trackingRef);
    assertEquals("Expected tracking branch to be updated", cop.getCommit().getId(), trackingId);
    new Git(repository1).checkout().setName("refs/heads/master").call();
    File testFile = new File(workdir2, repositoryUtil.getRepoRelativePath(file.getAbsolutePath()));
    assertTrue(testFile.exists());
  }
 private PushOperation createPushOperation() throws Exception {
   // set up push from repository1 to repository2
   // we cannot re-use the RemoteRefUpdate!!!
   PushOperationSpecification spec = new PushOperationSpecification();
   // the remote is repo2
   URIish remote = new URIish("file:///" + repository2.getDirectory().toString());
   // update master upon master
   List<RemoteRefUpdate> refUpdates = new ArrayList<RemoteRefUpdate>();
   RemoteRefUpdate update =
       new RemoteRefUpdate(repository1, "HEAD", "refs/heads/test", false, null, null);
   refUpdates.add(update);
   spec.addURIRefUpdates(remote, refUpdates);
   // now we can construct the push operation
   PushOperation pop = new PushOperation(repository1, spec, false, 0);
   return pop;
 }