Skip to content

Commit

Permalink
Merge branch 'master' into url-command
Browse files Browse the repository at this point in the history
Conflicts:
	completion/_feature
	completion/_hotfix
	completion/bash_completion.sh
	lib/github.rb
  • Loading branch information
Robin Choudhury committed Sep 20, 2013
2 parents 8400b96 + a86a12a commit 4b069ea
Show file tree
Hide file tree
Showing 21 changed files with 379 additions and 97 deletions.
88 changes: 71 additions & 17 deletions bin/feature
Expand Up @@ -10,7 +10,7 @@ $0 = ARGV.join(" ")

unless command == '--help' or command == '-h'
unless Git::in_a_repo
die("\nSwitch to a git repo.")
die("\nSwitch to a git repo. If you need help, use --help or -h.")
end
end

Expand Down Expand Up @@ -105,41 +105,95 @@ when 'finish'
puts "Successfully created pull-request ##{response[:number]}"
puts " " + response[:html_url]

when 'finish-issue'
require_argument(:feature, :'finish-issue')
issue = ARGV[1]
feature = Git::current_branch
# Push commits to origin
Git::run_safe(["git push origin #{feature}:#{feature}"])

exit 1 unless confirm("Convert issue ##{issue} into a pull-request using " +
"feature branch named '#{feature}' ?")
octokit = Github::api

pull = octokit.create_pull_request_for_issue(
Github::get_github_repo,
Git::development_branch,
feature,
issue
)

# We've converted the issue to a pull request, now lets change the
# description to include the last commit message and prompt the user to
# confirm it.

last_commit_message = Git::commit_message(feature)

original_title = pull[:title].gsub("\r","")
original_body = pull[:body].gsub("\r","")

initial_message = <<-MESSAGE
#{last_commit_message}
----
Original issue: #{original_title}
----
#{original_body}
MESSAGE

description = Github::open_title_body_editor(initial_message)

updated_pull = octokit.update_pull_request(
Github::get_github_repo,
issue,
description[:title],
description[:body]
)

puts "Successfully converted issue ##{issue} to a pull-request"
puts " " + updated_pull[:html_url]

when 'merge'
dev_branch = Git::development_branch
fail_on_local_changes

Git::run_safe(["git fetch"])
if ARGV[1] == '-n'
feature = get_branch_name_from_number(ARGV[2])
else
feature = ARGV[1] || Git::current_branch
end

feature = ARGV[1] || Git::current_branch

pull_info = Github::get_pull_request_info_from_api(feature, dev_branch)

warning = Github::get_commit_status_warning(pull_info[:status])
unless warning.empty?
puts highlight(warning)
end

exit 1 unless confirm("Merge feature branch named: '#{feature}' ?")

description = Github::get_pull_request_description_from_api(feature, dev_branch)
update = Git::submodules_update("get")

# Checkout the branch first to make sure we have it locally.
Git::run_safe([
"git fetch",
# Checkout the branch first to make sure we have it locally.
"git checkout \"#{feature}\"",
"git rebase --preserve-merges origin/#{feature}",
# pull the latest changes from master
"git checkout #{dev_branch}",
# rebase the unpushed master commits if any.
"git rebase --preserve-merges origin/#{dev_branch}",
# merge the feature branch into master
"git merge --no-ff --edit -m #{description.shellescape} \"#{feature}\"",
"git merge --no-ff --edit -m #{pull_info[:description].shellescape} \"#{feature}\"",
# init any submodules in the master branch
"#{update}",
# delete the local feature-branch
"git branch -d \"#{feature}\""
])

# init any submodules in the master branch
Git::submodules_update

# delete the local feature-branch
Git::run_safe(["git branch -d \"#{feature}\""])

# delete the remote branch we'll leave this off for now
# Git::run_safe("git push origin :\"#{feature}\"")
# push the the merge to our origin
# Git::run_safe("git push origin")

puts
puts "Successfully merged feature-branch: #{feature} into #{dev_branch}"
puts "If you are satisfied with the result, do this:\n" + <<CMDS
Expand Down
111 changes: 84 additions & 27 deletions bin/hotfix
Expand Up @@ -10,7 +10,7 @@ $0 = ARGV.join(" ")

unless command == '--help' or command == '-h'
unless Git::in_a_repo
die("\nSwitch to a git repo.")
die("\nSwitch to a git repo. If you need help, use --help or -h.")
end
end

Expand Down Expand Up @@ -82,50 +82,107 @@ when 'finish'
puts "Successfully created pull-request ##{response[:number]}"
puts " " + response[:html_url]

when 'finish-issue'
require_argument(:hotfix, :'finish-issue')
issue = ARGV[1]
hotfix = Git::current_branch

# Push commits to origin
Git::run_safe(["git push origin #{hotfix}:#{hotfix}"])

exit 1 unless confirm("Convert issue ##{issue} into a pull-request using " +
"hotfix branch named '#{hotfix}' ?")
octokit = Github::api

pull = octokit.create_pull_request_for_issue(
Github::get_github_repo,
'stable',
hotfix,
issue
)

# We've converted the issue to a pull request, now lets change the
# description to include the last commit message and prompt the user to
# confirm it.

last_commit_message = Git::commit_message(hotfix)

original_title = pull[:title].gsub("\r","")
original_body = pull[:body].gsub("\r","")

initial_message = <<-MESSAGE
#{last_commit_message}
----
Original issue: #{original_title}
----
#{original_body}
MESSAGE

description = Github::open_title_body_editor(initial_message)

updated_pull = octokit.update_pull_request(
Github::get_github_repo,
issue,
description[:title],
description[:body]
)

puts "Successfully converted issue ##{issue} to a pull-request"
puts " " + updated_pull[:html_url]

when 'merge'
fail_on_local_changes
dev_branch = Git::development_branch
hotfix = current_hotfix_branch

if ARGV[1] == '-n'
hotfix = get_branch_name_from_number(ARGV[2])
else
hotfix = ARGV[1] || Git::current_branch
end

Git::run_safe(["git fetch"])

pull_info = Github::get_pull_request_info_from_api(hotfix, 'stable')

warning = Github::get_commit_status_warning(pull_info[:status])
unless warning.empty?
puts highlight(warning)
end

exit 1 unless confirm("Merge hotfix named: '#{hotfix}' ?")

description = Github::get_pull_request_description_from_api(hotfix, 'stable')
descriptionDev = Github::get_pull_request_description_from_api(hotfix, dev_branch)
# init any submodules in the stable branch
commit_message = Git::get_description_from_user(pull_info[:description])
commit_message_dev = commit_message.sub('stable', dev_branch)

update = Git::submodules_update("get")

Git::run_safe([
# Checkout the branch to make sure we have it locally.
"git checkout \"#{hotfix}\"",
"git rebase --preserve-merges origin/#{hotfix}",
# Merge into stable
"git checkout #{hotfix.shellescape}",
"git rebase --preserve-merges origin/#{hotfix.shellescape}",
# Merge into stable.
"git checkout stable",
# pull the latest changes and rebase the unpushed commits if any.
# Pull the latest changes and rebase the unpushed commits if any.
"git rebase --preserve-merges origin/stable",
# merge the hotfix branch into stable
"git merge --no-ff --edit -m #{description.shellescape} \"#{hotfix}\"",
# Merge the hotfix branch into stable.
"git merge --no-ff --no-edit -m #{commit_message.shellescape} \"#{hotfix}\"",
"#{update}",
# push the the merge to our origin
# Git::run_safe("git push origin")
# Merge into master
# Merge into master.
"git checkout #{dev_branch}",
# pull the latest changes and rebase the unpushed master commits if any.
# Pull the latest changes and rebase the unpushed master commits if any.
"git rebase origin/#{dev_branch}",
# merge the hotfix branch into master
"git merge --no-ff --edit -m #{descriptionDev.shellescape} \"#{hotfix}\"",
# init any submodules in the master branch. Note: no need to change
# directories before calling git submodule since we are already in the
# projects top-level directory
# Merge the hotfix branch into master.
"git merge --no-ff --no-edit -m #{commit_message_dev.shellescape} \"#{hotfix}\"",
# Init any submodules in the master branch. Note: no need to change.
# Directories before calling git submodule since we are already in the
# projects top-level directory.
"#{update}",
# push the the merge to our origin
# Git::run_safe("git push origin")
# delete the local hotfix branch
"git branch -d \"#{hotfix}\"",
# delete the remote hotfix branch -- we'll leave this off for now
# Git::run_safe("git push origin :\"#{hotfix}\"")
# checkout stable branch
# Delete the local hotfix branch.
"git branch -d #{hotfix.shellescape}",
# Checkout stable branch.
"git checkout stable"
])

Expand Down
2 changes: 1 addition & 1 deletion completion/_feature
Expand Up @@ -11,7 +11,7 @@ _feature() {

case $state in
commands)
_arguments '1:Commands:(list start switch url finish merge pull prune status stashes clean github-test)'
_arguments '1:Commands:(list start switch finish finish-issue merge pull prune status stashes clean github-test url)'
;;
params)
if [[ "$words[2]" == "prune" ]]; then
Expand Down
5 changes: 3 additions & 2 deletions completion/_hotfix
Expand Up @@ -9,10 +9,11 @@ _hotfix() {
'2: :->params'
case $state in
commands)
_arguments '1:Commands:(list start switch url finish merge)'
_arguments '1:Commands:(list start switch finish finish-issue merge)'
;;
params)
if [[ "$words[2]" != list ]]; then
if [[ "$words[2]" != 'list' ||
"$words[2]" != 'finish-issue' ]]; then
local -a hotfixBranches args
hotfixBranches="$(git branch -a | tr -d ' *' | grep 'hotfix-' | sed -e 's|remotes/origin/||' -e 's|hotfix-||')"

Expand Down
4 changes: 2 additions & 2 deletions completion/bash_completion.sh
Expand Up @@ -10,15 +10,15 @@ _git-scripts()
case "$cmd" in
feature)
if [ "$line" = "$cmd $cur" ]; then
words="switch start finish stashes list merge pull status clean prune url"
words="switch start finish finish-issue stashes list merge pull status clean prune url"
else
# get branch names minus hotfixes
words="$(git branch -a | tr -d ' *' | grep -v 'hotfix-' | sed 's|remotes/origin/||')"
fi
;;
hotfix)
if [ "$line" = "$cmd $cur" ]; then
words="switch start finish merge list clean url"
words="switch start finish finish-issue merge list clean url"
else
# get hotfix branch names
words="$(git branch -a | tr -d ' *' | grep 'hotfix-' | sed -e 's|remotes/origin/||' -e 's|hotfix-||')"
Expand Down
9 changes: 5 additions & 4 deletions git-scripts.gemspec
Expand Up @@ -3,17 +3,18 @@

Gem::Specification.new do |s|
s.name = 'git-scripts'
s.version = '0.2.0'
s.version = '0.3.0'
s.date = Time.now.strftime('%Y-%m-%d')

s.authors = ['Daniel Beardsley', 'James Pearson', 'Tim Asp']
s.email = ['daniel@ifixit.com', 'james@ifixit.com', 'tim@ifixit.com']
s.authors = ['Daniel Beardsley', 'James Pearson', 'Tim Asp', 'Robin Choudhury']
s.email = ['daniel@ifixit.com', 'james@ifixit.com', 'tim@ifixit.com', 'robin@ifixit.com']

s.add_dependency 'bundler'
s.add_dependency 'octokit', '~> 1.22.0'
s.add_dependency 'highline'

s.files = %w( COPYING Rakefile README.md bash_completion.sh )
s.files = %w( COPYING Rakefile README.md )
s.files += Dir.glob 'completion/*'
s.files += Dir.glob 'bin/*'
s.files += Dir.glob 'lib/*'
s.files += Dir.glob 'man/*'
Expand Down

0 comments on commit 4b069ea

Please sign in to comment.