diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 6710f925ea21ead59af03ccad7bd0e45e31f5687..6fd50592681ae7fcb2c23a444223d6cfbdd7e7b9 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -54,15 +54,22 @@ module Hub # > git clone git@github.com:kneath/hemingway.git def clone(args) ssh = args.delete('-p') - args[1..-1].each_with_index do |arg, i| - i += 1 + + last_args = args[1..-1].reject { |arg| arg == "--" }.last(3) + last_args.each do |arg| + if arg =~ /^-/ + # Skip mandatory arguments. + last_args.shift if arg =~ /^(--(ref|o|br|u|t|d)[^=]+|-(o|b|u|d))$/ + next + end + if arg.scan('/').size == 1 && !arg.include?(':') url = ssh ? PRIVATE : PUBLIC - args[i] = url % arg.split('/') + args[args.index(arg)] = url % arg.split('/') break elsif arg !~ /:|\// url = ssh ? PRIVATE : PUBLIC - args[i] = url % [ github_user, arg ] + args[args.index(arg)] = url % [ github_user, arg ] break end end diff --git a/test/hub_test.rb b/test/hub_test.rb index 99e9c947552e10b0522be5b5660d054a438ccbf6..653feadd31752f0eac2e4689d118fc020948a2ad 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -30,6 +30,12 @@ class HubTest < Test::Unit::TestCase assert_command input, command end + def test_clone_with_arguments_and_path + input = "clone --bare -o master -- resque" + command = "git clone --bare -o master -- git://github.com/tpw/resque.git" + assert_command input, command + end + def test_your_private_clone_fails_without_config out = hub("clone -p mustache") do Hub::Commands::USER.replace("")