@Test
  public void testGetCloneAndPull() throws Exception {
    // see bug 339254
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = getWorkspaceId(workspaceLocation);

    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath =
        new Path("file").append(project.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION);

    // get clones for workspace
    WebRequest request = listGitClonesRequest(workspaceId, null);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject clones = new JSONObject(response.getText());
    JSONArray clonesArray = clones.getJSONArray(ProtocolConstants.KEY_CHILDREN);
    assertEquals(1, clonesArray.length());

    Git git = new Git(getRepositoryForContentLocation(contentLocation));
    // TODO: replace with RESTful API when ready, see bug 339114
    PullResult pullResult = git.pull().call();
    assertEquals(pullResult.getMergeResult().getMergeStatus(), MergeStatus.ALREADY_UP_TO_DATE);
    assertEquals(RepositoryState.SAFE, git.getRepository().getRepositoryState());
  }
Beispiel #2
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());
  }
  /*
   * 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;
  }
Beispiel #4
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());
  }
Beispiel #5
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);
  }
Beispiel #6
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;
  }
Beispiel #7
0
 private boolean hasRebaseResults() {
   final RebaseResult rebaseResult = result.getRebaseResult();
   return rebaseResult != null && rebaseResult.getStatus() != Status.UP_TO_DATE;
 }
Beispiel #8
0
 private boolean hasMergeResults() {
   final MergeResult mergeResult = result.getMergeResult();
   return mergeResult != null && mergeResult.getMergeStatus() != MergeStatus.ALREADY_UP_TO_DATE;
 }
Beispiel #9
0
 private boolean hasFetchResults() {
   final FetchResult fetchResult = result.getFetchResult();
   return fetchResult != null && !fetchResult.getTrackingRefUpdates().isEmpty();
 }