Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git.clone requires 2 arguments instead of 1 #565

Closed
sethfri opened this issue Jan 21, 2022 · 2 comments · Fixed by #578
Closed

Git.clone requires 2 arguments instead of 1 #565

sethfri opened this issue Jan 21, 2022 · 2 comments · Fixed by #578

Comments

@sethfri
Copy link

sethfri commented Jan 21, 2022

Subject of the issue

In the example usage of Git.clone, the documentation says that it can be called with only the URL of the repo, like so:

git = Git.clone('https://github.com/ruby-git/ruby-git.git')

However, the method itself requires both the URL and the name of the directory. You can't just use the default

Your environment

  • Git 2.34.0
  • ruby-git 1.8.1
  • Ruby 2.7.4

Steps to reproduce

git = Git.clone('https://github.com/ruby-git/ruby-git.git')

Expected behaviour

The clone will work and use ruby-git as the default name of the clone directory

Actual behaviour

The method fails with wrong number of arguments (given 1, expected 2..3)

@masterkain
Copy link

masterkain commented Mar 21, 2022

also if you do g = Git.clone(GIT_URL, branch: 'master') it will clone into a folder named {/branch=>"master"} resulting in

/Users/kain/.rvm/gems/ruby-3.0.0/gems/git-1.10.2/lib/git/base.rb:613:in `expand_path': no implicit conversion of Hash into String (TypeError)
	from /Users/kain/.rvm/gems/ruby-3.0.0/gems/git-1.10.2/lib/git/base.rb:613:in `normalize_working_directory'
	from /Users/kain/.rvm/gems/ruby-3.0.0/gems/git-1.10.2/lib/git/base.rb:592:in `normalize_paths'
	from /Users/kain/.rvm/gems/ruby-3.0.0/gems/git-1.10.2/lib/git/base.rb:22:in `clone'
	from /Users/kain/.rvm/gems/ruby-3.0.0/gems/git-1.10.2/lib/git.rb:161:in `clone'
	from main.rb:69:in `<main>'

@jcouball
Copy link
Member

jcouball commented Apr 26, 2022

Take a look at #578 which makes the directory parameter to Git.clone optional which means that you can:

# assume I am starting in the `/Users/me/Projects` directory
g = Git.clone('https://github.com/ruby-git/ruby-git')
g.dir.to_s #=> "/Users/me/Projects/ruby-git"

Since the definition of Git.clone is:

def self.clone(repository_url, directory = nil, options = {})

In order to pass a an option, you will need to pass nil for directory. So this won't have the desired effect:

g = Git.clone(GIT_URL, branch: 'master')

Instead, you will need to do this:

g = Git.clone(GIT_URL, nil, branch: 'master')

I think we will need to transition to using keyword parameters (or move the directory parameter to an option) in order to make Git.clone(url, branch: 'master') work like you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants