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

Code consistency tweaks

上级 98a5a280
...@@ -109,7 +109,7 @@ module Hub ...@@ -109,7 +109,7 @@ module Hub
# $ hub remote add origin # $ hub remote add origin
# > git remote add origin git://github.com/YOUR_LOGIN/THIS_REPO.git # > git remote add origin git://github.com/YOUR_LOGIN/THIS_REPO.git
def remote(args) def remote(args)
return if args[1] != 'add' or args.last =~ %r{.+?://|.+?@|^[./]} return if args[1] != 'add' || args.last =~ %r{.+?://|.+?@|^[./]}
ssh = args.delete('-p') ssh = args.delete('-p')
...@@ -225,8 +225,7 @@ module Hub ...@@ -225,8 +225,7 @@ module Hub
# $ hub browse # $ hub browse
user = repo_user user = repo_user
else else
warn "Usage: hub browse [<USER>/]<REPOSITORY>" abort "Usage: hub browse [<USER>/]<REPOSITORY>"
exit(1)
end end
params = { :user => user, :repo => repo } params = { :user => user, :repo => repo }
...@@ -240,7 +239,7 @@ module Hub ...@@ -240,7 +239,7 @@ module Hub
params[:web] = "/commits/#{branch}" params[:web] = "/commits/#{branch}"
when 'tree', NilClass when 'tree', NilClass
branch = !dest && tracked_branch branch = !dest && tracked_branch
params[:web] = "/tree/#{branch}" if branch and branch != 'master' params[:web] = "/tree/#{branch}" if branch && branch != 'master'
else else
params[:web] = "/#{subpage}" params[:web] = "/#{subpage}"
end end
...@@ -263,11 +262,11 @@ module Hub ...@@ -263,11 +262,11 @@ module Hub
args.shift args.shift
browse_command(args) do browse_command(args) do
if args.empty? if args.empty?
if branch = tracked_branch and branch != 'master' branch = tracked_branch
if branch && branch != 'master'
range, user = branch, repo_user range, user = branch, repo_user
else else
warn "Usage: hub compare [USER] [<START>...]<END>" abort "Usage: hub compare [USER] [<START>...]<END>"
exit(1)
end end
else else
range = args.pop range = args.pop
......
...@@ -12,7 +12,7 @@ module Hub ...@@ -12,7 +12,7 @@ module Hub
REMOTES = Hash.new do |cache, remote| REMOTES = Hash.new do |cache, remote|
url = GIT_CONFIG["config remote.#{remote}.url"] 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 } cache[remote] = { :user => $1, :repo => $2 }
else else
cache[remote] = { } cache[remote] = { }
...@@ -21,8 +21,6 @@ module Hub ...@@ -21,8 +21,6 @@ module Hub
LGHCONF = "http://github.com/guides/local-github-config" LGHCONF = "http://github.com/guides/local-github-config"
private
def repo_owner def repo_owner
REMOTES[default_remote][:user] REMOTES[default_remote][:user]
end end
...@@ -38,13 +36,19 @@ module Hub ...@@ -38,13 +36,19 @@ module Hub
# Either returns the GitHub user as set by git-config(1) or aborts # Either returns the GitHub user as set by git-config(1) or aborts
# with an error message. # with an error message.
def github_user(fatal = true) def github_user(fatal = true)
GIT_CONFIG['config github.user'] or if user = GIT_CONFIG['config github.user']
fatal ? abort("** No GitHub user set. See #{LGHCONF}") : nil user
elsif fatal
abort("** No GitHub user set. See #{LGHCONF}")
end
end end
def github_token(fatal = true) def github_token(fatal = true)
GIT_CONFIG['config github.token'] or if token = GIT_CONFIG['config github.token']
fatal ? abort("** No GitHub token set. See #{LGHCONF}") : nil token
elsif fatal
abort("** No GitHub token set. See #{LGHCONF}")
end
end end
def current_branch def current_branch
...@@ -82,7 +86,7 @@ module Hub ...@@ -82,7 +86,7 @@ module Hub
def github_url(options = {}) def github_url(options = {})
repo = options[:repo] 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 user ||= options[:user] || github_user
repo ||= repo_name repo ||= repo_name
secure = options[:private] secure = options[:private]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册