Upgraded hub command

This commit is contained in:
Yan Pritzker 2013-08-04 16:52:04 -05:00
parent 5c6b241605
commit 0d58568c9c

343
bin/hub
View File

@ -7,7 +7,7 @@
# #
module Hub module Hub
Version = VERSION = '1.10.2' Version = VERSION = '1.10.6'
end end
module Hub module Hub
@ -17,7 +17,6 @@ module Hub
def initialize(*args) def initialize(*args)
super super
@executable = ENV["GIT"] || "git" @executable = ENV["GIT"] || "git"
@after = nil
@skip = @noop = false @skip = @noop = false
@original_args = args.first @original_args = args.first
@chain = [nil] @chain = [nil]
@ -228,7 +227,7 @@ module Hub
end end
def create_repo project, options = {} def create_repo project, options = {}
is_org = project.owner != config.username(api_host(project.host)) is_org = project.owner.downcase != config.username(api_host(project.host)).downcase
params = { :name => project.name, :private => !!options[:private] } params = { :name => project.name, :private => !!options[:private] }
params[:description] = options[:description] if options[:description] params[:description] = options[:description] if options[:description]
params[:homepage] = options[:homepage] if options[:homepage] params[:homepage] = options[:homepage] if options[:homepage]
@ -239,6 +238,7 @@ module Hub
res = post "https://%s/user/repos" % api_host(project.host), params res = post "https://%s/user/repos" % api_host(project.host), params
end end
res.error! unless res.success? res.error! unless res.success?
res.data
end end
def pullrequest_info project, pull_id def pullrequest_info project, pull_id
@ -269,6 +269,14 @@ module Hub
res.data res.data
end end
def statuses project, sha
res = get "https://%s/repos/%s/%s/statuses/%s" %
[api_host(project.host), project.owner, project.name, sha]
res.error! unless res.success?
res.data
end
module HttpMethods module HttpMethods
module ResponseMethods module ResponseMethods
def status() code.to_i end def status() code.to_i end
@ -281,7 +289,12 @@ module Hub
data['errors'].map do |err| data['errors'].map do |err|
case err['code'] case err['code']
when 'custom' then err['message'] when 'custom' then err['message']
when 'missing_field' then "field '%s' is missing" % err['field'] when 'missing_field'
%(Missing field: "%s") % err['field']
when 'invalid'
%(Invalid value for "%s": "%s") % [ err['field'], err['value'] ]
when 'unauthorized'
%(Not allowed to change field "%s") % err['field']
end end
end.compact if data['errors'] end.compact if data['errors']
end end
@ -295,10 +308,17 @@ module Hub
perform_request url, :Post do |req| perform_request url, :Post do |req|
if params if params
req.body = JSON.dump params req.body = JSON.dump params
req['Content-Type'] = 'application/json' req['Content-Type'] = 'application/json;charset=utf-8'
end end
yield req if block_given? yield req if block_given?
req['Content-Length'] = req.body ? req.body.length : 0 req['Content-Length'] = byte_size req.body
end
end
def byte_size str
if str.respond_to? :bytesize then str.bytesize
elsif str.respond_to? :length then str.length
else 0
end end
end end
@ -315,14 +335,18 @@ module Hub
create_connection host_url create_connection host_url
end end
req['User-Agent'] = "Hub #{Hub::VERSION}"
apply_authentication(req, url) apply_authentication(req, url)
yield req if block_given? yield req if block_given?
begin
res = http.start { http.request(req) } res = http.start { http.request(req) }
res.extend ResponseMethods res.extend ResponseMethods
res return res
rescue SocketError => err rescue SocketError => err
raise Context::FatalError, "error with #{type.to_s.upcase} #{url} (#{err.message})" raise Context::FatalError, "error with #{type.to_s.upcase} #{url} (#{err.message})"
end end
end
def request_uri url def request_uri url
str = url.request_uri str = url.request_uri
@ -373,10 +397,17 @@ module Hub
if (req.path =~ /\/authorizations$/) if (req.path =~ /\/authorizations$/)
super super
else else
refresh = false
user = url.user || config.username(url.host) user = url.user || config.username(url.host)
token = config.oauth_token(url.host, user) { token = config.oauth_token(url.host, user) {
refresh = true
obtain_oauth_token url.host, user obtain_oauth_token url.host, user
} }
if refresh
res = get "https://#{url.host}/user"
res.error! unless res.success?
config.update_username(url.host, user, res.data['login'])
end
req['Authorization'] = "token #{token}" req['Authorization'] = "token #{token}"
end end
end end
@ -462,6 +493,7 @@ module Hub
end end
def username host def username host
return ENV['GITHUB_USER'] unless ENV['GITHUB_USER'].to_s.empty?
host = normalize_host host host = normalize_host host
@data.fetch_user host do @data.fetch_user host do
if block_given? then yield if block_given? then yield
@ -470,6 +502,12 @@ module Hub
end end
end end
def update_username host, old_username, new_username
entry = @data.entry_for_user(normalize_host(host), old_username)
entry['user'] = new_username
@data.save
end
def api_token host, user def api_token host, user
host = normalize_host host host = normalize_host host
@data.fetch_value host, user, :api_token do @data.fetch_value host, user, :api_token do
@ -480,6 +518,7 @@ module Hub
end end
def password host, user def password host, user
return ENV['GITHUB_PASSWORD'] unless ENV['GITHUB_PASSWORD'].to_s.empty?
host = normalize_host host host = normalize_host host
@password_cache["#{user}@#{host}"] ||= prompt_password host, user @password_cache["#{user}@#{host}"] ||= prompt_password host, user
end end
@ -504,11 +543,14 @@ module Hub
end end
end end
NULL = defined?(File::NULL) ? File::NULL :
File.exist?('/dev/null') ? '/dev/null' : 'NUL'
def askpass def askpass
tty_state = `stty -g` tty_state = `stty -g 2>#{NULL}`
system 'stty raw -echo -icanon isig' if $?.success? system 'stty raw -echo -icanon isig' if $?.success?
pass = '' pass = ''
while char = $stdin.getbyte and !(char == 13 or char == 10) while char = getbyte($stdin) and !(char == 13 or char == 10)
if char == 127 or char == 8 if char == 127 or char == 8
pass[-1,1] = '' unless pass.empty? pass[-1,1] = '' unless pass.empty?
else else
@ -520,6 +562,14 @@ module Hub
system "stty #{tty_state}" unless tty_state.empty? system "stty #{tty_state}" unless tty_state.empty?
end end
def getbyte(io)
if io.respond_to?(:getbyte)
io.getbyte
else
io.getc
end
end
def proxy_uri(with_ssl) def proxy_uri(with_ssl)
env_name = "HTTP#{with_ssl ? 'S' : ''}_PROXY" env_name = "HTTP#{with_ssl ? 'S' : ''}_PROXY"
if proxy = ENV[env_name] || ENV[env_name.downcase] and !proxy.empty? if proxy = ENV[env_name] || ENV[env_name.downcase] and !proxy.empty?
@ -744,6 +794,7 @@ module Hub
def initialize(*args) def initialize(*args)
super super
self.name = self.name.tr(' ', '-')
self.host ||= (local_repo || LocalRepo).default_host self.host ||= (local_repo || LocalRepo).default_host
self.host = host.sub(/^ssh\./i, '') if 'ssh.github.com' == host.downcase self.host = host.sub(/^ssh\./i, '') if 'ssh.github.com' == host.downcase
end end
@ -854,7 +905,7 @@ module Hub
end end
def project def project
urls.each { |url| urls.each_value { |url|
if valid = GithubProject.from_url(url, local_repo) if valid = GithubProject.from_url(url, local_repo)
return valid return valid
end end
@ -863,15 +914,21 @@ module Hub
end end
def urls def urls
@urls ||= local_repo.git_config("remote.#{name}.url", :all).to_s.split("\n").map { |uri| return @urls if defined? @urls
@urls = {}
local_repo.git_command('remote -v').to_s.split("\n").map do |line|
next if line !~ /^(.+?)\t(.+) \((.+)\)$/
remote, uri, type = $1, $2, $3
next if remote != self.name
if uri =~ %r{^[\w-]+://} or uri =~ %r{^([^/]+?):}
uri = "ssh://#{$1}/#{$'}" if $1
begin begin
if uri =~ %r{^[\w-]+://} then uri_parse(uri) @urls[type] = uri_parse(uri)
elsif uri =~ %r{^([^/]+?):} then uri_parse("ssh://#{$1}/#{$'}") # scp-like syntax
end
rescue URI::InvalidURIError rescue URI::InvalidURIError
nil
end end
}.compact end
end
@urls
end end
def uri_parse uri def uri_parse uri
@ -946,13 +1003,15 @@ module Hub
editor = git_command 'var GIT_EDITOR' editor = git_command 'var GIT_EDITOR'
editor = ENV[$1] if editor =~ /^\$(\w+)$/ editor = ENV[$1] if editor =~ /^\$(\w+)$/
editor = File.expand_path editor if (editor =~ /^[~.]/ or editor.index('/')) and editor !~ /["']/ editor = File.expand_path editor if (editor =~ /^[~.]/ or editor.index('/')) and editor !~ /["']/
editor.shellsplit if File.exist? editor then [editor]
else editor.shellsplit
end
end end
module System module System
def browser_launcher def browser_launcher
browser = ENV['BROWSER'] || ( browser = ENV['BROWSER'] || (
osx? ? 'open' : windows? ? 'start' : osx? ? 'open' : windows? ? %w[cmd /c start] :
%w[xdg-open cygstart x-www-browser firefox opera mozilla netscape].find { |comm| which comm } %w[xdg-open cygstart x-www-browser firefox opera mozilla netscape].find { |comm| which comm }
) )
@ -984,6 +1043,10 @@ module Hub
def command?(name) def command?(name)
!which(name).nil? !which(name).nil?
end end
def tmp_dir
ENV['TMPDIR'] || ENV['TEMP'] || '/tmp'
end
end end
include System include System
@ -1103,10 +1166,22 @@ class Hub::JSON
end end
end end
def generate_String(str) str.inspect end ESC_MAP = Hash.new {|h,k| k }.update \
alias generate_Numeric generate_String "\r" => 'r',
alias generate_TrueClass generate_String "\n" => 'n',
alias generate_FalseClass generate_String "\f" => 'f',
"\t" => 't',
"\b" => 'b'
def generate_String(str)
escaped = str.gsub(/[\r\n\f\t\b"\\]/) { "\\#{ESC_MAP[$&]}"}
%("#{escaped}")
end
def generate_simple(obj) obj.inspect end
alias generate_Numeric generate_simple
alias generate_TrueClass generate_simple
alias generate_FalseClass generate_simple
def generate_Symbol(sym) generate_String(sym.to_s) end def generate_Symbol(sym) generate_String(sym.to_s) end
@ -1132,10 +1207,10 @@ module Hub
extend Context extend Context
NAME_RE = /[\w.][\w.-]*/ NAME_RE = /[\w.][\w.-]*/
OWNER_RE = /[a-zA-Z0-9-]+/ OWNER_RE = /[a-zA-Z0-9][a-zA-Z0-9-]*/
NAME_WITH_OWNER_RE = /^(?:#{NAME_RE}|#{OWNER_RE}\/#{NAME_RE})$/ NAME_WITH_OWNER_RE = /^(?:#{NAME_RE}|#{OWNER_RE}\/#{NAME_RE})$/
CUSTOM_COMMANDS = %w[alias create browse compare fork pull-request] CUSTOM_COMMANDS = %w[alias create browse compare fork pull-request ci-status]
def run(args) def run(args)
slurp_global_flags(args) slurp_global_flags(args)
@ -1165,6 +1240,34 @@ module Hub
abort "fatal: #{err.message}" abort "fatal: #{err.message}"
end end
def ci_status(args)
args.shift
ref = args.words.first || 'HEAD'
unless head_project = local_repo.current_project
abort "Aborted: the origin remote doesn't point to a GitHub repository."
end
unless sha = local_repo.git_command("rev-parse -q #{ref}")
abort "Aborted: no revision could be determined from '#{ref}'"
end
statuses = api_client.statuses(head_project, sha)
status = statuses.first
ref_state = status ? status['state'] : 'no status'
exit_code = case ref_state
when 'success' then 0
when 'failure', 'error' then 1
when 'pending' then 2
else 3
end
$stdout.puts ref_state
exit exit_code
end
def pull_request(args) def pull_request(args)
args.shift args.shift
options = { } options = { }
@ -1172,6 +1275,10 @@ module Hub
base_project = local_repo.main_project base_project = local_repo.main_project
head_project = local_repo.current_project head_project = local_repo.current_project
unless current_branch
abort "Aborted: not currently on any branch."
end
unless base_project unless base_project
abort "Aborted: the origin remote doesn't point to a GitHub repository." abort "Aborted: the origin remote doesn't point to a GitHub repository."
end end
@ -1188,6 +1295,13 @@ module Hub
case arg case arg
when '-f' when '-f'
force = true force = true
when '-F', '--file'
file = args.shift
text = file == '-' ? $stdin.read : File.read(file)
options[:title], options[:body] = read_msg(text)
when '-m', '--message'
text = args.shift
options[:title], options[:body] = read_msg(text)
when '-b' when '-b'
base_project, options[:base] = from_github_ref.call(args.shift, base_project) base_project, options[:base] = from_github_ref.call(args.shift, base_project)
when '-h' when '-h'
@ -1200,7 +1314,10 @@ module Hub
if url = resolve_github_url(arg) and url.project_path =~ /^issues\/(\d+)/ if url = resolve_github_url(arg) and url.project_path =~ /^issues\/(\d+)/
options[:issue] = $1 options[:issue] = $1
base_project = url.project base_project = url.project
elsif !options[:title] then options[:title] = arg elsif !options[:title]
options[:title] = arg
warn "hub: Specifying pull request title without a flag is deprecated."
warn "Please use one of `-m' or `-F' options."
else else
abort "invalid argument: #{arg}" abort "invalid argument: #{arg}"
end end
@ -1258,8 +1375,9 @@ module Hub
[format, base_branch, remote_branch] [format, base_branch, remote_branch]
end end
options[:title], options[:body] = pullrequest_editmsg(commit_summary) { |msg| options[:title], options[:body] = pullrequest_editmsg(commit_summary) { |msg, initial_message|
msg.puts default_message if default_message initial_message ||= default_message
msg.puts initial_message if initial_message
msg.puts "" msg.puts ""
msg.puts "# Requesting a pull to #{base_project.owner}:#{options[:base]} from #{options[:head]}" msg.puts "# Requesting a pull to #{base_project.owner}:#{options[:base]} from #{options[:head]}"
msg.puts "#" msg.puts "#"
@ -1273,13 +1391,20 @@ module Hub
args.executable = 'echo' args.executable = 'echo'
args.replace [pull['html_url']] args.replace [pull['html_url']]
rescue GitHubAPI::Exceptions rescue GitHubAPI::Exceptions
display_api_exception("creating pull request", $!.response) response = $!.response
display_api_exception("creating pull request", response)
if 404 == response.status
base_url = base_project.web_url.split('://', 2).last
warn "Are you sure that #{base_url} exists?"
end
exit 1 exit 1
else
delete_editmsg
end end
def clone(args) def clone(args)
ssh = args.delete('-p') ssh = args.delete('-p')
has_values = /^(--(upload-pack|template|depth|origin|branch|reference)|-[ubo])$/ has_values = /^(--(upload-pack|template|depth|origin|branch|reference|name)|-[ubo])$/
idx = 1 idx = 1
while idx < args.length while idx < args.length
@ -1304,17 +1429,7 @@ module Hub
return unless index = args.index('add') return unless index = args.index('add')
args.delete_at index args.delete_at index
branch = args.index('-b') || args.index('--branch')
if branch
args.delete_at branch
branch_name = args.delete_at branch
end
clone(args) clone(args)
if branch_name
args.insert branch, '-b', branch_name
end
args.insert index, 'add' args.insert index, 'add'
end end
@ -1359,7 +1474,7 @@ module Hub
end end
projects = names.map { |name| projects = names.map { |name|
unless name =~ /\W/ or remotes.include?(name) or remotes_group(name) unless name !~ /^#{OWNER_RE}$/ or remotes.include?(name) or remotes_group(name)
project = github_project(nil, name) project = github_project(nil, name)
repo_info = api_client.repo_info(project) repo_info = api_client.repo_info(project)
if repo_info.success? if repo_info.success?
@ -1454,7 +1569,7 @@ module Hub
url = url.sub(%r{(/pull/\d+)/\w*$}, '\1') unless gist url = url.sub(%r{(/pull/\d+)/\w*$}, '\1') unless gist
ext = gist ? '.txt' : '.patch' ext = gist ? '.txt' : '.patch'
url += ext unless File.extname(url) == ext url += ext unless File.extname(url) == ext
patch_file = File.join(ENV['TMPDIR'] || '/tmp', "#{gist ? 'gist-' : ''}#{File.basename(url)}") patch_file = File.join(tmp_dir, "#{gist ? 'gist-' : ''}#{File.basename(url)}")
args.before 'curl', ['-#LA', "hub #{Hub::Version}", url, '-o', patch_file] args.before 'curl', ['-#LA', "hub #{Hub::Version}", url, '-o', patch_file]
args[idx] = patch_file args[idx] = patch_file
end end
@ -1476,9 +1591,14 @@ module Hub
end end
forked_project = project.owned_by(github_user(project.host)) forked_project = project.owned_by(github_user(project.host))
if api_client.repo_exists?(forked_project) existing_repo = api_client.repo_info(forked_project)
if existing_repo.success?
parent_data = existing_repo.data['parent']
parent_url = parent_data && resolve_github_url(parent_data['html_url'])
if !parent_url or parent_url.project != project
abort "Error creating fork: %s already exists on %s" % abort "Error creating fork: %s already exists on %s" %
[ forked_project.name_with_owner, forked_project.host ] [ forked_project.name_with_owner, forked_project.host ]
end
else else
api_client.fork_repo(project) unless args.noop? api_client.fork_repo(project) unless args.noop?
end end
@ -1528,7 +1648,10 @@ module Hub
action = "set remote origin" action = "set remote origin"
else else
action = "created repository" action = "created repository"
api_client.create_repo(new_project, options) unless args.noop? unless args.noop?
repo_data = api_client.create_repo(new_project, options)
new_project = github_project(repo_data['full_name'])
end
end end
url = new_project.git_url(:private => true, :https => https_protocol?) url = new_project.git_url(:private => true, :https => https_protocol?)
@ -1579,11 +1702,12 @@ module Hub
abort "Usage: hub browse [<USER>/]<REPOSITORY>" unless project abort "Usage: hub browse [<USER>/]<REPOSITORY>" unless project
require 'cgi'
path = case subpage = args.shift path = case subpage = args.shift
when 'commits' when 'commits'
"/commits/#{branch.short_name}" "/commits/#{branch_in_url(branch)}"
when 'tree', NilClass when 'tree', NilClass
"/tree/#{branch.short_name}" if branch and !branch.master? "/tree/#{branch_in_url(branch)}" if branch and !branch.master?
else else
"/#{subpage}" "/#{subpage}"
end end
@ -1604,7 +1728,7 @@ module Hub
abort "Usage: hub compare [USER] [<START>...]<END>" abort "Usage: hub compare [USER] [<START>...]<END>"
end end
else else
sha_or_tag = /(\w{1,2}|\w[\w.-]+\w)/ sha_or_tag = /((?:#{OWNER_RE}:)?\w[\w.-]+\w)/
range = args.pop.sub(/^#{sha_or_tag}\.\.#{sha_or_tag}$/, '\1...\2') range = args.pop.sub(/^#{sha_or_tag}\.\.#{sha_or_tag}$/, '\1...\2')
project = if owner = args.pop then github_project(nil, owner) project = if owner = args.pop then github_project(nil, owner)
else current_project else current_project
@ -1642,11 +1766,6 @@ module Hub
if script if script
puts "alias git=hub" puts "alias git=hub"
if 'zsh' == shell
puts "if type compdef >/dev/null; then"
puts " compdef hub=git"
puts "fi"
end
else else
profile = case shell profile = case shell
when 'bash' then '~/.bash_profile' when 'bash' then '~/.bash_profile'
@ -1672,25 +1791,35 @@ module Hub
def help(args) def help(args)
command = args.words[1] command = args.words[1]
if command == 'hub' if command == 'hub' || custom_command?(command)
puts hub_manpage puts hub_manpage
exit exit
elsif command.nil? && !args.has_flag?('-a', '--all') elsif command.nil?
if args.has_flag?('-a', '--all')
args.after 'echo', ["\nhub custom commands\n"]
args.after 'echo', CUSTOM_COMMANDS.map {|cmd| " #{cmd}" }
else
ENV['GIT_PAGER'] = '' unless args.has_flag?('-p', '--paginate') # Use `cat`. ENV['GIT_PAGER'] = '' unless args.has_flag?('-p', '--paginate') # Use `cat`.
puts improved_help_text puts improved_help_text
exit exit
end end
end end
end
alias_method "--help", :help alias_method "--help", :help
private private
def branch_in_url(branch)
require 'cgi'
CGI.escape(branch.short_name).gsub("%2F", "/")
end
def api_client def api_client
@api_client ||= begin @api_client ||= begin
config_file = ENV['HUB_CONFIG'] || '~/.config/hub' config_file = ENV['HUB_CONFIG'] || '~/.config/hub'
file_store = GitHubAPI::FileStore.new File.expand_path(config_file) file_store = GitHubAPI::FileStore.new File.expand_path(config_file)
file_config = GitHubAPI::Configuration.new file_store file_config = GitHubAPI::Configuration.new file_store
GitHubAPI.new file_config, :app_url => 'http://defunkt.io/hub/' GitHubAPI.new file_config, :app_url => 'http://github.github.com/hub/'
end end
end end
@ -1768,6 +1897,7 @@ GitHub Commands:
create Create this repository on GitHub and add GitHub as origin create Create this repository on GitHub and add GitHub as origin
browse Open a GitHub page in the default browser browse Open a GitHub page in the default browser
compare Open a compare page on GitHub compare Open a compare page on GitHub
ci-status Show the CI status of a commit
See 'git help <command>' for more information on a specific command. See 'git help <command>' for more information on a specific command.
help help
@ -1859,7 +1989,8 @@ help
Kernel.select [STDIN] Kernel.select [STDIN]
pager = ENV['GIT_PAGER'] || pager = ENV['GIT_PAGER'] ||
`git config --get-all core.pager`.split.first || ENV['PAGER'] || `git config --get-all core.pager`.split("\n").first ||
ENV['PAGER'] ||
'less -isr' 'less -isr'
pager = 'cat' if pager.empty? pager = 'cat' if pager.empty?
@ -1871,27 +2002,53 @@ help
read.close read.close
write.close write.close
end end
rescue NotImplementedError
end end
def pullrequest_editmsg(changes) def pullrequest_editmsg(changes)
message_file = File.join(git_dir, 'PULLREQ_EDITMSG') message_file = pullrequest_editmsg_file
if valid_editmsg_file?(message_file)
title, body = read_editmsg(message_file)
previous_message = [title, body].compact.join("\n\n") if title
end
File.open(message_file, 'w') { |msg| File.open(message_file, 'w') { |msg|
yield msg yield msg, previous_message
if changes if changes
msg.puts "#\n# Changes:\n#" msg.puts "#\n# Changes:\n#"
msg.puts changes.gsub(/^/, '# ').gsub(/ +$/, '') msg.puts changes.gsub(/^/, '# ').gsub(/ +$/, '')
end end
} }
edit_cmd = Array(git_editor).dup edit_cmd = Array(git_editor).dup
edit_cmd << '-c' << 'set ft=gitcommit' if edit_cmd[0] =~ /^[mg]?vim$/ edit_cmd << '-c' << 'set ft=gitcommit tw=0 wrap lbr' if edit_cmd[0] =~ /^[mg]?vim$/
edit_cmd << message_file edit_cmd << message_file
system(*edit_cmd) system(*edit_cmd)
abort "can't open text editor for pull request message" unless $?.success?
unless $?.success?
delete_editmsg(message_file)
abort "error using text editor for pull request message"
end
title, body = read_editmsg(message_file) title, body = read_editmsg(message_file)
abort "Aborting due to empty pull request title" unless title abort "Aborting due to empty pull request title" unless title
[title, body] [title, body]
end end
def valid_editmsg_file?(message_file)
File.exists?(message_file) &&
File.mtime(message_file) > File.mtime(__FILE__)
end
def read_msg(message)
message.split("\n\n", 2).each {|s| s.strip! }.reject {|s| s.empty? }
end
def pullrequest_editmsg_file
File.join(git_dir, 'PULLREQ_EDITMSG')
end
def read_editmsg(file) def read_editmsg(file)
title, body = '', '' title, body = '', ''
File.open(file, 'r') { |msg| File.open(file, 'r') { |msg|
@ -1907,6 +2064,10 @@ help
[title =~ /\S/ ? title : nil, body =~ /\S/ ? body : nil] [title =~ /\S/ ? title : nil, body =~ /\S/ ? body : nil]
end end
def delete_editmsg(file = pullrequest_editmsg_file)
File.delete(file) if File.exist?(file)
end
def expand_alias(cmd) def expand_alias(cmd)
if expanded = git_alias_for(cmd) if expanded = git_alias_for(cmd)
if expanded.index('!') != 0 if expanded.index('!') != 0
@ -1963,16 +2124,11 @@ module Hub
if args.noop? if args.noop?
puts commands puts commands
elsif not args.skip? elsif not args.skip?
if args.chained? execute_command_chain args.commands
execute_command_chain
else
exec(*args.to_exec)
end
end end
end end
def execute_command_chain def execute_command_chain commands
commands = args.commands
commands.each_with_index do |cmd, i| commands.each_with_index do |cmd, i|
if cmd.respond_to?(:call) then cmd.call if cmd.respond_to?(:call) then cmd.call
elsif i == commands.length - 1 elsif i == commands.length - 1
@ -1982,6 +2138,14 @@ module Hub
end end
end end
end end
def exec *args
if args.first == 'echo' && Context::windows?
puts args[1..-1].join(' ')
else
super
end
end
end end
end end
@ -1991,7 +2155,7 @@ __END__
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3
. .
.TH "HUB" "1" "May 2012" "DEFUNKT" "Git Manual" .TH "HUB" "1" "July 2013" "GITHUB" "Git Manual"
. .
.SH "NAME" .SH "NAME"
\fBhub\fR \- git + hub = github \fBhub\fR \- git + hub = github
@ -2051,7 +2215,10 @@ __END__
\fBgit fork\fR [\fB\-\-no\-remote\fR] \fBgit fork\fR [\fB\-\-no\-remote\fR]
. .
.br .br
\fBgit pull\-request\fR [\fB\-f\fR] [\fITITLE\fR|\fB\-i\fR \fIISSUE\fR] [\fB\-b\fR \fIBASE\fR] [\fB\-h\fR \fIHEAD\fR] \fBgit pull\-request\fR [\fB\-f\fR] [\fB\-m\fR \fIMESSAGE\fR|\fB\-F\fR \fIFILE\fR|\fB\-i\fR \fIISSUE\fR|\fIISSUE\-URL\fR] [\fB\-b\fR \fIBASE\fR] [\fB\-h\fR \fIHEAD\fR]
.
.br
\fBgit ci\-status\fR [\fICOMMIT\fR]
. .
.SH "DESCRIPTION" .SH "DESCRIPTION"
hub enhances various git commands to ease most common workflows with GitHub\. hub enhances various git commands to ease most common workflows with GitHub\.
@ -2121,30 +2288,40 @@ Create a new public GitHub repository from the current git repository and add re
. .
.TP .TP
\fBgit browse\fR [\fB\-u\fR] [[\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR] [SUBPAGE] \fBgit browse\fR [\fB\-u\fR] [[\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR] [SUBPAGE]
Open repository\'s GitHub page in the system\'s default web browser using \fBopen(1)\fR or the \fBBROWSER\fR env variable\. If the repository isn\'t specified, \fBbrowse\fR opens the page of the repository found in the current directory\. If SUBPAGE is specified, the browser will open on the specified subpage: one of "wiki", "commits", "issues" or other (the default is "tree")\. Open repository\'s GitHub page in the system\'s default web browser using \fBopen(1)\fR or the \fBBROWSER\fR env variable\. If the repository isn\'t specified, \fBbrowse\fR opens the page of the repository found in the current directory\. If SUBPAGE is specified, the browser will open on the specified subpage: one of "wiki", "commits", "issues" or other (the default is "tree")\. With \fB\-u\fR, outputs the URL rather than opening the browser\.
. .
.TP .TP
\fBgit compare\fR [\fB\-u\fR] [\fIUSER\fR] [\fISTART\fR\.\.\.]\fIEND\fR \fBgit compare\fR [\fB\-u\fR] [\fIUSER\fR] [\fISTART\fR\.\.\.]\fIEND\fR
Open a GitHub compare view page in the system\'s default web browser\. \fISTART\fR to \fIEND\fR are branch names, tag names, or commit SHA1s specifying the range of history to compare\. If a range with two dots (\fBa\.\.b\fR) is given, it will be transformed into one with three dots\. If \fISTART\fR is omitted, GitHub will compare against the base branch (the default is "master")\. Open a GitHub compare view page in the system\'s default web browser\. \fISTART\fR to \fIEND\fR are branch names, tag names, or commit SHA1s specifying the range of history to compare\. If a range with two dots (\fBa\.\.b\fR) is given, it will be transformed into one with three dots\. If \fISTART\fR is omitted, GitHub will compare against the base branch (the default is "master")\. With \fB\-u\fR, outputs the URL rather than opening the browser\.
. .
.TP .TP
\fBgit fork\fR [\fB\-\-no\-remote\fR] \fBgit fork\fR [\fB\-\-no\-remote\fR]
Forks the original project (referenced by "origin" remote) on GitHub and adds a new remote for it under your username\. Forks the original project (referenced by "origin" remote) on GitHub and adds a new remote for it under your username\.
. .
.TP .TP
\fBgit pull\-request\fR [\fB\-f\fR] [\fITITLE\fR|\fB\-i\fR \fIISSUE\fR|\fIISSUE\-URL\fR] [\fB\-b\fR \fIBASE\fR] [\fB\-h\fR \fIHEAD\fR] \fBgit pull\-request\fR [\fB\-f\fR] [\fB\-m\fR \fIMESSAGE\fR|\fB\-F\fR \fIFILE\fR|\fB\-i\fR \fIISSUE\fR|\fIISSUE\-URL\fR] [\fB\-b\fR \fIBASE\fR] [\fB\-h\fR \fIHEAD\fR]
Opens a pull request on GitHub for the project that the "origin" remote points to\. The default head of the pull request is the current branch\. Both base and head of the pull request can be explicitly given in one of the following formats: "branch", "owner:branch", "owner/repo:branch"\. This command will abort operation if it detects that the current topic branch has local commits that are not yet pushed to its upstream branch on the remote\. To skip this check, use \fB\-f\fR\. Opens a pull request on GitHub for the project that the "origin" remote points to\. The default head of the pull request is the current branch\. Both base and head of the pull request can be explicitly given in one of the following formats: "branch", "owner:branch", "owner/repo:branch"\. This command will abort operation if it detects that the current topic branch has local commits that are not yet pushed to its upstream branch on the remote\. To skip this check, use \fB\-f\fR\.
. .
.IP .IP
If \fITITLE\fR is omitted, a text editor will open in which title and body of the pull request can be entered in the same manner as git commit message\. Without \fIMESSAGE\fR or \fIFILE\fR, a text editor will open in which title and body of the pull request can be entered in the same manner as git commit message\. Pull request message can also be passed via stdin with \fB\-F \-\fR\.
. .
.IP .IP
If instead of normal \fITITLE\fR an issue number is given with \fB\-i\fR, the pull request will be attached to an existing GitHub issue\. Alternatively, instead of title you can paste a full URL to an issue on GitHub\. If instead of normal \fITITLE\fR an issue number is given with \fB\-i\fR, the pull request will be attached to an existing GitHub issue\. Alternatively, instead of title you can paste a full URL to an issue on GitHub\.
. .
.TP
\fBgit ci\-status\fR [\fICOMMIT\fR]
Looks up the SHA for \fICOMMIT\fR in GitHub Status API and displays the latest status\. Exits with one of:
.
.br
success (0), error (1), failure (1), pending (2), no status (3)
.
.SH "CONFIGURATION" .SH "CONFIGURATION"
Hub will prompt for GitHub username & password the first time it needs to access the API and exchange it for an OAuth token, which it saves in "~/\.config/hub"\. Hub will prompt for GitHub username & password the first time it needs to access the API and exchange it for an OAuth token, which it saves in "~/\.config/hub"\.
. .
.P .P
To avoid being prompted, use \fIGITHUB_USER\fR and \fIGITHUB_PASSWORD\fR environment variables\.
.
.P
If you prefer the HTTPS protocol for GitHub repositories, you can set "hub\.protocol" to "https"\. This will affect \fBclone\fR, \fBfork\fR, \fBremote add\fR and other operations that expand references to GitHub repositories as full URLs that otherwise use git and ssh protocols\. If you prefer the HTTPS protocol for GitHub repositories, you can set "hub\.protocol" to "https"\. This will affect \fBclone\fR, \fBfork\fR, \fBremote add\fR and other operations that expand references to GitHub repositories as full URLs that otherwise use git and ssh protocols\.
. .
.IP "" 4 .IP "" 4
@ -2286,7 +2463,7 @@ $ git pull\-request
[ opened pull request on GitHub for "YOUR_USER:feature" ] [ opened pull request on GitHub for "YOUR_USER:feature" ]
# explicit title, pull base & head: # explicit title, pull base & head:
$ git pull\-request "I\'ve implemented feature X" \-b defunkt:master \-h mislav:feature $ git pull\-request \-m "Implemented feature X" \-b defunkt:master \-h mislav:feature
$ git pull\-request \-i 123 $ git pull\-request \-i 123
[ attached pull request to issue #123 ] [ attached pull request to issue #123 ]
@ -2412,8 +2589,18 @@ $ hub submodule add wycats/bundler vendor/bundler
$ hub submodule add \-p wycats/bundler vendor/bundler $ hub submodule add \-p wycats/bundler vendor/bundler
> git submodule add git@github\.com:wycats/bundler\.git vendor/bundler > git submodule add git@github\.com:wycats/bundler\.git vendor/bundler
$ hub submodule add \-b ryppl ryppl/pip vendor/pip $ hub submodule add \-b ryppl \-\-name pip ryppl/pip vendor/pip
> git submodule add \-b ryppl git://github\.com/ryppl/pip\.git vendor/pip > git submodule add \-b ryppl \-\-name pip git://github\.com/ryppl/pip\.git vendor/pip
.
.fi
.
.SS "git ci\-status"
.
.nf
$ hub ci\-status [commit]
> (prints CI state of commit and exits with appropriate code)
> One of: success (0), error (1), failure (1), pending (2), no status (3)
. .
.fi .fi
. .
@ -2429,10 +2616,10 @@ $ git help hub
.fi .fi
. .
.SH "BUGS" .SH "BUGS"
\fIhttps://github\.com/defunkt/hub/issues\fR \fIhttps://github\.com/github/hub/issues\fR
. .
.SH "AUTHORS" .SH "AUTHORS"
\fIhttps://github\.com/defunkt/hub/contributors\fR \fIhttps://github\.com/github/hub/contributors\fR
. .
.SH "SEE ALSO" .SH "SEE ALSO"
git(1), git\-clone(1), git\-remote(1), git\-init(1), \fIhttp://github\.com\fR, \fIhttps://github\.com/defunkt/hub\fR git(1), git\-clone(1), git\-remote(1), git\-init(1), \fIhttp://github\.com\fR, \fIhttps://github\.com/github/hub\fR