mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
git: IDEA-101222 read branch files in UTF-8
Man git-commit-tree:
Path names are encoded in UTF-8 normalization form C.
This applies to tree objects, the index file, ref names,
as well as path names in command line arguments,
environment variables and config files.
This commit is contained in:
@@ -241,10 +241,15 @@ public class DvcsUtil {
|
||||
*/
|
||||
@NotNull
|
||||
public static String tryLoadFile(@NotNull final File file) throws RepoStateException {
|
||||
return tryLoadFile(file, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String tryLoadFile(@NotNull final File file, @Nullable String encoding) throws RepoStateException {
|
||||
return tryOrThrow(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
return StringUtil.convertLineSeparators(FileUtil.loadFile(file)).trim();
|
||||
return StringUtil.convertLineSeparators(FileUtil.loadFile(file, encoding)).trim();
|
||||
}
|
||||
}, file);
|
||||
}
|
||||
@@ -252,8 +257,14 @@ public class DvcsUtil {
|
||||
@Nullable
|
||||
@Contract("_ , !null -> !null")
|
||||
public static String tryLoadFileOrReturn(@NotNull final File file, @Nullable String defaultValue) {
|
||||
return tryLoadFileOrReturn(file, defaultValue, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("_ , !null, _ -> !null")
|
||||
public static String tryLoadFileOrReturn(@NotNull final File file, @Nullable String defaultValue, @Nullable String encoding) {
|
||||
try {
|
||||
return tryLoadFile(file);
|
||||
return tryLoadFile(file, encoding);
|
||||
}
|
||||
catch (RepoStateException e) {
|
||||
LOG.error(e);
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.intellij.openapi.vcs.changes.ChangeListManager;
|
||||
import com.intellij.openapi.vcs.changes.ChangeListManagerEx;
|
||||
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
|
||||
import com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Consumer;
|
||||
@@ -52,7 +53,10 @@ import git4idea.changes.GitCommittedChangeList;
|
||||
import git4idea.commands.*;
|
||||
import git4idea.config.GitConfigUtil;
|
||||
import git4idea.i18n.GitBundle;
|
||||
import git4idea.repo.*;
|
||||
import git4idea.repo.GitBranchTrackInfo;
|
||||
import git4idea.repo.GitRemote;
|
||||
import git4idea.repo.GitRepository;
|
||||
import git4idea.repo.GitRepositoryManager;
|
||||
import git4idea.util.GitSimplePathsBrowser;
|
||||
import git4idea.util.GitUIUtil;
|
||||
import git4idea.util.StringScanner;
|
||||
@@ -112,7 +116,7 @@ public class GitUtil {
|
||||
return headExists ? dotGit : null;
|
||||
}
|
||||
|
||||
String content = DvcsUtil.tryLoadFileOrReturn(dotGit, null);
|
||||
String content = DvcsUtil.tryLoadFileOrReturn(dotGit, null, CharsetToolkit.UTF8);
|
||||
if (content == null) return null;
|
||||
String pathToDir = parsePathToRepository(content);
|
||||
return findSubmoduleRepositoryDir(rootDir.getPath(), pathToDir);
|
||||
|
||||
@@ -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.vfs.CharsetToolkit;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -169,7 +170,7 @@ class GitRepositoryReader {
|
||||
if (rebaseDir.exists()) {
|
||||
File headName = new File(rebaseDir, "head-name");
|
||||
if (headName.exists()) {
|
||||
return DvcsUtil.tryLoadFileOrReturn(headName, null);
|
||||
return DvcsUtil.tryLoadFileOrReturn(headName, null, CharsetToolkit.UTF8);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -197,7 +198,7 @@ class GitRepositoryReader {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
try {
|
||||
String content = DvcsUtil.tryLoadFile(myPackedRefsFile);
|
||||
String content = DvcsUtil.tryLoadFile(myPackedRefsFile, CharsetToolkit.UTF8);
|
||||
return ContainerUtil.map2MapNotNull(LineTokenizer.tokenize(content, false), new Function<String, Pair<String, String>>() {
|
||||
@Override
|
||||
public Pair<String, String> fun(String line) {
|
||||
@@ -319,7 +320,7 @@ class GitRepositoryReader {
|
||||
private HeadInfo readHead() {
|
||||
String headContent;
|
||||
try {
|
||||
headContent = DvcsUtil.tryLoadFile(myHeadFile);
|
||||
headContent = DvcsUtil.tryLoadFile(myHeadFile, CharsetToolkit.UTF8);
|
||||
}
|
||||
catch (RepoStateException e) {
|
||||
LOG.error(e);
|
||||
|
||||
@@ -111,6 +111,14 @@ class GitRepositoryReaderNewTest : GitSingleRepoTest() {
|
||||
assertEquals("Fresh repository should be on master", "master", currentBranch!!.name)
|
||||
}
|
||||
|
||||
fun `test non-ascii current branch name`() {
|
||||
makeCommit("file.txt")
|
||||
val branch = "teslá"
|
||||
git("checkout -b $branch")
|
||||
val state = readState()
|
||||
assertEquals(branch, state.currentBranch!!.name)
|
||||
}
|
||||
|
||||
private fun moveToDetachedHead(): String {
|
||||
makeCommit("file.txt")
|
||||
makeCommit("file.txt")
|
||||
|
||||
Reference in New Issue
Block a user