Skip to content

Commit 1ca369b

Browse files
committed
added git push and switch
1 parent 90eac0c commit 1ca369b

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

.ruby-gemset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
burnthis

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.0.0-p247

bin/code

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env ruby
2+
3+
$: << File.join(File.dirname(__FILE__), '..', 'lib') # while this is still in development
4+
25
require 'gli'
36
begin # XXX: Remove this begin/rescue before distributing your app
47
require 'code'
@@ -35,20 +38,33 @@ command :publish do |c|
3538
end
3639
end
3740

41+
desc "Push your current branch"
42+
command :push do |c|
43+
c.action do |global_options, options, args|
44+
$git.push $git.current_branch
45+
end
46+
end
47+
3848
desc 'Cleanup after a feature has been merged through GitHub'
3949
command :finish do |c|
4050
c.action do |global_options, options, args|
4151
$git.finish
4252
end
4353
end
4454

45-
desc 'Delete the branch you are working on switch back to development'
55+
desc 'Delete the branch you are working on and switch back to development'
4656
command :cancel do |c|
4757
c.action do |global_options, options, args|
4858
$git.cancel
4959
end
5060
end
5161

62+
command :switch do |c|
63+
c.action do |global_options, options, args|
64+
$git.switch(*args)
65+
end
66+
end
67+
5268
pre do |global, command, options, args|
5369
$git = Code::Git.new
5470
true

lib/code/git.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ def start(feature)
1414
checkout feature
1515
end
1616

17+
def switch(*patterns)
18+
branch = branch_matching *patterns
19+
checkout branch
20+
end
21+
22+
def branch_matching(*patterns)
23+
branches.find { |b| branch_matches? b, *patterns } or abort "No branch matching #{patterns.join ' '} exists"
24+
end
25+
26+
def branch_matches?(branch, *patterns)
27+
patterns.all? { |p| branch.include? p }
28+
end
29+
30+
def branches
31+
`git branch`.strip.lines.map { |line| line.gsub(/\s|\*/, '') }
32+
end
33+
1734
def cancel
1835
if on_main_branch?
1936
puts "Nothing to cancel (already on #{main_branch})"

0 commit comments

Comments
 (0)