Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions lua/neo-tree/git/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ M.parse_status_porcelain = function(
local unmerged = {}

if porcelain_version == 1 then
local status_chars = "MADTRCU?! "
-- Skip lines until we arrive at a status. this should exclude comments, warnings, and fatal messages
while line do
local first_char = line:sub(1, 1)
if status_chars:find(first_char, 1, true) then
break
end
line = status_iter()
end
while line do
-- Example status:
-- D deleted_staged.txt
Expand All @@ -128,25 +137,24 @@ M.parse_status_porcelain = function(
-- ?? .gitignore
-- ?? untracked.txt
-- !! ignored.txt

local XY = line:sub(1, 2)
if #XY == 0 or XY == "??" or XY == "!!" then
break
end

if XY ~= "# " then
local X = XY:sub(1, 1)
local Y = XY:sub(2, 2)
if M.status_code_is_conflict(X, Y) then
unmerged[#unmerged + 1] = #paths + 1
elseif X == "R" or Y == "R" or X == "C" or Y == "C" then
status_iter() -- consume original path
end

local path = line:sub(4)
local abspath = git_root_dir .. path
paths[#paths + 1] = abspath
statuses[#statuses + 1] = XY:gsub(" ", ".")
local X = XY:sub(1, 1)
local Y = XY:sub(2, 2)
if M.status_code_is_conflict(X, Y) then
unmerged[#unmerged + 1] = #paths + 1
elseif XY:find("[RC]", 1) then
status_iter() -- consume original path
end

local path = line:sub(4)
local abspath = git_root_dir .. path
paths[#paths + 1] = abspath
statuses[#statuses + 1] = XY:gsub(" ", ".")
line = status_iter()
if context then
if not increment_batch_or_yield(context, git_status) then
Expand All @@ -155,6 +163,15 @@ M.parse_status_porcelain = function(
end
end
elseif porcelain_version == 2 then
local status_beginning_chars = "12?!"
-- Skip lines until we arrive at a status. this should exclude comments, warnings, and fatal messages
while line do
local first_char = line:sub(1, 1)
if status_beginning_chars:find(first_char, 1, true) then
break
end
line = status_iter()
end
while line do
-- Example status:
-- 1 D. N... 100644 000000 000000 ade2881afa1dcb156a3aa576024aa0fecf789191 0000000000000000000000000000000000000000 deleted_staged.txt
Expand All @@ -175,9 +192,7 @@ M.parse_status_porcelain = function(

local line_type_byte = line:byte(1, 1)
local abspath, XY
if line_type_byte == COMMENT_BYTE then
-- continue for now
elseif line_type_byte == TYPE_ONE_BYTE then
if line_type_byte == TYPE_ONE_BYTE then
XY = line:sub(3, 4)
-- local submodule_state = line:sub(6, 9)
-- local mH = line:sub(11, 16)
Expand Down
4 changes: 4 additions & 0 deletions tests/neo-tree/git/parser_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ local test_utils = require("tests.utils")
describe("git parser", function()
describe("parses v2 output", function()
local porcelain_v2_status = {
"warning: could not open directory 'foo/bar/': Permission denied",
"#comment",
"1 MM N... 100644 100644 100644 109d711d57a4f9683fde9128389928002162a490 42c6fcc404e517043706028825185095d0c47421 dir1/dir2/dir3/mixed_modify.txt",
"1 D. N... 100644 000000 000000 37ce9c00e8b504beab1de2eafc826384fc370d56 0000000000000000000000000000000000000000 dir1/dir2/staged_delete.txt",
"1 .T N... 100644 100644 120000 0325a864d684a90d6c2ae8ea87cc03f018453413 0325a864d684a90d6c2ae8ea87cc03f018453413 dir1/dir2/type_change.txt",
Expand Down Expand Up @@ -57,6 +59,8 @@ describe("git parser", function()

describe("parses v1 output", function()
local porcelain_v1_status = {
"warning: could not open directory 'foo/bar/': Permission denied",
"#comment",
"MM dir1/dir2/dir3/mixed_modify.txt",
"D dir1/dir2/staged_delete.txt",
" T dir1/dir2/type_change.txt",
Expand Down
Loading