Search in sources :

Example 1 with RepoStateException

use of com.intellij.dvcs.repo.RepoStateException in project intellij-community by JetBrains.

the class GitRepositoryReader method readHead.

@NotNull
private HeadInfo readHead() {
    String headContent;
    try {
        headContent = DvcsUtil.tryLoadFile(myHeadFile, CharsetToolkit.UTF8);
    } catch (RepoStateException e) {
        LOG.error(e);
        return new HeadInfo(false, null);
    }
    Hash hash = parseHash(headContent);
    if (hash != null) {
        return new HeadInfo(false, headContent);
    }
    String target = getTarget(headContent);
    if (target != null) {
        return new HeadInfo(true, target);
    }
    // including "refs/tags/v1"
    LOG.error(new RepoStateException("Invalid format of the .git/HEAD file: [" + headContent + "]"));
    return new HeadInfo(false, null);
}
Also used : RepoStateException(com.intellij.dvcs.repo.RepoStateException) Hash(com.intellij.vcs.log.Hash) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with RepoStateException

use of com.intellij.dvcs.repo.RepoStateException in project intellij-community by JetBrains.

the class HgRepositoryReader method readCurrentTipRevision.

/**
   * Finds tip revision value.
   *
   * @return The tip revision hash, or <b>{@code null}</b> if tip revision is unknown - it is the initial repository state.
   */
@Nullable
public String readCurrentTipRevision() {
    if (!isBranchInfoAvailable())
        return null;
    String[] branchesWithHeads;
    try {
        branchesWithHeads = DvcsUtil.tryLoadFile(myBranchHeadsFile).split("\n");
    } catch (RepoStateException e) {
        LOG.error(e);
        return null;
    }
    String head = branchesWithHeads[0];
    Matcher matcher = HASH_NAME.matcher(head);
    if (matcher.matches()) {
        return (matcher.group(1));
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) RepoStateException(com.intellij.dvcs.repo.RepoStateException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

RepoStateException (com.intellij.dvcs.repo.RepoStateException)2 Hash (com.intellij.vcs.log.Hash)1 Matcher (java.util.regex.Matcher)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1