From 60cf5697762224fe1eb5cb953e9297c3039b9884 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Mon, 25 Apr 2022 22:58:19 +0200 Subject: [PATCH] Pass a null device instead of explicitly closing stderr When calling git any error messages should be suppressed (e.g. if an directory is not inside a git repository). Closing the stderr output when calling `IO.popen` works fine on POSIX systems, but on Windows it does not and spits out a warning for every invocation: ``` git.rb:44: warning: cannot close fd before spawn ``` Fixes #517. --- lib/colorls/git.rb | 2 +- spec/color_ls/git_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/colorls/git.rb b/lib/colorls/git.rb index 3b2102b..cf3f75d 100644 --- a/lib/colorls/git.rb +++ b/lib/colorls/git.rb @@ -52,7 +52,7 @@ module ColorLS def git_prefix(repo_path) [ - IO.popen(['git', '-C', repo_path, 'rev-parse', '--show-prefix'], err: :close, &:gets)&.chomp, + IO.popen(['git', '-C', repo_path, 'rev-parse', '--show-prefix'], err: File::NULL, &:gets)&.chomp, $CHILD_STATUS.success? ] rescue Errno::ENOENT diff --git a/spec/color_ls/git_spec.rb b/spec/color_ls/git_spec.rb index 317971e..65ee927 100644 --- a/spec/color_ls/git_spec.rb +++ b/spec/color_ls/git_spec.rb @@ -39,4 +39,10 @@ RSpec.describe ColorLS::Git do expect(subject.status('/repo/')).to include('subdir' => Set['M', 'D']) end end + + context 'determining the git status' do + it 'does not output to stderr' do + expect { subject.status('.') }.not_to output.to_stderr + end + end end