Exemplo n.º 1
0
  @Test
  public void testPullConflict() throws Exception {
    PullResult res = target.pull().call();
    // nothing to update since we don't have different data yet
    assertTrue(res.getFetchResult().getTrackingRefUpdates().isEmpty());
    assertTrue(res.getMergeResult().getMergeStatus().equals(MergeStatus.ALREADY_UP_TO_DATE));

    assertFileContentsEqual(targetFile, "Hello world");

    // change the source file
    writeToFile(sourceFile, "Source change");
    source.add().addFilepattern("SomeFile.txt").call();
    source.commit().setMessage("Source change in remote").call();

    // change the target file
    writeToFile(targetFile, "Target change");
    target.add().addFilepattern("SomeFile.txt").call();
    target.commit().setMessage("Target change in local").call();

    res = target.pull().call();

    String sourceChangeString =
        "Source change\n>>>>>>> branch 'refs/heads/master' of "
            + target.getRepository().getConfig().getString("remote", "origin", "url");

    assertFalse(res.getFetchResult().getTrackingRefUpdates().isEmpty());
    assertEquals(res.getMergeResult().getMergeStatus(), MergeStatus.CONFLICTING);
    String result = "<<<<<<< HEAD\nTarget change\n=======\n" + sourceChangeString + "\n";
    assertFileContentsEqual(targetFile, result);
    assertEquals(RepositoryState.MERGING, target.getRepository().getRepositoryState());
  }
Exemplo n.º 2
0
  /*
   * Pull latest from 'source' and 'binary' repository.
   */
  public boolean gitpull() throws GitException {

    boolean result = false;

    // do 'pull' on 'source'
    Git srcgit = Git.wrap(sourceRepository);
    Git bingit = Git.wrap(binaryRepository);

    try {

      PullResult srcpull = srcgit.pull().call();
      PullResult binpull = bingit.pull().call();

      if (srcpull.isSuccessful() && binpull.isSuccessful()) {
        if (srcpull.getFetchResult() != null
            && (srcpull.getFetchResult().getTrackingRefUpdates().size() > 0)) {
          result = true;
        }
        if (srcpull.getMergeResult() != null
            && (srcpull.getMergeResult().getMergeStatus() == MergeStatus.FAST_FORWARD
                || srcpull.getMergeResult().getMergeStatus() == MergeStatus.MERGED)) {
          result = true;
        }

        // TODO: rebase status needs to be checked but it is ignored for now
      }

    } catch (WrongRepositoryStateException e) {
      throw new GitException(e);
    } catch (InvalidConfigurationException e) {
      throw new GitException(e);
    } catch (DetachedHeadException e) {
      throw new GitException(e);
    } catch (InvalidRemoteException e) {
      throw new GitException(e);
    } catch (CanceledException e) {
      throw new GitException(e);
    } catch (RefNotFoundException e) {
      throw new GitException(e);
    } catch (NoHeadException e) {
      throw new GitException(e);
    } catch (TransportException e) {
      throw new GitException(e);
    } catch (GitAPIException e) {
      throw new GitException(e);
    }

    return result;
  }
Exemplo n.º 3
0
  @Test
  public void testPullLocalConflict() throws Exception {
    target
        .branchCreate()
        .setName("basedOnMaster")
        .setStartPoint("refs/heads/master")
        .setUpstreamMode(SetupUpstreamMode.TRACK)
        .call();
    target.getRepository().updateRef(Constants.HEAD).link("refs/heads/basedOnMaster");
    PullResult res = target.pull().call();
    // nothing to update since we don't have different data yet
    assertNull(res.getFetchResult());
    assertTrue(res.getMergeResult().getMergeStatus().equals(MergeStatus.ALREADY_UP_TO_DATE));

    assertFileContentsEqual(targetFile, "Hello world");

    // change the file in master
    target.getRepository().updateRef(Constants.HEAD).link("refs/heads/master");
    writeToFile(targetFile, "Master change");
    target.add().addFilepattern("SomeFile.txt").call();
    target.commit().setMessage("Source change in master").call();

    // change the file in slave
    target.getRepository().updateRef(Constants.HEAD).link("refs/heads/basedOnMaster");
    writeToFile(targetFile, "Slave change");
    target.add().addFilepattern("SomeFile.txt").call();
    target.commit().setMessage("Source change in based on master").call();

    res = target.pull().call();

    String sourceChangeString =
        "Master change\n>>>>>>> branch 'refs/heads/master' of local repository";

    assertNull(res.getFetchResult());
    assertEquals(res.getMergeResult().getMergeStatus(), MergeStatus.CONFLICTING);
    String result = "<<<<<<< HEAD\nSlave change\n=======\n" + sourceChangeString + "\n";
    assertFileContentsEqual(targetFile, result);
    assertEquals(RepositoryState.MERGING, target.getRepository().getRepositoryState());
  }
Exemplo n.º 4
0
  @Test
  public void testPullFastForward() throws Exception {
    PullResult res = target.pull().call();
    // nothing to update since we don't have different data yet
    assertTrue(res.getFetchResult().getTrackingRefUpdates().isEmpty());
    assertTrue(res.getMergeResult().getMergeStatus().equals(MergeStatus.ALREADY_UP_TO_DATE));

    assertFileContentsEqual(targetFile, "Hello world");

    // change the source file
    writeToFile(sourceFile, "Another change");
    source.add().addFilepattern("SomeFile.txt").call();
    source.commit().setMessage("Some change in remote").call();

    res = target.pull().call();

    assertFalse(res.getFetchResult().getTrackingRefUpdates().isEmpty());
    assertEquals(res.getMergeResult().getMergeStatus(), MergeStatus.FAST_FORWARD);
    assertFileContentsEqual(targetFile, "Another change");
    assertEquals(RepositoryState.SAFE, target.getRepository().getRepositoryState());

    res = target.pull().call();
    assertEquals(res.getMergeResult().getMergeStatus(), MergeStatus.ALREADY_UP_TO_DATE);
  }
Exemplo n.º 5
0
  @Override
  protected Control createDialogArea(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().applyTo(main);
    GridDataFactory.fillDefaults().indent(0, 0).grab(true, true).applyTo(main);
    Group fetchResultGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    fetchResultGroup.setText(UIText.PullResultDialog_FetchResultGroupHeader);
    GridLayoutFactory.fillDefaults().applyTo(fetchResultGroup);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(fetchResultGroup);
    FetchResult fRes = result.getFetchResult();
    if (hasFetchResults()) {
      GridLayoutFactory.fillDefaults().applyTo(fetchResultGroup);
      FetchResultDialog dlg =
          new FetchResultDialog(getParentShell(), repo, fRes, result.getFetchedFrom());
      Control fresult = dlg.createFetchResultTable(fetchResultGroup);
      Object layoutData = fresult.getLayoutData();
      if (layoutData instanceof GridData)
        GridDataFactory.createFrom((GridData) layoutData).hint(SWT.DEFAULT, 130).applyTo(fresult);

    } else {
      GridLayoutFactory.swtDefaults().applyTo(fetchResultGroup);
      Label noResult = new Label(fetchResultGroup, SWT.NONE);
      if (result.getFetchedFrom().equals(".")) // $NON-NLS-1$
      noResult.setText(UIText.PullResultDialog_NothingToFetchFromLocal);
      else
        noResult.setText(
            NLS.bind(UIText.FetchResultDialog_labelEmptyResult, result.getFetchedFrom()));
    }
    Group mergeResultGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    mergeResultGroup.setText(UIText.PullResultDialog_MergeResultGroupHeader);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(mergeResultGroup);
    if (hasMergeResults()) {
      GridLayoutFactory.fillDefaults().applyTo(mergeResultGroup);
      MergeResultDialog dlg =
          new MergeResultDialog(getParentShell(), repo, result.getMergeResult());
      dlg.createDialogArea(mergeResultGroup);
    } else if (hasRebaseResults()) {
      Status status = result.getRebaseResult().getStatus();
      GridLayoutFactory.fillDefaults().applyTo(mergeResultGroup);
      switch (status) {
        case OK:
          // fall through
        case FAST_FORWARD:
          // fall through
        case UP_TO_DATE:
          // fall through
        case FAILED:
          // fall through
        case ABORTED:
          break;
        case STOPPED:
          Label errorLabel = new Label(mergeResultGroup, SWT.NONE);
          errorLabel.setImage(
              PlatformUI.getWorkbench()
                  .getSharedImages()
                  .getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
          Text errorText = new Text(mergeResultGroup, SWT.READ_ONLY);
          errorText.setText(UIText.PullResultDialog_RebaseStoppedMessage);
          break;
      }
      Label statusLabel = new Label(mergeResultGroup, SWT.NONE);
      statusLabel.setText(UIText.PullResultDialog_RebaseStatusLabel);
      Text statusText = new Text(mergeResultGroup, SWT.READ_ONLY);
      statusText.setText(status.name());
    } else {
      GridLayoutFactory.swtDefaults().applyTo(mergeResultGroup);
      Label noResult = new Label(mergeResultGroup, SWT.NONE);
      noResult.setText(UIText.PullResultDialog_MergeAlreadyUpToDateMessage);
    }
    return main;
  }
Exemplo n.º 6
0
 private boolean hasFetchResults() {
   final FetchResult fetchResult = result.getFetchResult();
   return fetchResult != null && !fetchResult.getTrackingRefUpdates().isEmpty();
 }