@@ -107,11 +107,23 @@ def self.bare(git_dir, options = {})
107
107
# @see https://git-scm.com/docs/git-clone git clone
108
108
# @see https://git-scm.com/docs/git-clone#_git_urls_a_id_urls_a GIT URLs
109
109
#
110
- # @param [URI, Pathname] repository The (possibly remote) repository to clone
110
+ # @param repository_url [URI, Pathname] The (possibly remote) repository url to clone
111
111
# from. See [GIT URLS](https://git-scm.com/docs/git-clone#_git_urls_a_id_urls_a)
112
112
# for more information.
113
113
#
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`.
115
127
#
116
128
# @param [Hash] options The options for this command (see list of valid
117
129
# options below)
@@ -158,8 +170,10 @@ def self.bare(git_dir, options = {})
158
170
# @return [Git::Base] an object that can execute git commands in the context
159
171
# of the cloned local working copy or cloned repository.
160
172
#
161
- def self . clone ( repository , name , options = { } )
162
- Base . clone ( repository , name , options )
173
+ def self . clone ( repository_url , directory = nil , options = { } )
174
+ clone_to_options = options . select { |key , _value | %i[ bare mirror ] . include? ( key ) }
175
+ directory ||= Git ::URL . clone_to ( repository_url , **clone_to_options )
176
+ Base . clone ( repository_url , directory , options )
163
177
end
164
178
165
179
# Export the current HEAD (or a branch, if <tt>options[:branch]</tt>
0 commit comments