Skip to content

Commit da23b9a

Browse files
committed
fix(git): Handle chars with byte values > 0x80 in file names (fixes #419)
1 parent a18981d commit da23b9a

File tree

1 file changed

+51
-10
lines changed

1 file changed

+51
-10
lines changed

lua/diffview/vcs/adapters/git/init.lua

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ function GitAdapter:stream_fh_data(state)
567567
"-P",
568568
"-c",
569569
"gc.auto=0",
570+
"-c",
571+
"core.quotePath=false",
570572
"log",
571573
"--pretty=format:%x00%n" .. GitAdapter.COMMIT_PRETTY_FMT,
572574
"--numstat",
@@ -644,6 +646,8 @@ function GitAdapter:stream_line_trace_data(state)
644646
"-P",
645647
"-c",
646648
"gc.auto=0",
649+
"-c",
650+
"core.quotePath=false",
647651
"log",
648652
"--color=never",
649653
"--no-ext-diff",
@@ -1026,6 +1030,8 @@ GitAdapter.fh_retry_commit = async.wrap(function(self, rev_arg, state, opt, call
10261030
"-P",
10271031
"-c",
10281032
"gc.auto=0",
1033+
"-c",
1034+
"core.quotePath=false",
10291035
"show",
10301036
"--pretty=format:" .. GitAdapter.COMMIT_PRETTY_FMT,
10311037
"--numstat",
@@ -1124,21 +1130,33 @@ function GitAdapter:parse_fh_data(data, commit, state)
11241130
for i = 1, #data.numstat do
11251131
local status, name, oldname
11261132

1127-
local namestat_fields = utils.str_split(data.namestat[i])
1128-
local num_parents = #namestat_fields[1]:match("^(:+)")
1133+
local line = data.namestat[i]
1134+
local num_parents = #(line:match("^(:+)"))
11291135
local offset = (num_parents + 1) * 2 + 1
1130-
status = namestat_fields[offset]:match("^%a%a?")
1136+
local namestat_fields
1137+
1138+
local j = 1
1139+
for idx in line:gmatch("%s+()") do
1140+
---@cast idx integer
1141+
j = j + 1
1142+
if j == offset then
1143+
namestat_fields = utils.str_split(line:sub(idx), "\t")
1144+
break
1145+
end
1146+
end
11311147

1132-
if num_parents == 1 and namestat_fields[offset + 2] then
1148+
status = namestat_fields[1]:match("^%a%a?")
1149+
1150+
if num_parents == 1 and namestat_fields[3] then
11331151
-- Rename
1134-
oldname = namestat_fields[offset + 1]
1135-
name = namestat_fields[offset + 2]
1152+
oldname = namestat_fields[2]
1153+
name = namestat_fields[3]
11361154

11371155
if state.single_file then
11381156
state.old_path = oldname
11391157
end
11401158
else
1141-
name = namestat_fields[offset + 1]
1159+
name = namestat_fields[2]
11421160
end
11431161

11441162
local stats = {
@@ -1655,13 +1673,29 @@ GitAdapter.tracked_files = async.wrap(function(self, left, right, args, kind, op
16551673

16561674
local namestat_job = Job({
16571675
command = self:bin(),
1658-
args = utils.vec_join(self:args(), "diff", "--ignore-submodules", "--name-status", args),
1676+
args = utils.vec_join(
1677+
self:args(),
1678+
"-c",
1679+
"core.quotePath=false",
1680+
"diff",
1681+
"--ignore-submodules",
1682+
"--name-status",
1683+
args
1684+
),
16591685
cwd = self.ctx.toplevel,
16601686
log_opt = log_opt,
16611687
})
16621688
local numstat_job = Job({
16631689
command = self:bin(),
1664-
args = utils.vec_join(self:args(), "diff", "--ignore-submodules", "--numstat", args),
1690+
args = utils.vec_join(
1691+
self:args(),
1692+
"-c",
1693+
"core.quotePath=false",
1694+
"diff",
1695+
"--ignore-submodules",
1696+
"--numstat",
1697+
args
1698+
),
16651699
cwd = self.ctx.toplevel,
16661700
log_opt = log_opt,
16671701
})
@@ -1769,7 +1803,14 @@ end)
17691803
GitAdapter.untracked_files = async.wrap(function(self, left, right, opt, callback)
17701804
local job = Job({
17711805
command = self:bin(),
1772-
args = utils.vec_join(self:args(), "ls-files", "--others", "--exclude-standard"),
1806+
args = utils.vec_join(
1807+
self:args(),
1808+
"-c",
1809+
"core.quotePath=false",
1810+
"ls-files",
1811+
"--others",
1812+
"--exclude-standard"
1813+
),
17731814
cwd = self.ctx.toplevel,
17741815
log_opt = { label = "GitAdapter:untracked_files()", }
17751816
})

0 commit comments

Comments
 (0)