@@ -97,11 +97,23 @@ def self.open(worktree_path)
9797 #
9898 # @return [RubyGit::Worktree] the Git working tree checked out from the cloned repository
9999 #
100- def self . clone ( repository_url , to_path : '' )
101- command = [ 'clone' , '--' , repository_url , to_path ]
100+ def self . clone ( repository_url , to_path : nil )
101+ command = [ 'clone' , '--' , repository_url ]
102+ command << to_path if to_path
102103 options = { out : StringIO . new , err : StringIO . new }
103- RubyGit ::CommandLine . run ( *command , **options )
104- new ( to_path )
104+ clone_output = RubyGit ::CommandLine . run ( *command , **options ) . stderr
105+ new ( cloned_to ( clone_output ) )
106+ end
107+
108+ # Get path of the cloned worktree from `git clone` stderr output
109+ #
110+ # @param clone_output [String] the stderr output of the `git clone` command
111+ #
112+ # @return [String] the path of the cloned worktree
113+ #
114+ # @api private
115+ def self . cloned_to ( clone_output )
116+ clone_output . match ( /Cloning into ['"](.+)['"]\. \. \. / ) [ 1 ]
105117 end
106118
107119 # Show the working tree and index status
@@ -151,7 +163,7 @@ def repository
151163 command = %w[ rev-parse --git-dir ]
152164 options = { chdir : path , chomp : true , out : StringIO . new , err : StringIO . new }
153165 # rev-parse path might be relative to the worktree, thus the need to expand it
154- git_dir = File . expand_path ( RubyGit ::CommandLine . run ( *command , **options ) . stdout , path )
166+ git_dir = File . realpath ( RubyGit ::CommandLine . run ( *command , **options ) . stdout , path )
155167 Repository . new ( git_dir )
156168 end
157169 end
@@ -182,7 +194,7 @@ def initialize(worktree_path)
182194 def root_path ( worktree_path )
183195 command = %w[ rev-parse --show-toplevel ]
184196 options = { chdir : worktree_path , chomp : true , out : StringIO . new , err : StringIO . new }
185- RubyGit ::CommandLine . run ( *command , **options ) . stdout
197+ File . realpath ( RubyGit ::CommandLine . run ( *command , **options ) . stdout )
186198 end
187199
188200 # Run a Git command in this worktree
0 commit comments