@@ -107,11 +107,23 @@ def self.bare(git_dir, options = {})
107107 # @see https://git-scm.com/docs/git-clone git clone
108108 # @see https://git-scm.com/docs/git-clone#_git_urls_a_id_urls_a GIT URLs
109109 #
110- # @param [URI, Pathname] repository The (possibly remote) repository to clone
110+ # @param repository_url [URI, Pathname] The (possibly remote) repository url to clone
111111 # from. See [GIT URLS](https://git-scm.com/docs/git-clone#_git_urls_a_id_urls_a)
112112 # for more information.
113113 #
114- # @param [Pathname] name The directory to clone into.
114+ # @param directory [Pathname, nil] The directory to clone into
115+ #
116+ # If `directory` is a relative directory it is relative to the `path` option if
117+ # given. If `path` is not given, `directory` is relative to the current working
118+ # directory.
119+ #
120+ # If `nil`, `directory` will be set to the basename of the last component of
121+ # the path from the `repository_url`. For example, for the URL:
122+ # `https://github.com/org/repo.git`, `directory` will be set to `repo`.
123+ #
124+ # If the last component of the path is `.git`, the next-to-last component of
125+ # the path is used. For example, for the URL `/Users/me/foo/.git`, `directory`
126+ # will be set to `foo`.
115127 #
116128 # @param [Hash] options The options for this command (see list of valid
117129 # options below)
@@ -158,8 +170,9 @@ def self.bare(git_dir, options = {})
158170 # @return [Git::Base] an object that can execute git commands in the context
159171 # of the cloned local working copy or cloned repository.
160172 #
161- def self . clone ( repository , name , options = { } )
162- Base . clone ( repository , name , options )
173+ def self . clone ( repository_url , directory = nil , options = { } )
174+ directory ||= Git ::URL . clone_to ( repository_url , **options . slice ( :bare , :mirror ) )
175+ Base . clone ( repository_url , directory , options )
163176 end
164177
165178 # Export the current HEAD (or a branch, if <tt>options[:branch]</tt>
0 commit comments