Ejemplo n.º 1
0
  @Test
  public void updateKeepsWorkingAfterPull() throws Exception {

    changeFile_A_AndCommitInRemoteRepository();

    // do a simple pull without an update
    HgPullCommand pull = new HgPullCommand(myProject, projectRepoVirtualFile);
    pull.setSource(new HgShowConfigCommand(myProject).getDefaultPath(projectRepoVirtualFile));
    pull.setUpdate(false);
    pull.execute();

    assertEquals(
        determineNumberOfIncomingChanges(projectRepo),
        0,
        "The update operation should have pulled the incoming changes from the default repository.");

    updateThroughPlugin();

    HgRevisionNumber parentRevision =
        new HgWorkingCopyRevisionsCommand(myProject).firstParent(projectRepoVirtualFile);
    assertEquals(
        parentRevision.getRevision(),
        "1",
        "The working directory should have been updated to the latest version");
  }
  public int compareTo(VcsRevisionNumber o) {
    // boundary cases
    if (this == o) {
      return 0;
    }
    if (!(o instanceof HgRevisionNumber)) {
      return -1;
    }
    final HgRevisionNumber other = (HgRevisionNumber) o;
    if (changeset.equals(other.changeset)) {
      return 0;
    }

    // compare revision numbers.
    final int revCompare =
        java.lang.Long.valueOf(getRevisionNumber())
            .compareTo(java.lang.Long.valueOf(other.getRevisionNumber()));
    if (revCompare != 0) {
      return revCompare;
    }
    // If they are equal, the working revision is greater.
    if (isWorkingVersion) {
      return other.isWorkingVersion ? 0 : 1;
    } else {
      return other.isWorkingVersion ? -1 : 0;
    }
  }
  private void updateToPulledHead(
      VirtualFile repo,
      UpdatedFiles updatedFiles,
      HgRevisionNumber newHead,
      ProgressIndicator indicator) {
    indicator.setText2(HgVcsMessages.message("hg4idea.update.progress.updating.to.pulled.head"));
    HgRevisionNumber parentBeforeUpdate =
        new HgWorkingCopyRevisionsCommand(project).firstParent(repo);
    HgUpdateCommand updateCommand = new HgUpdateCommand(project, repoRoot);
    updateCommand.setRevision(newHead.getChangeset());
    updateCommand.setClean(true);
    updateCommand.execute();

    HgRevisionNumber commonParent = findCommonParent(newHead, parentBeforeUpdate);
    addUpdatedFiles(repo, updatedFiles, commonParent, newHead);
  }
 private void addUpdatedFiles(
     VirtualFile repo,
     UpdatedFiles updatedFiles,
     HgRevisionNumber parentBeforeUpdate,
     HgRevisionNumber parentAfterUpdate) {
   if (parentAfterUpdate == null || parentBeforeUpdate == null) {
     return;
   }
   if (parentAfterUpdate.equals(
       parentBeforeUpdate)) { // nothing to update => returning not to capture local uncommitted
                              // changes
     return;
   }
   HgStatusCommand statusCommand =
       new HgStatusCommand.Builder(true)
           .ignored(false)
           .unknown(false)
           .baseRevision(parentBeforeUpdate)
           .targetRevision(parentAfterUpdate)
           .build(project);
   Set<HgChange> changes = statusCommand.execute(repo);
   for (HgChange change : changes) {
     HgFileStatusEnum status = change.getStatus();
     switch (status) {
       case ADDED:
         addToGroup(updatedFiles, change, FileGroup.CREATED_ID);
         break;
       case MODIFIED:
         addToGroup(updatedFiles, change, FileGroup.UPDATED_ID);
         break;
       case DELETED:
         addToGroup(updatedFiles, change, FileGroup.REMOVED_FROM_REPOSITORY_ID);
         break;
       case COPY:
         addToGroup(updatedFiles, change, FileGroup.CHANGED_ON_SERVER_ID);
         break;
       default:
         // do nothing
         break;
     }
   }
 }
Ejemplo n.º 5
0
  public static List<? extends VcsFullCommitDetails> createFullCommitsFromResult(
      @NotNull Project project,
      @NotNull VirtualFile root,
      @Nullable HgCommandResult result,
      @NotNull HgVersion version,
      boolean silent) {
    final VcsLogObjectsFactory factory = getObjectsFactoryWithDisposeCheck(project);
    if (factory == null) {
      return Collections.emptyList();
    }
    List<HgFileRevision> hgRevisions =
        getCommitRecords(
            project,
            result,
            new HgFileRevisionLogParser(project, getOriginalHgFile(project, root), version),
            silent);
    List<VcsFullCommitDetails> vcsFullCommitDetailsList = new ArrayList<VcsFullCommitDetails>();
    for (HgFileRevision revision : hgRevisions) {

      HgRevisionNumber vcsRevisionNumber = revision.getRevisionNumber();
      List<HgRevisionNumber> parents = vcsRevisionNumber.getParents();
      HgRevisionNumber firstParent =
          parents.isEmpty() ? null : parents.get(0); // can have no parents if it is a root
      List<Hash> parentsHash = new SmartList<Hash>();
      for (HgRevisionNumber parent : parents) {
        parentsHash.add(factory.createHash(parent.getChangeset()));
      }

      final Collection<Change> changes = new ArrayList<Change>();
      for (String file : revision.getModifiedFiles()) {
        changes.add(
            createChange(
                project, root, file, firstParent, file, vcsRevisionNumber, FileStatus.MODIFIED));
      }
      for (String file : revision.getAddedFiles()) {
        changes.add(
            createChange(project, root, null, null, file, vcsRevisionNumber, FileStatus.ADDED));
      }
      for (String file : revision.getDeletedFiles()) {
        changes.add(
            createChange(
                project, root, file, firstParent, null, vcsRevisionNumber, FileStatus.DELETED));
      }
      for (Map.Entry<String, String> copiedFile : revision.getCopiedFiles().entrySet()) {
        changes.add(
            createChange(
                project,
                root,
                copiedFile.getKey(),
                firstParent,
                copiedFile.getValue(),
                vcsRevisionNumber,
                FileStatus.ADDED));
      }

      vcsFullCommitDetailsList.add(
          factory.createFullDetails(
              factory.createHash(vcsRevisionNumber.getChangeset()),
              parentsHash,
              revision.getRevisionDate().getTime(),
              root,
              vcsRevisionNumber.getSubject(),
              vcsRevisionNumber.getAuthor(),
              vcsRevisionNumber.getEmail(),
              vcsRevisionNumber.getCommitMessage(),
              vcsRevisionNumber.getAuthor(),
              vcsRevisionNumber.getEmail(),
              revision.getRevisionDate().getTime(),
              new ThrowableComputable<Collection<Change>, Exception>() {
                @Override
                public Collection<Change> compute() throws Exception {
                  return changes;
                }
              }));
    }
    return vcsFullCommitDetailsList;
  }