提交 8345753e 编写于 作者: C Chris Wanstrath

Code consistency tweaks

上级 98a5a280
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 [<USER>/]<REPOSITORY>"
exit(1)
abort "Usage: hub browse [<USER>/]<REPOSITORY>"
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] [<START>...]<END>"
exit(1)
abort "Usage: hub compare [USER] [<START>...]<END>"
end
else
range = args.pop
......
......@@ -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]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册