From 7d006785d271deb2143571dd6287ee110db02549 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Fri, 25 Dec 2009 05:08:40 +0800 Subject: [PATCH] Support clone flags (e.g., hub clone --bare repo). --- lib/hub/commands.rb | 15 +++++++++++---- test/hub_test.rb | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 6710f925..6fd50592 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 99e9c947..653feadd 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("") -- GitLab