danhper / elixir-git-cli

A simple interface to Git CLI for Elixir
https://hex.pm/packages/git_cli
MIT License
72 stars 13 forks source link

Git.clone with cli arguments returns invalid repo path #6

Closed gcmurphy closed 6 years ago

gcmurphy commented 6 years ago

I want to be able to specify command line arguments directly to clone, the returned repository has an invalid path assigned.

Here are some examples:

URL followed by cli arguments:

iex(20)> {_, repo} = Git.clone ["https://github.com/tuvistavie/elixir-git-cli", "--depth=1"]
{:ok, %Git.Repository{path: "/private/tmp/--depth=1"}}
iex(21)> Git.pull repo
spawn: Could not cd to /private/tmp/--depth=1
{:error, %Git.Error{args: [], code: 2, command: "pull", message: ""}}

CLI arguments, followed by URL

iex(24)> {_, repo} = Git.clone ["--depth=1", "https://github.com/tuvistavie/elixir-git-cli"]
{:ok,
 %Git.Repository{
   path: "/private/tmp/https:/github.com/tuvistavie/elixir-git-cli"
 }}
iex(25)> Git.pull repo
spawn: Could not cd to /private/tmp/https:/github.com/tuvistavie/elixir-git-cli
{:error, %Git.Error{args: [], code: 2, command: "pull", message: ""}}

Currently using something along these lines as a workaround for http/s urls:

clone = fn(repo, args) ->    
 Git.clone! [repo] ++ args
 URI.parse(repo).path 
 |> Path.rootname 
 |> Path.basename
 |> Git.new
end
danhper commented 6 years ago

Thanks for reporting. This should be fixed in the latest version.