Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added some kickass network commands that use the network graph api

uses git-cherry now so it can ignore rebases and cherry-picks
updated the unit tests to run properly
  • Loading branch information...
commit 269ad8475ae041e43f328738825f4bee63131009 1 parent 9e11c44
@schacon schacon authored
View
4 Rakefile
@@ -4,12 +4,12 @@ require 'rake'
begin
require 'echoe'
- Echoe.new('github', '0.1.4') do |p|
+ Echoe.new('github', '0.2.0') do |p|
p.rubyforge_name = 'github'
p.summary = "The official `github` command line helper for simplifying your GitHub experience."
p.description = "The official `github` command line helper for simplifying your GitHub experience."
p.url = "http://github.com/"
- p.author = ['Chris Wanstrath', 'Kevin Ballard']
+ p.author = ['Chris Wanstrath', 'Kevin Ballard', 'Scott Chacon']
p.email = "chris@ozmm.org"
# p.dependencies = ["launchy"]
end
View
62 commands/commands.rb
@@ -20,12 +20,58 @@
end
end
-desc "Open the network page for this repo in a web browser."
-command :network do |user|
- if helper.project
- user ||= helper.owner
+desc "Project network tools - sub-commands : web [user], list, fetch, commits [user]"
+command :network do |command, user|
+ return if !helper.project
+ user ||= helper.owner
+
+ case command
+ when 'web'
helper.open helper.network_page_for(user)
+ when 'list'
+ data = get_network_data(user)
+ data['users'].each do |hsh|
+ puts [ hsh['name'].ljust(20), hsh['heads'].map {|a| a['name']}.uniq.join(', ') ].join(' ')
+ end
+ when 'fetch'
+ # fetch each remote we don't have
+ data = get_network_data(user)
+ data['users'].each do |hsh|
+ u = hsh['name']
+ GitHub.invoke(:track, u) unless helper.tracking?(u)
+ puts "fetching #{u}"
+ GitHub.invoke(:fetch_all, u)
+ end
+ when 'commits'
+ # show commits we don't have yet
+ # !! check that our heads are the same as the remote heads (multi-masters?)
+ ids = []
+ data = get_network_data(user)
+ data['users'].each do |hsh|
+ u = hsh['name']
+ ids += hsh['heads'].map { |a| a['id'] }
+ end
+ ids.uniq!
+
+ local_heads = helper.local_heads
+ local_heads_not = local_heads.map { |a| "^#{a}"}
+ looking_for = (ids - local_heads) + local_heads_not
+ commits = helper.get_commits(looking_for)
+
+ cherry = []
+ ids.each do |id|
+ cherry += helper.get_cherry(id)
+ end
+ if cherry.size > 0
+ helper.print_network_cherry_help
+ helper.print_commits(cherry, commits)
+ else
+ puts "no unapplied commits"
+ end
+ else
+ puts 'please provide a command'
end
+
end
desc "Info about this project."
@@ -61,6 +107,12 @@
end
end
+desc "Fetch all refs from a user"
+command :fetch_all do |user|
+ GitHub.invoke(:track, user) unless helper.tracking?(user)
+ git "fetch #{user}"
+end
+
desc "Fetch from a remote to a local branch."
command :fetch do |user, branch|
die "Specify a user to pull from" if user.nil?
@@ -69,7 +121,7 @@
GitHub.invoke(:track, user) unless helper.tracking?(user)
git "fetch #{user} #{branch}:refs/remotes/#{user}/#{branch}"
- git_exec "checkout -b #{user}/#{branch} refs/remotes/#{user}/#{branch}"
+ git_exec "checkout -b #{user}/#{branch} refs/remotes/#{user}/#{branch}"
end
desc "Pull from a remote."
View
48 commands/helpers.rb
@@ -34,6 +34,35 @@
`git config --get remote.#{remote}.url`.chomp
end
+helper :local_heads do
+ `git show-ref --heads --hash`.split("\n")
+end
+
+helper :get_commits do |rev_array|
+ list = rev_array.join(' ')
+ `git log --pretty=format:"%H::%ae::%s" --no-merges #{list}`.split("\n").map { |a| a.split('::') }
+end
+
+helper :get_cherry do |branch|
+ `git cherry HEAD #{branch} | git name-rev --stdin`.split("\n").map { |a| a.split(' ') }
+end
+
+helper :print_commits do |cherries, commits|
+ cherries.sort! { |a, b| a[2] <=> b[2] }
+ shown_commits = {}
+ cherries.each do |cherry|
+ status, sha, ref_name = cherry
+ next if shown_commits[sha]
+ ref_name = ref_name.gsub('remotes/', '')
+ commit = commits.assoc(sha)
+ if status == '+' && commit
+ puts [sha[0,6], ref_name.ljust(25), commit[1][0,20].ljust(21), commit[2][0, 36]].join(" ")
+ end
+ shown_commits[sha] = true
+ end
+ puts
+end
+
helper :remotes do
regexp = '^remote\.(.+)\.url$'
`git config --get-regexp '#{regexp}'`.split(/\n/).inject({}) do |memo, line|
@@ -105,6 +134,11 @@
"https://github.com/#{user}/#{project}/network"
end
+helper :network_meta_for do |user|
+ "http://github.com/#{user}/#{project}/network_meta"
+end
+
+
helper :has_launchy? do |blk|
begin
gem 'launchy'
@@ -121,3 +155,17 @@
}
end
+helper :print_network_cherry_help do
+ puts "
+=========================================================================================
+These are all the commits that other people have pushed that you have not
+applied or ignored yet. (see 'github ignore')
+
+* You can run 'github fetch user/branch' to pull one into a local branch for testing
+* You can run 'git cherry-pick [SHA]' to apply a single patch
+* Or, you can run 'git merge user/branch' to merge a commit and everything underneath it.
+=========================================================================================
+
+"
+end
+
View
2  lib/github.rb
@@ -3,6 +3,8 @@
require 'github/command'
require 'github/helper'
require 'rubygems'
+require 'open-uri'
+require 'json'
##
# Starting simple.
View
5 lib/github/command.rb
@@ -47,6 +47,11 @@ def sh(*command)
Shell.new(*command).run
end
+ def get_network_data(user)
+ puts "gathering metadata from github...\n\n"
+ data = JSON.parse(open(helper.network_meta_for(user)).read)
+ end
+
def die(message)
puts "=> #{message}"
exit!
View
4 spec/ui_spec.rb
@@ -49,14 +49,14 @@
# -- network --
specify "network should open the network page for this repo" do
- running :network do
+ running :network, 'web' do
setup_url_for
@helper.should_receive(:open).once.with("https://github.com/user/project/network")
end
end
specify "network defunkt should open the network page for defunkt's fork" do
- running :network, "defunkt" do
+ running :network, 'web', "defunkt" do
setup_url_for
@helper.should_receive(:open).once.with("https://github.com/defunkt/project/network")
end
Please sign in to comment.
Something went wrong with that request. Please try again.