mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-12 05:31:14 +02:00
Fix error when git is not installed
This commit is contained in:
parent
93b08f9403
commit
373fb67003
2 changed files with 13 additions and 8 deletions
|
@ -6,11 +6,11 @@ require 'set'
|
|||
module ColorLS
|
||||
module Git
|
||||
def self.status(repo_path)
|
||||
prefix = git_prefix(repo_path)
|
||||
prefix, success = git_prefix(repo_path)
|
||||
|
||||
return unless $CHILD_STATUS.success?
|
||||
return unless success
|
||||
|
||||
prefix = Pathname.new(prefix.chomp)
|
||||
prefix = Pathname.new(prefix)
|
||||
|
||||
git_status = Hash.new { |hash, key| hash[key] = Set.new }
|
||||
|
||||
|
@ -52,7 +52,12 @@ module ColorLS
|
|||
private
|
||||
|
||||
def git_prefix(repo_path)
|
||||
IO.popen(['git', '-C', repo_path, 'rev-parse', '--show-prefix'], err: :close, &:gets)
|
||||
[
|
||||
IO.popen(['git', '-C', repo_path, 'rev-parse', '--show-prefix'], err: :close, &:gets)&.chomp,
|
||||
$CHILD_STATUS.success?
|
||||
]
|
||||
rescue Errno::ENOENT
|
||||
[nil, false]
|
||||
end
|
||||
|
||||
def git_subdir_status(repo_path)
|
||||
|
|
|
@ -14,14 +14,14 @@ RSpec.describe ColorLS::Git do
|
|||
|
||||
context 'with file in repository root' do
|
||||
it 'returns `M`' do
|
||||
allow(subject).to receive(:git_prefix).with('/repo/').and_return('')
|
||||
allow(subject).to receive(:git_prefix).with('/repo/').and_return(['', true])
|
||||
allow(subject).to receive(:git_subdir_status).and_yield(git_status(' M foo.txt'))
|
||||
|
||||
expect(subject.status('/repo/')).to include('foo.txt' => Set['M'])
|
||||
end
|
||||
|
||||
it 'returns `??`' do
|
||||
allow(subject).to receive(:git_prefix).with('/repo/').and_return('')
|
||||
allow(subject).to receive(:git_prefix).with('/repo/').and_return(['', true])
|
||||
allow(subject).to receive(:git_subdir_status).and_yield(git_status('?? foo.txt'))
|
||||
|
||||
expect(subject.status('/repo/')).to include('foo.txt' => Set['??'])
|
||||
|
@ -30,14 +30,14 @@ RSpec.describe ColorLS::Git do
|
|||
|
||||
context 'with file in subdir' do
|
||||
it 'returns `M` for subdir' do
|
||||
allow(subject).to receive(:git_prefix).with('/repo/').and_return('')
|
||||
allow(subject).to receive(:git_prefix).with('/repo/').and_return(['', true])
|
||||
allow(subject).to receive(:git_subdir_status).and_yield(git_status(' M subdir/foo.txt'))
|
||||
|
||||
expect(subject.status('/repo/')).to include('subdir' => Set['M'])
|
||||
end
|
||||
|
||||
it 'returns `M` and `D` for subdir' do
|
||||
allow(subject).to receive(:git_prefix).with('/repo/').and_return('')
|
||||
allow(subject).to receive(:git_prefix).with('/repo/').and_return(['', true])
|
||||
allow(subject).to receive(:git_subdir_status).and_yield(git_status(' M subdir/foo.txt', 'D subdir/other.c'))
|
||||
|
||||
expect(subject.status('/repo/')).to include('subdir' => Set['M', 'D'])
|
||||
|
|
Loading…
Reference in a new issue