Permalink
Browse files

Added a set of git tasks for our workflow

  • Loading branch information...
1 parent 1fe8955 commit 70ac0c1a3bbcfbb7c4359216839a288cc4cc4c22 @evanphx evanphx committed Oct 3, 2007
Showing with 77 additions and 0 deletions.
  1. +77 −0 rakelib/git.rake
View
@@ -0,0 +1,77 @@
+require 'readline'
+
+def git_branch
+ `git branch | grep "*"`.strip[2..-1]
+end
+
+namespace :git do
+ desc "Show the current status of the checkout"
+ task :status do
+ system "git status"
+ end
+
+ task :topic do
+ name = Readline.readline "Topic name: "
+ sh "git checkout -b #{name}"
+ end
+
+ task :push => :update do
+ branch = git_branch()
+ if branch != "master"
+ `git diff-files --quiet`
+ if $?.exitstatus == 1
+ puts "You have outstanding changes. Please commit them first."
+ exit 1
+ end
+
+ puts "* Merging topic '#{branch}' back into master..."
+ `git checkout master`
+ sh "git merge #{branch}"
+ switch = true
+ else
+ switch = false
+ end
+
+ puts "* Pushing changes..."
+ sh "git push"
+
+ if switch
+ puts "* Switching back to #{branch}..."
+ `git checkout #{branch}`
+ end
+ end
+
+ task :update do
+ `git diff-files --quiet`
+ if $?.exitstatus == 1
+ stash = true
+ puts "* Saving changes..."
+ `git stash save`
+ else
+ stash = false
+ end
+
+ branch = git_branch()
+ if branch != "master"
+ switch = true
+ `git checkout master`
+ puts "* Switching back to master..."
+ else
+ switch = false
+ end
+
+ puts "* Pulling in new commits..."
+ sh "git pull"
+
+ if switch
+ puts "* Porting changes into #{branch}..."
+ `git checkout #{branch}`
+ sh "git rebase master"
+ end
+
+ if stash
+ puts "* Applying changes..."
+ sh "git stash apply"
+ end
+ end
+end

0 comments on commit 70ac0c1

Please sign in to comment.