Skip to content

Commit

Permalink
Added confirmation for branch to base feature branch off of
Browse files Browse the repository at this point in the history
  • Loading branch information
winton committed Jan 20, 2012
1 parent 328cade commit 315a5b7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 32 deletions.
9 changes: 6 additions & 3 deletions README.md
Expand Up @@ -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
6 changes: 5 additions & 1 deletion features/gitcycle.feature
Expand Up @@ -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'."
Expand All @@ -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'."
Expand Down Expand Up @@ -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

Expand Down
70 changes: 42 additions & 28 deletions lib/gitcycle.rb
Expand Up @@ -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?")
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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}")
Expand Down

0 comments on commit 315a5b7

Please sign in to comment.