Skip next NUL separated git status field for renames

In the `-z` git status format, a NUL follows each file name. When files are
renamed, the status field is followed by a space, the "to" path, a NUL
character, the "from" path and a terminating NUL.

This fixes #185.
This commit is contained in:
Claudio Bley 2018-03-27 19:30:12 +02:00
parent 51fe55cc8f
commit 8b0ea26c01

View file

@ -4,8 +4,13 @@ module ColorLS
@git_status = {}
IO.popen(['git', '-C', repo_path, 'status', '--porcelain', '-z', '-unormal', '--ignored']) do |output|
output.read.split("\x0").map { |x| x.split(' ', 2) }.each do |mode, file|
while (status_line = output.gets "\x0")
mode, file = status_line.chomp("\x0").split(' ', 2)
@git_status[file] = mode
# skip the next \x0 separated original path for renames, issue #185
output.gets("\x0") if mode.start_with? 'R'
end
end
warn "git status failed in #{repo_path}" unless $CHILD_STATUS.success?