-
Notifications
You must be signed in to change notification settings - Fork 1
/
hotfix
executable file
·132 lines (106 loc) · 4.07 KB
/
hotfix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env ruby
require_relative '../lib/github.rb'
require_relative '../lib/git.rb'
require_relative '../lib/helpers.rb'
command=ARGV.first
BRANCH_PREFIX = "hotfix-"
case command
when 'start'
require_argument(:hotfix, :start)
hotfix = BRANCH_PREFIX + ARGV[1]
exit if !confirm("Create hotfix branch named: '#{hotfix}' ?")
Git::run_safe("git checkout stable")
Git::run_safe("git pull --rebase")
Git::run_safe("git branch \"#{hotfix}\" stable")
Git::run_safe("git checkout \"#{hotfix}\"")
Git::run_safe("git submodule --quiet update --init --recursive")
# Automatically setup remote tracking branch
Git::run_safe("git config branch.#{hotfix}.remote origin")
Git::run_safe("git config branch.#{hotfix}.merge refs/heads/#{hotfix}")
Git::run_safe("git config branch.#{hotfix}.rebase true")
when 'switch'
require_argument(:hotfix, :switch, min=2, max=3)
hotfix = BRANCH_PREFIX + ARGV[1]
Git::switch_branch(hotfix)
when 'finish'
hotfix = ARGV[1] || Git::current_branch
# ensure the hotfix name is the real branch name
if (!hotfix.start_with?("hotfix-"))
hotfix = "hotfix-" + hotfix
end
# Push commits to origin
Git::run_safe("git push origin #{hotfix}:#{hotfix}")
exit 1 if !confirm("Create a pull-request for hotfix branch named: '#{hotfix}' ?")
octokit = Github::api
description = Github::get_pull_request_description(hotfix)
puts "Pull-request description:"
puts description[:title]
puts "#"
puts description[:body]
response = octokit.create_pull_request(
Github::get_github_repo,
'stable',
hotfix,
description[:title],
description[:body]
)
puts "Successfully created pull-request ##{response[:number]}"
puts " " + response[:html_url]
when 'merge'
fail_on_local_changes
dev_branch = Git::development_branch
Git::run_safe("git fetch")
if ARGV[1]
hotfix = BRANCH_PREFIX + ARGV[1]
else
hotfix = Git::current_branch
end
exit 1 if !confirm("Merge hotfix named: '#{hotfix}' ?")
description = Github::get_pull_request_description_from_api(hotfix, 'stable')
# Checkout the branch to make sure we have it locally.
Git::run_safe("git checkout \"#{hotfix}\"")
Git::run_safe("git rebase --preserve-merges origin/#{hotfix}")
# Merge into stable
Git::run_safe("git checkout stable")
# pull the latest changes and rebase the unpushed commits if any.
Git::run_safe("git rebase --preserve-merges origin/stable")
# merge the hotfix branch into stable
Git::run_safe("git merge --no-ff --edit -m #{description.shellescape} \"#{hotfix}\"")
# init any submodules in the stable branch
Git::run_safe("git submodule --quiet update --init --recursive")
# push the the merge to our origin
# Git::run_safe("git push origin")
description = Github::get_pull_request_description_from_api(hotfix, dev_branch)
# Merge into master
Git::run_safe("git checkout #{dev_branch}")
# pull the latest changes and rebase the unpushed master commits if any.
Git::run_safe("git rebase origin/#{dev_branch}")
# merge the hotfix branch into master
Git::run_safe("git merge --no-ff --edit -m #{description.shellescape} \"#{hotfix}\"")
# init any submodules in the master branch
Git::run_safe("git submodule --quiet update --init --recursive")
# push the the merge to our origin
# Git::run_safe("git push origin")
# delete the local hotfix branch
Git::run_safe("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
Git::run_safe("git checkout stable")
puts "Successfully merged hotfix branch: #{hotfix} into stable and #{dev_branch}"
puts "If you are satisfied with the result, do this:\n" + <<CMDS
git push
git checkout #{dev_branch}
git push
CMDS
when 'list'
options = {
:hotfix => Git::hotfix_branches(:unmerged)
}
if ARGV.include?('-v')
options[:merged] = Git::hotfix_branches(:merged)
end
Git.show_branch_list(options)
else
display_hotfix_help
end