Search in sources :

Example 1 with GitCoreException

use of com.virtuslab.gitcore.api.GitCoreException in project git-machete-intellij-plugin by VirtusLab.

the class GitMacheteRepository method discoverLayoutAndCreateSnapshot.

@Override
@UIThreadUnsafe
public IGitMacheteRepositorySnapshot discoverLayoutAndCreateSnapshot() throws GitMacheteException {
    LOG.startTimer().debug("Entering");
    try {
        val aux = new DiscoverGitMacheteRepositoryAux(gitCoreRepository, statusHookExecutor, preRebaseHookExecutor);
        val result = aux.discoverLayoutAndCreateSnapshot(NUMBER_OF_MOST_RECENTLY_CHECKED_OUT_BRANCHES_FOR_DISCOVER);
        LOG.withTimeElapsed().info("Finished");
        return result;
    } catch (GitCoreException e) {
        throw new GitMacheteException(e);
    }
}
Also used : lombok.val(lombok.val) GitMacheteException(com.virtuslab.gitmachete.backend.api.GitMacheteException) GitCoreException(com.virtuslab.gitcore.api.GitCoreException) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Example 2 with GitCoreException

use of com.virtuslab.gitcore.api.GitCoreException in project git-machete-intellij-plugin by VirtusLab.

the class GitMacheteRepository method inferParentForLocalBranch.

@Override
@UIThreadUnsafe
public Option<ILocalBranchReference> inferParentForLocalBranch(Set<String> eligibleLocalBranchNames, String localBranchName) throws GitMacheteException {
    LOG.startTimer().debug(() -> "Entering: localBranchName = ${localBranchName}");
    try {
        val aux = new Aux(gitCoreRepository);
        val result = aux.inferParentForLocalBranch(eligibleLocalBranchNames, localBranchName);
        LOG.withTimeElapsed().info("Finished");
        return result;
    } catch (GitCoreException e) {
        throw new GitMacheteException(e);
    }
}
Also used : lombok.val(lombok.val) GitMacheteException(com.virtuslab.gitmachete.backend.api.GitMacheteException) GitCoreException(com.virtuslab.gitcore.api.GitCoreException) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Example 3 with GitCoreException

use of com.virtuslab.gitcore.api.GitCoreException in project git-machete-intellij-plugin by VirtusLab.

the class GitMacheteRepository method createSnapshotForLayout.

@Override
@UIThreadUnsafe
public IGitMacheteRepositorySnapshot createSnapshotForLayout(IBranchLayout branchLayout) throws GitMacheteException {
    LOG.startTimer().debug("Entering");
    try {
        val aux = new CreateGitMacheteRepositoryAux(gitCoreRepository, statusHookExecutor, preRebaseHookExecutor);
        val result = aux.createSnapshot(branchLayout);
        LOG.withTimeElapsed().info("Finished");
        return result;
    } catch (GitCoreException e) {
        throw new GitMacheteException(e);
    }
}
Also used : lombok.val(lombok.val) GitMacheteException(com.virtuslab.gitmachete.backend.api.GitMacheteException) GitCoreException(com.virtuslab.gitcore.api.GitCoreException) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Example 4 with GitCoreException

use of com.virtuslab.gitcore.api.GitCoreException in project git-machete-intellij-plugin by VirtusLab.

the class GitCoreRepository method deriveHead.

@Override
public IGitCoreHeadSnapshot deriveHead() throws GitCoreException {
    Ref ref = Try.of(() -> jgitRepo.getRefDatabase().findRef(Constants.HEAD)).getOrElseThrow(e -> new GitCoreException("Cannot get current branch", e));
    if (ref == null) {
        throw new GitCoreException("Error occurred while getting current branch ref");
    }
    val reflog = deriveReflogByRefFullName(Constants.HEAD);
    String currentBranchName = null;
    if (ref.isSymbolic()) {
        currentBranchName = Repository.shortenRefName(ref.getTarget().getName());
    } else {
        Option<Path> headNamePath = Stream.of("rebase-apply", "rebase-merge").map(dir -> jgitRepo.getDirectory().toPath().resolve(dir).resolve("head-name")).find(path -> path.toFile().isFile());
        if (headNamePath.isDefined()) {
            currentBranchName = Try.of(() -> Stream.ofAll(Files.readAllLines(headNamePath.get()))).getOrElseThrow(e -> new GitCoreException("Error occurred while getting current branch ref", e)).headOption().map(Repository::shortenRefName).getOrNull();
        }
    }
    IGitCoreLocalBranchSnapshot targetBranch;
    if (currentBranchName != null) {
        targetBranch = deriveLocalBranchByName(currentBranchName).getOrNull();
    } else {
        targetBranch = null;
    }
    return new GitCoreHeadSnapshot(targetBranch, reflog);
}
Also used : lombok.val(lombok.val) Path(java.nio.file.Path) Match(io.vavr.API.Match) RevCommit(org.eclipse.jgit.revwalk.RevCommit) SneakyThrows(lombok.SneakyThrows) ReflogReader(org.eclipse.jgit.lib.ReflogReader) GitCoreRepositoryState(com.virtuslab.gitcore.api.GitCoreRepositoryState) IGitCoreHeadSnapshot(com.virtuslab.gitcore.api.IGitCoreHeadSnapshot) CheckedFunction1(io.vavr.CheckedFunction1) RepositoryState(org.eclipse.jgit.lib.RepositoryState) List(io.vavr.collection.List) IGitCoreLocalBranchSnapshot(com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot) Predicates.isIn(io.vavr.Predicates.isIn) RevWalk(org.eclipse.jgit.revwalk.RevWalk) CONFIG_KEY_MERGE(org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_MERGE) Option(io.vavr.control.Option) IGitCoreRepository(com.virtuslab.gitcore.api.IGitCoreRepository) ToString(lombok.ToString) Iterator(io.vavr.collection.Iterator) Stream(io.vavr.collection.Stream) Path(java.nio.file.Path) GitCoreNoSuchRevisionException(com.virtuslab.gitcore.api.GitCoreNoSuchRevisionException) API.$(io.vavr.API.$) BranchFullNameUtils.getLocalBranchFullName(com.virtuslab.gitcore.impl.jgit.BranchFullNameUtils.getLocalBranchFullName) Tuple(io.vavr.Tuple) RevFilter(org.eclipse.jgit.revwalk.filter.RevFilter) Files(java.nio.file.Files) CONFIG_BRANCH_SECTION(org.eclipse.jgit.lib.ConfigConstants.CONFIG_BRANCH_SECTION) CONFIG_KEY_REMOTE(org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_REMOTE) GitCoreCannotAccessGitDirectoryException(com.virtuslab.gitcore.api.GitCoreCannotAccessGitDirectoryException) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) lombok.val(lombok.val) BranchFullNameUtils.getRemoteBranchFullName(com.virtuslab.gitcore.impl.jgit.BranchFullNameUtils.getRemoteBranchFullName) RevSort(org.eclipse.jgit.revwalk.RevSort) Case(io.vavr.API.Case) IOException(java.io.IOException) CustomLog(lombok.CustomLog) Constants(org.eclipse.jgit.lib.Constants) IGitCoreCommit(com.virtuslab.gitcore.api.IGitCoreCommit) GitCoreRelativeCommitCount(com.virtuslab.gitcore.api.GitCoreRelativeCommitCount) RevWalkUtils(org.eclipse.jgit.revwalk.RevWalkUtils) ObjectId(org.eclipse.jgit.lib.ObjectId) Try(io.vavr.control.Try) Tuple2(io.vavr.Tuple2) Ref(org.eclipse.jgit.lib.Ref) Unique(org.checkerframework.common.aliasing.qual.Unique) Repository(org.eclipse.jgit.lib.Repository) GitCoreException(com.virtuslab.gitcore.api.GitCoreException) IGitCoreReflogEntry(com.virtuslab.gitcore.api.IGitCoreReflogEntry) Ref(org.eclipse.jgit.lib.Ref) IGitCoreRepository(com.virtuslab.gitcore.api.IGitCoreRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) GitCoreException(com.virtuslab.gitcore.api.GitCoreException) ToString(lombok.ToString) IGitCoreLocalBranchSnapshot(com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot) IGitCoreHeadSnapshot(com.virtuslab.gitcore.api.IGitCoreHeadSnapshot)

Example 5 with GitCoreException

use of com.virtuslab.gitcore.api.GitCoreException in project git-machete-intellij-plugin by VirtusLab.

the class GitCoreRepository method ancestorsOf.

@Override
public Stream<IGitCoreCommit> ancestorsOf(IGitCoreCommit commitInclusive) throws GitCoreException {
    RevWalk walk = new RevWalk(jgitRepo);
    walk.sort(RevSort.TOPO);
    ObjectId objectId = convertGitCoreCommitToObjectId(commitInclusive);
    Try.run(() -> walk.markStart(walk.parseCommit(objectId))).getOrElseThrow(e -> new GitCoreException(e));
    return Stream.ofAll(walk).map(GitCoreCommit::new);
}
Also used : IGitCoreCommit(com.virtuslab.gitcore.api.IGitCoreCommit) ObjectId(org.eclipse.jgit.lib.ObjectId) GitCoreException(com.virtuslab.gitcore.api.GitCoreException) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Aggregations

GitCoreException (com.virtuslab.gitcore.api.GitCoreException)6 lombok.val (lombok.val)5 IGitCoreCommit (com.virtuslab.gitcore.api.IGitCoreCommit)3 GitMacheteException (com.virtuslab.gitmachete.backend.api.GitMacheteException)3 UIThreadUnsafe (com.virtuslab.qual.guieffect.UIThreadUnsafe)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 GitCoreCannotAccessGitDirectoryException (com.virtuslab.gitcore.api.GitCoreCannotAccessGitDirectoryException)2 GitCoreNoSuchRevisionException (com.virtuslab.gitcore.api.GitCoreNoSuchRevisionException)2 GitCoreRelativeCommitCount (com.virtuslab.gitcore.api.GitCoreRelativeCommitCount)2 GitCoreRepositoryState (com.virtuslab.gitcore.api.GitCoreRepositoryState)2 IGitCoreHeadSnapshot (com.virtuslab.gitcore.api.IGitCoreHeadSnapshot)2 IGitCoreLocalBranchSnapshot (com.virtuslab.gitcore.api.IGitCoreLocalBranchSnapshot)2 IGitCoreReflogEntry (com.virtuslab.gitcore.api.IGitCoreReflogEntry)2 IGitCoreRepository (com.virtuslab.gitcore.api.IGitCoreRepository)2 BranchFullNameUtils.getLocalBranchFullName (com.virtuslab.gitcore.impl.jgit.BranchFullNameUtils.getLocalBranchFullName)2 BranchFullNameUtils.getRemoteBranchFullName (com.virtuslab.gitcore.impl.jgit.BranchFullNameUtils.getRemoteBranchFullName)2 API.$ (io.vavr.API.$)2 Case (io.vavr.API.Case)2 Match (io.vavr.API.Match)2