GitRemoteBranch (@NotNull String fullBranchName, @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); } else { GitRemote remote; String remoteName; String branchName; do { remoteName = stdName.substring(0, slash); branchName = stdName.substring(slash + 1); remote = GitUtil.findRemoteByName(remotes, remoteName); slash = stdName.indexOf('/', slash + 1); } while (remote == null && slash >= 0); if (remote == null) { // user may remove the remote section from .git/config, but leave remote refs untouched in .git/refs/remotes LOG.trace(String.format("No remote found with the name [%s]. All remotes: %s", remoteName, remotes)); GitRemote fakeRemote = new GitRemote(remoteName, emptyList(), emptyList(), emptyList(), emptyList()); return new GitStandardRemoteBranch(fakeRemote, branchName); } return new GitStandardRemoteBranch(remote, branchName); } }