mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-143404 .git/config is shared among workspaces
This commit is contained in:
@@ -75,9 +75,13 @@ public class GitRepositoryFiles {
|
||||
private final String myInfoDirPath;
|
||||
private final String myExcludePath;
|
||||
|
||||
private GitRepositoryFiles(@NotNull VirtualFile gitDir, @NotNull File headFile, @NotNull File refsDir, @NotNull File packedRefsFile) {
|
||||
private GitRepositoryFiles(@NotNull VirtualFile gitDir,
|
||||
@NotNull File configFile,
|
||||
@NotNull File headFile,
|
||||
@NotNull File refsDir,
|
||||
@NotNull File packedRefsFile) {
|
||||
myGitDirPath = GitFileUtils.stripFileProtocolPrefix(gitDir.getPath());
|
||||
myConfigFilePath = myGitDirPath + slash(CONFIG);
|
||||
myConfigFilePath = FileUtil.toSystemIndependentName(configFile.getPath());
|
||||
myHeadFilePath = FileUtil.toSystemIndependentName(headFile.getPath());
|
||||
myIndexFilePath = myGitDirPath + slash(INDEX);
|
||||
myMergeHeadPath = myGitDirPath + slash(MERGE_HEAD);
|
||||
@@ -100,15 +104,18 @@ public class GitRepositoryFiles {
|
||||
File headFile = new File(gitDir.getPath(), HEAD);
|
||||
File refsDir;
|
||||
File packedRefsFile;
|
||||
File configFile;
|
||||
if (gitDirForWorktree == null) {
|
||||
refsDir = new File(gitDir.getPath(), REFS);
|
||||
packedRefsFile = new File(gitDir.getPath(), PACKED_REFS);
|
||||
configFile = new File(gitDir.getPath(), CONFIG);
|
||||
}
|
||||
else {
|
||||
refsDir = new File(gitDirForWorktree.getPath(), REFS);
|
||||
packedRefsFile = new File(gitDirForWorktree.getPath(), PACKED_REFS);
|
||||
configFile = new File(gitDirForWorktree.getPath(), CONFIG);
|
||||
}
|
||||
return new GitRepositoryFiles(gitDir, headFile, refsDir, packedRefsFile);
|
||||
return new GitRepositoryFiles(gitDir, configFile, headFile, refsDir, packedRefsFile);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,6 +180,11 @@ public class GitRepositoryFiles {
|
||||
return myHeadFilePath;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getConfigPath() {
|
||||
return myConfigFilePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code .git/config}
|
||||
*/
|
||||
|
||||
@@ -21,8 +21,8 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import git4idea.GitLocalBranch;
|
||||
import git4idea.GitPlatformFacade;
|
||||
@@ -43,6 +43,8 @@ public class GitRepositoryImpl extends RepositoryImpl implements GitRepository {
|
||||
@NotNull private final GitVcs myVcs;
|
||||
@NotNull private final GitRepositoryReader myReader;
|
||||
@NotNull private final VirtualFile myGitDir;
|
||||
@NotNull private final GitRepositoryFiles myRepositoryFiles;
|
||||
|
||||
@Nullable private final GitUntrackedFilesHolder myUntrackedFilesHolder;
|
||||
|
||||
@NotNull private volatile GitRepoInfo myInfo;
|
||||
@@ -57,7 +59,8 @@ public class GitRepositoryImpl extends RepositoryImpl implements GitRepository {
|
||||
myPlatformFacade = facade;
|
||||
myVcs = assertNotNull(GitVcs.getInstance(project));
|
||||
myGitDir = gitDir;
|
||||
myReader = new GitRepositoryReader(myGitDir);
|
||||
myRepositoryFiles = GitRepositoryFiles.getInstance(gitDir);
|
||||
myReader = new GitRepositoryReader(myRepositoryFiles);
|
||||
myInfo = readRepoInfo();
|
||||
if (!light) {
|
||||
myUntrackedFilesHolder = new GitUntrackedFilesHolder(this);
|
||||
@@ -194,7 +197,7 @@ public class GitRepositoryImpl extends RepositoryImpl implements GitRepository {
|
||||
|
||||
@NotNull
|
||||
private GitRepoInfo readRepoInfo() {
|
||||
File configFile = new File(VfsUtilCore.virtualToIoFile(getGitDir()), "config");
|
||||
File configFile = new File(FileUtil.toSystemDependentName(myRepositoryFiles.getConfigPath()));
|
||||
GitConfig config = GitConfig.read(myPlatformFacade, configFile);
|
||||
Collection<GitRemote> remotes = config.parseRemotes();
|
||||
GitBranchState state = myReader.readState(remotes);
|
||||
|
||||
@@ -23,7 +23,6 @@ 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.vfs.VirtualFile;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -68,8 +67,7 @@ class GitRepositoryReader {
|
||||
@NotNull private final File myRefsRemotesDir; // .git/refs/remotes/
|
||||
@NotNull private final File myPackedRefsFile; // .git/packed-refs
|
||||
|
||||
GitRepositoryReader(@NotNull VirtualFile gitDir) {
|
||||
GitRepositoryFiles gitFiles = GitRepositoryFiles.getInstance(gitDir);
|
||||
GitRepositoryReader(@NotNull GitRepositoryFiles gitFiles) {
|
||||
myGitDir = new File(FileUtil.toSystemDependentName(gitFiles.getGitDirPath()));
|
||||
DvcsUtil.assertFileExists(myGitDir, ".git directory not found in " + myGitDir);
|
||||
myHeadFile = new File(FileUtil.toSystemDependentName(gitFiles.getHeadPath()));
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.VcsTestUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import git4idea.GitLocalBranch;
|
||||
import git4idea.GitRemoteBranch;
|
||||
@@ -64,7 +65,9 @@ public class GitConfigTest extends GitPlatformTest {
|
||||
|
||||
File gitDir = new File(myProjectPath, ".git");
|
||||
GitConfig config = GitConfig.read(myPlatformFacade, new File(gitDir, "config"));
|
||||
GitBranchState state = new GitRepositoryReader(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(gitDir)).readState(config.parseRemotes());
|
||||
VirtualFile dir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(gitDir);
|
||||
GitRepositoryReader reader = new GitRepositoryReader(GitRepositoryFiles.getInstance(dir));
|
||||
GitBranchState state = reader.readState(config.parseRemotes());
|
||||
Collection<GitBranchTrackInfo> trackInfos = config.parseTrackInfos(state.getLocalBranches().keySet(), state.getRemoteBranches().keySet());
|
||||
assertTrue("Couldn't find correct a#branch tracking information among: [" + trackInfos + "]",
|
||||
ContainerUtil.exists(trackInfos, new Condition<GitBranchTrackInfo>() {
|
||||
|
||||
@@ -118,7 +118,7 @@ public class GitRepositoryReaderNewTest extends GitSingleRepoTest {
|
||||
private GitBranchState readState() {
|
||||
VirtualFile gitDir = myRepo.getGitDir();
|
||||
GitConfig config = GitConfig.read(myPlatformFacade, new File(gitDir.getPath(), "config"));
|
||||
GitRepositoryReader reader = new GitRepositoryReader(gitDir);
|
||||
GitRepositoryReader reader = new GitRepositoryReader(GitRepositoryFiles.getInstance(gitDir));
|
||||
Collection<GitRemote> remotes = config.parseRemotes();
|
||||
return reader.readState(remotes);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.VcsTestUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.EdtTestUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
@@ -115,7 +116,8 @@ public class GitRepositoryReaderTest extends GitPlatformTest {
|
||||
}
|
||||
FileUtil.rename(dotGit, myGitDir);
|
||||
TestCase.assertTrue(myGitDir.exists());
|
||||
myRepositoryReader = new GitRepositoryReader(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(myGitDir));
|
||||
VirtualFile gitDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(myGitDir);
|
||||
myRepositoryReader = new GitRepositoryReader(GitRepositoryFiles.getInstance(gitDir));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package git4idea.repo
|
||||
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import git4idea.GitUtil
|
||||
import git4idea.branch.GitBranchUtil
|
||||
import git4idea.branch.GitBranchesCollection
|
||||
import git4idea.config.GitVersion
|
||||
import git4idea.test.GitExecutor.*
|
||||
@@ -66,12 +67,7 @@ class GitWorkTreeTest : GitPlatformTest() {
|
||||
}
|
||||
|
||||
fun `test remote branches`() {
|
||||
cd(myTestRoot)
|
||||
git("clone --bare $myMainRoot parent.git")
|
||||
cd(myMainRoot)
|
||||
val parentPath = File(myTestRoot, "parent.git").path
|
||||
git("remote add origin $parentPath")
|
||||
git("push origin master")
|
||||
setUpRemote()
|
||||
|
||||
val masterHead = last()
|
||||
git("checkout -b feature")
|
||||
@@ -97,6 +93,25 @@ class GitWorkTreeTest : GitPlatformTest() {
|
||||
assertEquals("Incorrect current revision", featureHead, myRepo.currentRevision)
|
||||
}
|
||||
|
||||
fun `test tracked branch`() {
|
||||
setUpRemote()
|
||||
|
||||
myRepo.update()
|
||||
|
||||
val masterBranch = myRepo.branches.findLocalBranch("master")!!
|
||||
val trackInfo = GitBranchUtil.getTrackInfoForBranch(myRepo, masterBranch)!!
|
||||
assertEquals("origin/master", trackInfo.remoteBranch.nameForLocalOperations)
|
||||
}
|
||||
|
||||
private fun setUpRemote() {
|
||||
cd(myTestRoot)
|
||||
git("clone --bare $myMainRoot parent.git")
|
||||
cd(myMainRoot)
|
||||
val parentPath = File(myTestRoot, "parent.git").path
|
||||
git("remote add origin $parentPath")
|
||||
git("push origin -u master")
|
||||
}
|
||||
|
||||
private fun assertBranchHash(expectedHash: String, branches: GitBranchesCollection, branchName: String) {
|
||||
assertEquals(expectedHash, branches.getHash(branches.findBranchByName(branchName)!!)!!.asString())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user