diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 7611f22362478f5a8d3c0b1398f7b4b6c4182a4d..c921a66af007ad8ecb88023a3a255b17b4e8a08c 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -1,7 +1,7 @@ module Hub # See context.rb module Context; end - + # The Commands module houses the git commands that hub # lovingly wraps. If a method exists here, it is expected to have a # corresponding git command which either gets run before or after @@ -109,7 +109,7 @@ module Hub # $ hub remote add origin # > git remote add origin git://github.com/YOUR_LOGIN/THIS_REPO.git def remote(args) - return if args[1] != 'add' or args.last =~ %r{.+?://|.+?@|^[./]} + return if args[1] != 'add' || args.last =~ %r{.+?://|.+?@|^[./]} ssh = args.delete('-p') @@ -225,8 +225,7 @@ module Hub # $ hub browse user = repo_user else - warn "Usage: hub browse [/]" - exit(1) + abort "Usage: hub browse [/]" end params = { :user => user, :repo => repo } @@ -240,7 +239,7 @@ module Hub params[:web] = "/commits/#{branch}" when 'tree', NilClass branch = !dest && tracked_branch - params[:web] = "/tree/#{branch}" if branch and branch != 'master' + params[:web] = "/tree/#{branch}" if branch && branch != 'master' else params[:web] = "/#{subpage}" end @@ -263,11 +262,11 @@ module Hub args.shift browse_command(args) do if args.empty? - if branch = tracked_branch and branch != 'master' + branch = tracked_branch + if branch && branch != 'master' range, user = branch, repo_user else - warn "Usage: hub compare [USER] [...]" - exit(1) + abort "Usage: hub compare [USER] [...]" end else range = args.pop diff --git a/lib/hub/context.rb b/lib/hub/context.rb index 6d7919403c108126842ee74a54501c18ea8b7689..df64abf415be6746afc94b8c23a234abd2c7e83d 100644 --- a/lib/hub/context.rb +++ b/lib/hub/context.rb @@ -12,7 +12,7 @@ module Hub REMOTES = Hash.new do |cache, remote| url = GIT_CONFIG["config remote.#{remote}.url"] - if url and url.to_s =~ %r{\bgithub\.com[:/](.+)/(.+).git$} + if url && url.to_s =~ %r{\bgithub\.com[:/](.+)/(.+).git$} cache[remote] = { :user => $1, :repo => $2 } else cache[remote] = { } @@ -21,8 +21,6 @@ module Hub LGHCONF = "http://github.com/guides/local-github-config" - private - def repo_owner REMOTES[default_remote][:user] end @@ -38,13 +36,19 @@ module Hub # Either returns the GitHub user as set by git-config(1) or aborts # with an error message. def github_user(fatal = true) - GIT_CONFIG['config github.user'] or - fatal ? abort("** No GitHub user set. See #{LGHCONF}") : nil + if user = GIT_CONFIG['config github.user'] + user + elsif fatal + abort("** No GitHub user set. See #{LGHCONF}") + end end def github_token(fatal = true) - GIT_CONFIG['config github.token'] or - fatal ? abort("** No GitHub token set. See #{LGHCONF}") : nil + if token = GIT_CONFIG['config github.token'] + token + elsif fatal + abort("** No GitHub token set. See #{LGHCONF}") + end end def current_branch @@ -82,7 +86,7 @@ module Hub def github_url(options = {}) repo = options[:repo] - user, repo = repo.split('/') if repo and repo.index('/') + user, repo = repo.split('/') if repo && repo.index('/') user ||= options[:user] || github_user repo ||= repo_name secure = options[:private]