5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/colorls/git.rb', line 5
def self.status(repo_path)
prefix = IO.popen(['git', '-C', repo_path, 'rev-parse', '--show-prefix'], err: :close, &:gets)
return unless $CHILD_STATUS.success?
prefix.chomp!
git_status = {}
IO.popen(['git', '-C', repo_path, 'status', '--porcelain', '-z', '-unormal', '--ignored', '.']) do |output|
while (status_line = output.gets "\x0")
mode, file = status_line.chomp("\x0").split(' ', 2)
git_status[file.delete_prefix(prefix)] = mode
output.gets("\x0") if mode.start_with? 'R'
end
end
warn "git status failed in #{repo_path}" unless $CHILD_STATUS.success?
git_status
end
|