Search in sources :

Example 6 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgRealRepositoryReaderTest method testOpenedBranches.

public void testOpenedBranches() {
    cd(myRepository);
    myRepository.refresh(false, true);
    HgRepository hgRepository = HgRepositoryImpl.getInstance(myRepository, myProject, myProject);
    hg("up branchA");
    hg("commit -m 'close branch' --close-branch");
    hgRepository.update();
    VcsTestUtil.assertEqualCollections(hgRepository.getOpenedBranches(), Arrays.asList("default", "branchB"));
}
Also used : HgRepository(org.zmlx.hg4idea.repo.HgRepository)

Example 7 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgReferenceValidatorTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    HgRepository hgRepository = HgRepositoryImpl.getInstance(myRepository, myProject, myProject);
    assertNotNull(hgRepository);
    myValidator = new HgBranchReferenceValidator(hgRepository);
    cd(myRepository);
    hg("branch '" + BRANCH_NAME + "'");
    String firstFile = "file.txt";
    echo(firstFile, BRANCH_NAME);
    hg("commit -m 'createdBranch " + BRANCH_NAME + "' ");
    hg("branch '" + UNCOMMITTED_BRANCH + "'");
    hgRepository.update();
}
Also used : HgBranchReferenceValidator(org.zmlx.hg4idea.util.HgBranchReferenceValidator) HgRepository(org.zmlx.hg4idea.repo.HgRepository) Before(org.junit.Before)

Example 8 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgTaskHandler method mergeAndClose.

@Override
protected void mergeAndClose(@NotNull final String branch, @NotNull final List<HgRepository> repositories) {
    String bookmarkRevisionArg = "bookmark(\"" + branch + "\")";
    FileDocumentManager.getInstance().saveAllDocuments();
    final UpdatedFiles updatedFiles = UpdatedFiles.create();
    for (final HgRepository repository : repositories) {
        HgMergeCommand.mergeWith(repository, bookmarkRevisionArg, updatedFiles, new Runnable() {

            @Override
            public void run() {
                Project project = repository.getProject();
                VirtualFile repositoryRoot = repository.getRoot();
                try {
                    new HgCommitCommand(project, repository, "Automated merge with " + branch).executeInCurrentThread();
                    HgBookmarkCommand.deleteBookmarkSynchronously(project, repositoryRoot, branch);
                } catch (HgCommandException e) {
                    HgErrorUtil.handleException(project, e);
                } catch (VcsException e) {
                    VcsNotifier.getInstance(project).notifyError("Exception during merge commit with " + branch, e.getMessage());
                }
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) HgCommitCommand(org.zmlx.hg4idea.command.HgCommitCommand) VcsException(com.intellij.openapi.vcs.VcsException) UpdatedFiles(com.intellij.openapi.vcs.update.UpdatedFiles) HgRepository(org.zmlx.hg4idea.repo.HgRepository) HgCommandException(org.zmlx.hg4idea.execution.HgCommandException)

Example 9 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgAbstractGlobalAction method actionPerformed.

public void actionPerformed(@NotNull AnActionEvent event) {
    final DataContext dataContext = event.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return;
    }
    VirtualFile[] files = event.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    final HgRepositoryManager repositoryManager = HgUtil.getRepositoryManager(project);
    List<HgRepository> repositories = repositoryManager.getRepositories();
    if (!repositories.isEmpty()) {
        List<HgRepository> selectedRepositories = files != null ? HgActionUtil.collectRepositoriesFromFiles(repositoryManager, Arrays.asList(files)) : ContainerUtil.<HgRepository>emptyList();
        execute(project, repositories, selectedRepositories.isEmpty() ? Collections.singletonList(HgUtil.getCurrentRepository(project)) : selectedRepositories);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) HgRepositoryManager(org.zmlx.hg4idea.repo.HgRepositoryManager) HgRepository(org.zmlx.hg4idea.repo.HgRepository)

Example 10 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgCompareWithBranchAction method getDiffChanges.

@Override
@NotNull
protected Collection<Change> getDiffChanges(@NotNull Project project, @NotNull VirtualFile file, @NotNull String branchToCompare) throws VcsException {
    HgRepository repository = getRepositoryManager(project).getRepositoryForFile(file);
    if (repository == null) {
        throw new VcsException("Couldn't find repository for " + file.getName());
    }
    final FilePath filePath = VcsUtil.getFilePath(file);
    final VirtualFile repositoryRoot = repository.getRoot();
    final HgFile hgFile = new HgFile(repositoryRoot, filePath);
    Hash refHashToCompare = detectActiveHashByName(repository, branchToCompare);
    if (refHashToCompare == null) {
        throw new VcsException(String.format("Couldn't detect commit related to %s name for %s.", branchToCompare, file));
    }
    final HgRevisionNumber compareWithRevisionNumber = HgRevisionNumber.getInstance(branchToCompare, refHashToCompare.toString());
    List<Change> changes = HgUtil.getDiff(project, repositoryRoot, filePath, compareWithRevisionNumber, null);
    if (changes.isEmpty() && !existInBranch(repository, filePath, compareWithRevisionNumber)) {
        throw new VcsException(fileDoesntExistInBranchError(file, branchToCompare));
    }
    return changes.isEmpty() && !filePath.isDirectory() ? createChangesWithCurrentContentForFile(filePath, HgContentRevision.create(project, hgFile, compareWithRevisionNumber)) : changes;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) VcsException(com.intellij.openapi.vcs.VcsException) HgRepository(org.zmlx.hg4idea.repo.HgRepository) Change(com.intellij.openapi.vcs.changes.Change) Hash(com.intellij.vcs.log.Hash) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HgRepository (org.zmlx.hg4idea.repo.HgRepository)36 NotNull (org.jetbrains.annotations.NotNull)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 Project (com.intellij.openapi.project.Project)7 VcsException (com.intellij.openapi.vcs.VcsException)5 FilePath (com.intellij.openapi.vcs.FilePath)4 HgCommitCommand (org.zmlx.hg4idea.command.HgCommitCommand)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 File (java.io.File)3 HgFile (org.zmlx.hg4idea.HgFile)3 HgCommandException (org.zmlx.hg4idea.execution.HgCommandException)3 Task (com.intellij.openapi.progress.Task)2 AbstractVcsVirtualFile (com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile)2 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Nullable (org.jetbrains.annotations.Nullable)2 HgFileRevision (org.zmlx.hg4idea.HgFileRevision)2 HgNameWithHashInfo (org.zmlx.hg4idea.HgNameWithHashInfo)2 HgLogCommand (org.zmlx.hg4idea.command.HgLogCommand)2