Permalink
Browse files

Added confirmation for branch to base feature branch off of

  • Loading branch information...
1 parent 328cade commit 315a5b7e4dd889c200f76b16a0d51a1daa464f86 @winton committed Jan 20, 2012
Showing with 53 additions and 32 deletions.
  1. +6 −3 README.md
  2. +5 −1 features/gitcycle.feature
  3. +42 −28 lib/gitcycle.rb
View
@@ -99,7 +99,10 @@ This will add a "pass" label to the issue and will complete the pull request by
Todo
----
+* Make ticket active when starting branch
* Label issues with ticket milestone?
-* Add confirmation when creating new dev branch for branch that it is based off of
- * If confirmation is a no, allow user to specify branch to base off of
-* bug with branch rename on Jimmy's machine
+* Bug with branch rename on Jimmy's machine
+* Need to pull before merging qa pass branch
+* Check for conflict wherever merge happens
+* Instead of detecting CONFLICT, use error status $? != 0
+* Add comment on lighthouse with issue URL
@@ -21,10 +21,12 @@ Scenario: Feature branch w/ custom branch name
And a new Lighthouse ticket
When I cd to the user repo
And I execute gitcycle with the Lighthouse ticket URL
+ And I enter "y"
And I enter "n"
And I enter "ticket.id-rename"
Then gitcycle runs
And output includes "Retrieving branch information from gitcycle."
+ And output includes "Your work will eventually merge into 'master'. Is this correct?"
And output includes "Would you like to name your branch 'ticket.id'?"
And output includes "What would you like to name your branch?"
And output includes "Creating 'ticket.id-rename' from 'master'."
@@ -39,8 +41,10 @@ Scenario: Feature branch
When I cd to the user repo
And I execute gitcycle with the Lighthouse ticket URL
And I enter "y"
+ And I enter "y"
Then gitcycle runs
And output includes "Retrieving branch information from gitcycle."
+ And output includes "Your work will eventually merge into 'master'. Is this correct?"
And output includes "Would you like to name your branch 'ticket.id'?"
And output does not include "What would you like to name your branch?"
And output includes "Creating 'ticket.id' from 'master'."
@@ -86,7 +90,7 @@ Scenario: Pull changes from upstream
Then gitcycle runs
And output includes "Retrieving branch information from gitcycle."
And output includes "Adding remote repo 'config.owner/config.repo'."
- And output includes "Fetching remote branch 'master'."
+ And output includes "Fetching remote repo 'config.owner'."
And output includes "Merging remote branch 'master' from 'config.owner/config.repo'."
And git log should contain the last commit
View
@@ -56,18 +56,21 @@ def create_branch(url_or_title)
branch = get('branch', params)
name = branch['name']
+ owner, repo = branch['repo'].split(':')
unless branch['exists']
branch['home'] = @git_login
branch['source'] = branches(:current => true)
- # unless yes?("Would you like to eventually merge this feature into #{branch['source']}?")
- # branch['source'] = q("What branch would you like to eventually merge this feature into?")
- # end
+ unless yes?("Your work will eventually merge into '#{branch['source']}'. Is this correct?")
+ branch['source'] = q("What branch would you like to eventually merge into?")
+ end
- # unless branches(:match => branch['source'])
-
- # end
+ checkout_remote_branch(
+ :owner => owner,
+ :repo => repo,
+ :branch => branch['source']
+ )
unless yes?("Would you like to name your branch '#{name}'?")
name = q("\nWhat would you like to name your branch?")
@@ -329,6 +332,23 @@ def start(args=[])
private
+ def add_remote_and_fetch(options={})
+ owner = options[:owner]
+ repo = options[:repo]
+
+ $remotes ||= {}
+
+ unless $remotes[owner]
+ $remotes[owner] = true
+ puts "Adding remote repo '#{owner}/#{repo}'.\n".green
+ run("git remote rm #{owner}") if remotes(:match => owner)
+ run("git remote add #{owner} git@github.com:#{owner}/#{repo}.git")
+ end
+
+ puts "\nFetching remote repo '#{owner}'.\n".green
+ run("git fetch #{owner}")
+ end
+
def branches(options={})
b = `git branch#{" -a" if options[:all]}`
if options[:current]
@@ -345,20 +365,22 @@ def checkout_remote_branch(options={})
repo = options[:repo]
branch = options[:branch]
- $remotes ||= {}
+ add_remote_and_fetch(options)
+
+ puts "\nChecking out remote branch '#{branch}' from '#{owner}/#{repo}'.\n".green
- unless $remotes[owner]
- $remotes[owner] = true
- puts "Adding remote repo '#{owner}/#{repo}'.\n".green
- run("git remote rm #{owner}") if remotes(:match => owner)
- run("git remote add #{owner} git@github.com:#{owner}/#{repo}.git")
+ if branches(:match => branch)
+ run("git checkout #{branch}")
+ else
+ run("git checkout -b #{branch} #{owner}/#{branch}")
end
-
- puts "\nFetching remote branch '#{branch}'.\n".green
- run("git fetch #{owner}")
- puts "\nMerging remote branch '#{branch}' from '#{owner}/#{repo}'.\n".green
- run("git merge #{owner}/#{branch}")
+ if branches(:current => true) == branch
+ run("git pull #{owner} #{branch}")
+ else
+ puts "Oops. Something bad happened.\n".red
+ exit
+ end
end
def create_pull_request
@@ -408,6 +430,8 @@ def create_qa_branch(options)
run("git fetch && git checkout -b #{source} origin/#{source}")
end
+ run("git pull origin #{source}")
+
if branches(:match => name, :all => true)
puts "Deleting old QA branch '#{name}'.\n".green
run("git branch -D #{name}")
@@ -507,17 +531,7 @@ def merge_remote_branch(options={})
repo = options[:repo]
branch = options[:branch]
- $remotes ||= {}
-
- unless $remotes[owner]
- $remotes[owner] = true
- puts "Adding remote repo '#{owner}/#{repo}'.\n".green
- run("git remote rm #{owner}") if remotes(:match => owner)
- run("git remote add #{owner} git@github.com:#{owner}/#{repo}.git")
- end
-
- puts "\nFetching remote branch '#{branch}'.\n".green
- run("git fetch #{owner}")
+ add_remote_and_fetch(options)
puts "\nMerging remote branch '#{branch}' from '#{owner}/#{repo}'.\n".green
run("git merge #{owner}/#{branch}")

0 comments on commit 315a5b7

Please sign in to comment.