mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-157915 resolve Git symbolic-ref in HEAD
This commit is contained in:
committed by
Kirill Likhodedov
parent
f493d9e03b
commit
f57c1c02ef
@@ -316,4 +316,9 @@ public class GitRepositoryFiles {
|
||||
Collection<VirtualFile> getRootDirs() {
|
||||
return ContainerUtil.newHashSet(myMainDir, myWorktreeDir);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
File getBranchFile(@NotNull String fullBranchName) {
|
||||
return file(myMainDir.getPath() + slash(fullBranchName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.LineTokenizer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.Processor;
|
||||
@@ -320,9 +321,14 @@ class GitRepositoryReader {
|
||||
|
||||
@NotNull
|
||||
private HeadInfo readHead() {
|
||||
return readHeadInternal(myHeadFile, new ArrayList<>());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private HeadInfo readHeadInternal(@NotNull File headFile, @NotNull List<String> alreadyVisited) {
|
||||
String headContent;
|
||||
try {
|
||||
headContent = DvcsUtil.tryLoadFile(myHeadFile, CharsetToolkit.UTF8);
|
||||
headContent = DvcsUtil.tryLoadFile(headFile, CharsetToolkit.UTF8);
|
||||
}
|
||||
catch (RepoStateException e) {
|
||||
LOG.error(e);
|
||||
@@ -331,11 +337,22 @@ class GitRepositoryReader {
|
||||
|
||||
Hash hash = parseHash(headContent);
|
||||
if (hash != null) {
|
||||
return new HeadInfo(false, headContent);
|
||||
if (alreadyVisited.isEmpty()) {
|
||||
return new HeadInfo(false, headContent);
|
||||
} else {
|
||||
return new HeadInfo(true, ContainerUtil.getLastItem(alreadyVisited));
|
||||
}
|
||||
}
|
||||
String target = getTarget(headContent);
|
||||
if (target != null) {
|
||||
return new HeadInfo(true, target);
|
||||
if (alreadyVisited.contains(target)) {
|
||||
alreadyVisited.add(target);
|
||||
LOG.error(new RepoStateException("Cyclic symbolic ref in HEAD: [" + StringUtil.join(alreadyVisited, " -> ") + "]"));
|
||||
return new HeadInfo(false, null);
|
||||
} else {
|
||||
alreadyVisited.add(target);
|
||||
return readHeadInternal(myGitFiles.getBranchFile(target), alreadyVisited);
|
||||
}
|
||||
}
|
||||
LOG.error(new RepoStateException("Invalid format of the .git/HEAD file: [" + headContent + "]")); // including "refs/tags/v1"
|
||||
return new HeadInfo(false, null);
|
||||
|
||||
@@ -1 +1 @@
|
||||
0e1d130689bc52f140c5c374aa9cc2b8916c0ad7 master-link
|
||||
0e1d130689bc52f140c5c374aa9cc2b8916c0ad7 master
|
||||
|
||||
Reference in New Issue
Block a user