[git] IDEA-130702 Don't spam "No remote found with name" & simplify

This commit is contained in:
Kirill Likhodedov
2014-11-06 18:20:14 +03:00
parent 30f65070cb
commit b2e4365834
3 changed files with 35 additions and 48 deletions
+7 -2
View File
@@ -687,8 +687,13 @@ public class GitUtil {
@Nullable
public static GitRemote findRemoteByName(@NotNull GitRepository repository, @Nullable final String name) {
return ContainerUtil.find(repository.getRemotes(), new Condition<GitRemote>() {
public static GitRemote findRemoteByName(@NotNull GitRepository repository, @NotNull final String name) {
return findRemoteByName(repository.getRemotes(), name);
}
@Nullable
public static GitRemote findRemoteByName(Collection<GitRemote> remotes, @NotNull final String name) {
return ContainerUtil.find(remotes, new Condition<GitRemote>() {
@Override
public boolean value(GitRemote remote) {
return remote.getName().equals(name);
@@ -30,7 +30,6 @@ import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.vcs.log.Hash;
import com.intellij.vcsUtil.VcsUtil;
import git4idea.*;
import git4idea.commands.GitCommand;
@@ -209,46 +208,6 @@ public class GitBranchUtil {
return remote;
}
/**
*
* @return {@link git4idea.GitStandardRemoteBranch} or {@link GitSvnRemoteBranch}, or null in case of an error. The error is logged in this method.
* @deprecated Should be used only in the GitRepositoryReader, i. e. moved there once all other usages are removed.
*/
@Deprecated
@Nullable
public static GitRemoteBranch parseRemoteBranch(@NotNull String fullBranchName, @NotNull Hash hash,
@NotNull Collection<GitRemote> remotes) {
String stdName = stripRefsPrefix(fullBranchName);
int slash = stdName.indexOf('/');
if (slash == -1) { // .git/refs/remotes/my_branch => git-svn
return new GitSvnRemoteBranch(fullBranchName, hash);
}
else {
String remoteName = stdName.substring(0, slash);
String branchName = stdName.substring(slash + 1);
GitRemote remote = findRemoteByName(remoteName, remotes);
if (remote == null) {
// user may remove the remote section from .git/config, but leave remote refs untouched in .git/refs/remotes
LOG.info(String.format("No remote found with the name [%s]. All remotes: %s", remoteName, remotes));
GitRemote fakeRemote = new GitRemote(remoteName, ContainerUtil.<String>emptyList(), Collections.<String>emptyList(),
Collections.<String>emptyList(), Collections.<String>emptyList());
return new GitStandardRemoteBranch(fakeRemote, branchName, hash);
}
return new GitStandardRemoteBranch(remote, branchName, hash);
}
}
@Nullable
private static GitRemote findRemoteByName(@NotNull String remoteName, @NotNull Collection<GitRemote> remotes) {
for (GitRemote remote : remotes) {
if (remote.getName().equals(remoteName)) {
return remote;
}
}
return null;
}
/**
* Convert {@link git4idea.GitRemoteBranch GitRemoteBranches} to their names, and remove remote HEAD pointers: origin/HEAD.
*/
@@ -25,9 +25,7 @@ import com.intellij.util.Processor;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.vcs.log.Hash;
import com.intellij.vcs.log.impl.HashImpl;
import git4idea.GitBranch;
import git4idea.GitLocalBranch;
import git4idea.GitRemoteBranch;
import git4idea.*;
import git4idea.branch.GitBranchUtil;
import git4idea.branch.GitBranchesCollection;
import org.jetbrains.annotations.NonNls;
@@ -349,7 +347,7 @@ class GitRepositoryReader {
String hash = loadHashFromBranchFile(file);
Hash h = createHash(hash);
if (h != null) {
GitRemoteBranch remoteBranch = GitBranchUtil.parseRemoteBranch(branchName, h, remotes);
GitRemoteBranch remoteBranch = parseRemoteBranch(branchName, h, remotes);
if (remoteBranch != null) {
branches.add(remoteBranch);
}
@@ -386,7 +384,7 @@ class GitRepositoryReader {
localBranches.add(new GitLocalBranch(branchName, hash));
}
else if (branchName.startsWith(REFS_REMOTES_PREFIX)) {
GitRemoteBranch remoteBranch = GitBranchUtil.parseRemoteBranch(branchName, hash, remotes);
GitRemoteBranch remoteBranch = parseRemoteBranch(branchName, hash, remotes);
if (remoteBranch != null) {
remoteBranches.add(remoteBranch);
}
@@ -395,6 +393,31 @@ class GitRepositoryReader {
return new GitBranchesCollection(localBranches, remoteBranches);
}
@Nullable
private static GitRemoteBranch parseRemoteBranch(@NotNull String fullBranchName,
@NotNull Hash hash,
@NotNull Collection<GitRemote> remotes) {
String stdName = GitBranchUtil.stripRefsPrefix(fullBranchName);
int slash = stdName.indexOf('/');
if (slash == -1) { // .git/refs/remotes/my_branch => git-svn
return new GitSvnRemoteBranch(fullBranchName, hash);
}
else {
String remoteName = stdName.substring(0, slash);
String branchName = stdName.substring(slash + 1);
GitRemote remote = GitUtil.findRemoteByName(remotes, remoteName);
if (remote == null) {
// user may remove the remote section from .git/config, but leave remote refs untouched in .git/refs/remotes
LOG.debug(String.format("No remote found with the name [%s]. All remotes: %s", remoteName, remotes));
GitRemote fakeRemote = new GitRemote(remoteName, ContainerUtil.<String>emptyList(), Collections.<String>emptyList(),
Collections.<String>emptyList(), Collections.<String>emptyList());
return new GitStandardRemoteBranch(fakeRemote, branchName, hash);
}
return new GitStandardRemoteBranch(remote, branchName, hash);
}
}
@NotNull
private static String readBranchFile(@NotNull File branchFile) {
return RepositoryUtil.tryLoadFile(branchFile);