Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git: support unicode filenames #728

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -58,7 +58,7 @@ public GitCommits(Path dir, String range, boolean reverse, int num) throws IOExc
@Override
public Iterator<Commit> iterator() {
var cmd = new ArrayList<String>();
cmd.addAll(List.of("git", "log", "--format=" + format,
cmd.addAll(List.of("git", "-c", "core.quotePath=false", "log", "--format=" + format,
"--patch",
"--find-renames=90%",
"--find-copies=90%",
@@ -863,7 +863,7 @@ public Optional<String> username() throws IOException {
}

private String treeEntry(Path path, Hash hash) throws IOException {
try (var p = Process.capture("git", "ls-tree", hash.hex(), path.toString())
try (var p = Process.capture("git", "-c", "core.quotePath=false", "ls-tree", hash.hex(), path.toString())
.workdir(root())
.execute()) {
var res = await(p);
@@ -879,7 +879,7 @@ private String treeEntry(Path path, Hash hash) throws IOException {

private List<FileEntry> allFiles(Hash hash, List<Path> paths) throws IOException {
var cmd = new ArrayList<String>();
cmd.addAll(List.of("git", "ls-tree", "-r"));
cmd.addAll(List.of("git", "-c", "core.quotePath=false", "ls-tree", "-r"));
cmd.add(hash.hex());
cmd.addAll(paths.stream().map(Path::toString).collect(Collectors.toList()));
try (var p = Process.capture(cmd.toArray(new String[0]))
@@ -970,7 +970,7 @@ public void dump(FileEntry entry, Path to) throws IOException {
@Override
public List<StatusEntry> status(Hash from, Hash to) throws IOException {
var cmd = new ArrayList<String>();
cmd.addAll(List.of("git", "diff", "--raw",
cmd.addAll(List.of("git", "-c", "core.quotePath=false", "diff", "--raw",
"--find-renames=90%",
"--find-copies=90%",
"--find-copies-harder",
@@ -1017,7 +1017,7 @@ public Diff diff(Hash from, Hash to, List<Path> files, int similarity) throws IO
if (similarity < 0 || similarity > 100) {
throw new IllegalArgumentException("similarity must be between 0 and 100, is: " + similarity);
}
var cmd = new ArrayList<>(List.of("git", "diff", "--patch",
var cmd = new ArrayList<>(List.of("git", "-c", "core.quotePath=false", "diff", "--patch",
"--find-renames=" + similarity + "%",
"--find-copies=" + similarity + "%",
"--find-copies-harder",
@@ -1769,6 +1769,30 @@ void testStatus(VCS vcs) throws IOException {
}
}

// Mercurial doesn't seem like to unicode filenames on Windows
@Test
void testStatusWithUnicodeFiles() throws IOException {
try (var dir = new TemporaryDirectory()) {
var r = Repository.init(dir.path(), VCS.GIT);
assertTrue(r.isClean());

var f = dir.path().resolve("REÁDME.md");
Files.writeString(f, "Hello\n");
r.add(f);
var first = r.commit("Add readme", "duke", "duke@openjdk.org");

Files.writeString(f, "Hello\nWorld\n");
r.add(f);
var second = r.commit("Update readme", "duke", "duke@openjdk.org");

var entries = r.status(first, second);
assertEquals(1, entries.size());
var entry = entries.get(0);
assertTrue(entry.status().isModified());
assertEquals(Path.of("REÁDME.md"), entry.target().path().get());
}
}

@ParameterizedTest
@EnumSource(VCS.class)
void testTrackLineEndings(VCS vcs) throws IOException, InterruptedException {