Skip to content

Commit

Permalink
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/com/sourcegraph/vcs/RepoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.dvcs.repo.VcsRepositoryManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcsUtil.VcsUtil;
import com.sourcegraph.cody.agent.CodyAgent;
Expand Down Expand Up @@ -223,11 +224,22 @@ public static VCSType getVcsType(@NotNull Project project, @NotNull VirtualFile
}

private static Optional<VirtualFile> getRootFileFromFirstGitRepository(@NotNull Project project) {
// https://intellij-support.jetbrains.com/hc/en-us/community/posts/206105769/comments/206091565
Object lock = new Object();
ProjectLevelVcsManager.getInstance(project)
.runAfterInitialization(
() -> {
synchronized (lock) {
lock.notify();
}
});
synchronized (lock) {
try {
lock.wait();
} catch (InterruptedException ignored) {
}
}
Optional<Repository> firstFoundRepository =
// NOTE(olafurpg): getRepositories() returns an empty stream in most cases. I made multiple
// failed attempts to infer the repository from a project. Ideally, we should just persist
// the codebase per project so that we only have to wait until the user has opened a file
// once for any given project.
VcsRepositoryManager.getInstance(project).getRepositories().stream()
.filter(it -> it.getVcs().getName().equals(GitVcs.NAME))
.findFirst();
Expand Down

0 comments on commit 3d6f314

Please sign in to comment.