Last active
August 29, 2015 14:02
-
-
Save NigelThorne/4cb00375e28e1b65c427 to your computer and use it in GitHub Desktop.
Git workflow using Stash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I added an alias to my git aliases in my .gitconfig | |
review-me = !sh -c 'cmd.exe /c \"@e:\\bin\\send_for_review.bat\"' | |
so I can type 'git review-me' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ruby %~dp0send_for_review.rb %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! ruby | |
# https://gist.github.com/NigelThorne/4cb00375e28e1b65c427 | |
if ARGV[0].nil? or ARGV.empty? | |
print "Please enter reviewer(s) initials:" | |
@reviewers = gets.chomp.split(/[\s,]/).reject{|s| s.empty?} | |
else | |
@reviewers = ARGV | |
end | |
if(/no stash in/ =~ `which stash 2>&1`) | |
puts "You need to run 'gem install atlassian-stash' " | |
puts "'atlassian-stash' needs DevTools installed." | |
puts "Download it, unpackit somewhere. (usually in a devtools folder under your ruby folder)." | |
puts "run devkitvars.bat in the CMD window you are running 'gem install' from." | |
exit(1) | |
end | |
## ensure all changes are committed and we are up to date | |
@status = `git status` | |
if !(/nothing to commit, working directory clean/ =~ @status ) | |
puts "There are unsaved change" | |
exit 1 | |
end | |
if /Your branch is ahead of/ =~ @status | |
puts "You need to push your dev changes to Stash" | |
exit 1 | |
end | |
## Capture the branch name | |
@full_branch_name = (@status.match(/On branch (.+)$/)||[])[1] | |
unless @branch | |
puts "This is not a dev branch" | |
exit 1 | |
end | |
# Push changes to Stash | |
unless /Branch #{@full_branch_name} set up to track remote branch #{@full_branch_name} from origin./=~ (err = `git push -u origin #{@full_branch_name} 2>&1`) | |
puts "Unable to push the branch to origin" | |
puts err | |
exit 1 | |
end | |
(err = `git fetch 2>&1`) | |
unless /\sorigin\/integration\r?\n/=~(err = `git branch --remote 2>&1`) | |
worked = !(/fatal:/ =~ (err = `git branch -f integration origin/master`)) | |
worked = /Branch integration set up to track remote branch integration from origin./ =~ (err = `git push --set-upstream origin integration 2>&1`) if worked | |
unless worked | |
puts "Remote integration branch was not able to be created... " | |
puts err | |
exit 1 | |
end | |
end | |
puts `stash pull-request #{@full_branch_name} integration @#{@reviewers.join(" ")} -o` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now creates integration branch if it's not there.