From 1c0381fa1ccd334870b96e6d807e0cbc897d8c2a Mon Sep 17 00:00:00 2001 From: Chris Hoffman Date: Thu, 11 Mar 2010 05:29:40 +0800 Subject: [PATCH] Refactor remote command logic --- lib/hub/commands.rb | 55 +++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 15a8add6..db8f19ba 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -112,42 +112,27 @@ module Hub ssh = args.delete('-p') url = ssh ? PRIVATE : PUBLIC - - if args.last =~ /\b(.*?)\/([^\/]+)$/ - # user/repo - user, repo = $1, $2 - - if args.words[-2] == args.words[1] - # rtomayko/tilt => rtomayko - # Make sure you dance around flags. - idx = args.index( args.words[-1] ) - args[idx] = user - else - # They're specifying the remote name manually (e.g. - # git remote add blah rtomayko/tilt), so just drop the last - # argument. - args.replace args[0...-1] - end - - args << url % [ user, repo ] - elsif args.last !~ /:|\// - if args.words[2] == 'origin' && args.words[3].nil? - # Origin special case. - user = github_user - else - # Assume no : or / means GitHub user. - user = args.last - end - - if args.words[-2] != args.words[1] - # They're specifying the remote name manually (e.g. - # git remote add blah rtomayko), so just drop the last - # argument. - args.replace args[0...-1] - end - - args << url % [ user, REPO ] + + # user/repo + args.last =~ /\b(.+?)(?:\/(.+))?$/ + user, repo = $1, $2 || REPO + + if args.words[2] == 'origin' && args.words[3].nil? + # Origin special case. + user = github_user + elsif args.words[-2] == args.words[1] + # rtomayko/tilt => rtomayko + # Make sure you dance around flags. + idx = args.index( args.words[-1] ) + args[idx] = user + else + # They're specifying the remote name manually (e.g. + # git remote add blah rtomayko/tilt), so just drop the last + # argument. + args.replace args[0...-1] end + + args << url % [ user, repo ] end # $ hub init -g -- GitLab