Skip to content

Commit 77cc10d

Browse files
committed
Capture standard error when shelling out to git.
Also better error messages
1 parent 8ccbb1a commit 77cc10d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/pry-git.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require 'grit'
77
require 'diffy'
88
require 'tempfile'
9+
require 'open3'
910

1011
module PryGit
1112
module GitHelpers
@@ -36,12 +37,13 @@ def relative_path(root, path)
3637

3738
# return the git top level for a given directory
3839
def find_git_root(dir)
39-
git_root = "."
40+
git_root = nil
4041
Dir.chdir dir do
41-
git_root = `git rev-parse --show-toplevel`.chomp
42+
git_root, _ = Open3.capture2e("git rev-parse --show-toplevel")
43+
git_root = git_root.chomp
4244
end
4345

44-
raise "No associated git repository found!" if git_root =~ /fatal:/
46+
raise Pry::CommandError, "No git repository found in #{dir}" if git_root =~ /fatal:/
4547
git_root
4648
end
4749
end

0 commit comments

Comments
 (0)