git-scripts 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/README.md +0 -15
  2. data/bin/feature +70 -15
  3. data/bin/hotfix +78 -23
  4. data/completion/_feature +38 -0
  5. data/completion/_hotfix +28 -0
  6. data/{bash_completion.sh → completion/bash_completion.sh} +2 -2
  7. data/lib/git.rb +59 -13
  8. data/lib/github.rb +15 -9
  9. data/lib/helpers.rb +20 -11
  10. data/man/feature-finish-issue.1 +22 -0
  11. data/man/feature-finish-issue.1.ronn +26 -0
  12. data/man/feature-finish.1 +4 -4
  13. data/man/feature-finish.1.html +7 -12
  14. data/man/feature-finish.1.ronn +6 -5
  15. data/man/feature-list.1 +8 -2
  16. data/man/feature-list.1.html +11 -9
  17. data/man/feature-list.1.ronn +6 -1
  18. data/man/feature-merge.1.html +4 -9
  19. data/man/feature-switch.1 +3 -3
  20. data/man/feature-switch.1.html +6 -10
  21. data/man/feature-switch.1.ronn +3 -1
  22. data/man/{feature-github-test.1.html → feature-url.1.html} +9 -15
  23. data/man/feature.1.html +3 -7
  24. data/man/hotfix-finish-issue.1 +22 -0
  25. data/man/hotfix-finish-issue.1.ronn +26 -0
  26. data/man/hotfix-finish.1 +2 -2
  27. data/man/hotfix-finish.1.ronn +1 -1
  28. data/man/hotfix-list.1 +8 -2
  29. data/man/hotfix-list.1.html +11 -9
  30. data/man/hotfix-list.1.ronn +6 -1
  31. data/man/hotfix-merge.1.html +4 -9
  32. data/man/hotfix-switch.1 +3 -3
  33. data/man/hotfix-switch.1.ronn +3 -1
  34. data/man/{hotfix-start.1.html → hotfix-url.1.html} +9 -15
  35. data/man/hotfix.1.html +2 -7
  36. metadata +13 -28
  37. data/man/feature-clean.1.html +0 -120
  38. data/man/feature-clean.1.markdown +0 -58
  39. data/man/feature-finish.1.markdown +0 -52
  40. data/man/feature-github-test.1.markdown +0 -50
  41. data/man/feature-list.1.markdown +0 -51
  42. data/man/feature-merge.1.markdown +0 -55
  43. data/man/feature-start.1.html +0 -110
  44. data/man/feature-start.1.markdown +0 -50
  45. data/man/feature-stashes.1.html +0 -122
  46. data/man/feature-stashes.1.markdown +0 -60
  47. data/man/feature-status.1.html +0 -113
  48. data/man/feature-status.1.markdown +0 -53
  49. data/man/feature-switch.1.markdown +0 -56
  50. data/man/feature.1.markdown +0 -75
  51. data/man/feature.html +0 -140
  52. data/man/hotfix-finish.1.html +0 -112
  53. data/man/hotfix-finish.1.markdown +0 -52
  54. data/man/hotfix-list.1.markdown +0 -51
  55. data/man/hotfix-merge.1.markdown +0 -55
  56. data/man/hotfix-start.1.markdown +0 -50
  57. data/man/hotfix-switch.1.html +0 -110
  58. data/man/hotfix-switch.1.markdown +0 -50
  59. data/man/hotfix.1.markdown +0 -65
data/README.md CHANGED
@@ -124,18 +124,3 @@ Merges the hotfix branch back into `stable` with `--no-ff`. Also does a
124
124
  merge back into `master`.
125
125
 
126
126
  [gitflow]: http://nvie.com/posts/a-successful-git-branching-model/
127
-
128
- ## Hacking
129
-
130
- We (obviously) use the same method on this repo as the tools contained within
131
- encourage. Unfortunately, `feature finish` will create a pull request within
132
- your own forked repo. Thus, if you do not have write privileges to this
133
- repository, you have to create the pull request manually - bummer.
134
-
135
- Please include any necessary changes to the documentation. The man files are
136
- written in [ronn], so the only manual change you need make are to the
137
- man/*.ronn files. After you've done that, run `rake man` to generate the HTML
138
- and roff files.
139
-
140
- [ronn]: http://rtomayko.github.io/ronn/ronn-format.7.html
141
-
data/bin/feature CHANGED
@@ -8,6 +8,12 @@ command=ARGV.first
8
8
 
9
9
  $0 = ARGV.join(" ")
10
10
 
11
+ unless command == '--help' or command == '-h'
12
+ unless Git::in_a_repo
13
+ die("\nSwitch to a git repo. If you need help, use --help or -h.")
14
+ end
15
+ end
16
+
11
17
  case command
12
18
  when 'github-test'
13
19
  octokit = Github::api
@@ -99,20 +105,70 @@ when 'finish'
99
105
  puts "Successfully created pull-request ##{response[:number]}"
100
106
  puts " " + response[:html_url]
101
107
 
108
+ when 'finish-issue'
109
+ require_argument(:feature, :'finish-issue')
110
+ issue = ARGV[1]
111
+ feature = Git::current_branch
112
+ # Push commits to origin
113
+ Git::run_safe(["git push origin #{feature}:#{feature}"])
114
+
115
+ exit 1 unless confirm("Convert issue ##{issue} into a pull-request using " +
116
+ "feature branch named '#{feature}' ?")
117
+ octokit = Github::api
118
+
119
+ pull = octokit.create_pull_request_for_issue(
120
+ Github::get_github_repo,
121
+ Git::development_branch,
122
+ feature,
123
+ issue
124
+ )
125
+
126
+ # We've converted the issue to a pull request, now lets change the
127
+ # description to include the last commit message and prompt the user to
128
+ # confirm it.
129
+
130
+ last_commit_message = Git::commit_message(feature)
131
+
132
+ original_title = pull[:title].gsub("\r","")
133
+ original_body = pull[:body].gsub("\r","")
134
+
135
+ initial_message = <<-MESSAGE
136
+ #{last_commit_message}
137
+
138
+ ----
139
+
140
+ Original issue: #{original_title}
141
+ ----
142
+
143
+ #{original_body}
144
+ MESSAGE
145
+
146
+ description = Github::open_title_body_editor(initial_message)
147
+
148
+ updated_pull = octokit.update_pull_request(
149
+ Github::get_github_repo,
150
+ issue,
151
+ description[:title],
152
+ description[:body]
153
+ )
154
+
155
+ puts "Successfully converted issue ##{issue} to a pull-request"
156
+ puts " " + updated_pull[:html_url]
157
+
102
158
  when 'merge'
103
159
  dev_branch = Git::development_branch
104
160
  fail_on_local_changes
105
161
 
106
- Git::run_safe(["git fetch"])
107
-
108
162
  feature = ARGV[1] || Git::current_branch
109
163
 
110
164
  exit 1 unless confirm("Merge feature branch named: '#{feature}' ?")
111
165
 
112
166
  description = Github::get_pull_request_description_from_api(feature, dev_branch)
167
+ update = Git::submodules_update("get")
113
168
 
114
- # Checkout the branch first to make sure we have it locally.
115
169
  Git::run_safe([
170
+ "git fetch",
171
+ # Checkout the branch first to make sure we have it locally.
116
172
  "git checkout \"#{feature}\"",
117
173
  "git rebase --preserve-merges origin/#{feature}",
118
174
  # pull the latest changes from master
@@ -121,19 +177,12 @@ when 'merge'
121
177
  "git rebase --preserve-merges origin/#{dev_branch}",
122
178
  # merge the feature branch into master
123
179
  "git merge --no-ff --edit -m #{description.shellescape} \"#{feature}\"",
180
+ # init any submodules in the master branch
181
+ "#{update}",
182
+ # delete the local feature-branch
183
+ "git branch -d \"#{feature}\""
124
184
  ])
125
185
 
126
- # init any submodules in the master branch
127
- Git::submodules_update
128
-
129
- # delete the local feature-branch
130
- Git::run_safe(["git branch -d \"#{feature}\""])
131
-
132
- # delete the remote branch we'll leave this off for now
133
- # Git::run_safe("git push origin :\"#{feature}\"")
134
- # push the the merge to our origin
135
- # Git::run_safe("git push origin")
136
-
137
186
  puts
138
187
  puts "Successfully merged feature-branch: #{feature} into #{dev_branch}"
139
188
  puts "If you are satisfied with the result, do this:\n" + <<CMDS
@@ -141,9 +190,15 @@ when 'merge'
141
190
  CMDS
142
191
 
143
192
  when 'switch'
144
- require_argument(:feature, :switch, min=2, max=3)
193
+
194
+ require_argument(:feature, :switch, min=2, max=4)
195
+
145
196
  feature = ARGV[1]
146
197
 
198
+ if ARGV[1] == '-n'
199
+ feature = get_branch_name_from_number(ARGV[2])
200
+ end
201
+
147
202
  Git::switch_branch(feature)
148
203
 
149
204
  when 'prune'
data/bin/hotfix CHANGED
@@ -8,6 +8,12 @@ command=ARGV.first
8
8
 
9
9
  $0 = ARGV.join(" ")
10
10
 
11
+ unless command == '--help' or command == '-h'
12
+ unless Git::in_a_repo
13
+ die("\nSwitch to a git repo. If you need help, use --help or -h.")
14
+ end
15
+ end
16
+
11
17
  case command
12
18
  when 'start'
13
19
  require_argument(:hotfix, :start)
@@ -63,6 +69,57 @@ when 'finish'
63
69
  puts "Successfully created pull-request ##{response[:number]}"
64
70
  puts " " + response[:html_url]
65
71
 
72
+ when 'finish-issue'
73
+ require_argument(:hotfix, :'finish-issue')
74
+ issue = ARGV[1]
75
+ hotfix = Git::current_branch
76
+
77
+ # Push commits to origin
78
+ Git::run_safe(["git push origin #{hotfix}:#{hotfix}"])
79
+
80
+ exit 1 unless confirm("Convert issue ##{issue} into a pull-request using " +
81
+ "hotfix branch named '#{hotfix}' ?")
82
+ octokit = Github::api
83
+
84
+ pull = octokit.create_pull_request_for_issue(
85
+ Github::get_github_repo,
86
+ 'stable',
87
+ hotfix,
88
+ issue
89
+ )
90
+
91
+ # We've converted the issue to a pull request, now lets change the
92
+ # description to include the last commit message and prompt the user to
93
+ # confirm it.
94
+
95
+ last_commit_message = Git::commit_message(hotfix)
96
+
97
+ original_title = pull[:title].gsub("\r","")
98
+ original_body = pull[:body].gsub("\r","")
99
+
100
+ initial_message = <<-MESSAGE
101
+ #{last_commit_message}
102
+
103
+ ----
104
+
105
+ Original issue: #{original_title}
106
+ ----
107
+
108
+ #{original_body}
109
+ MESSAGE
110
+
111
+ description = Github::open_title_body_editor(initial_message)
112
+
113
+ updated_pull = octokit.update_pull_request(
114
+ Github::get_github_repo,
115
+ issue,
116
+ description[:title],
117
+ description[:body]
118
+ )
119
+
120
+ puts "Successfully converted issue ##{issue} to a pull-request"
121
+ puts " " + updated_pull[:html_url]
122
+
66
123
  when 'merge'
67
124
  fail_on_local_changes
68
125
  dev_branch = Git::development_branch
@@ -73,40 +130,38 @@ when 'merge'
73
130
  exit 1 unless confirm("Merge hotfix named: '#{hotfix}' ?")
74
131
 
75
132
  description = Github::get_pull_request_description_from_api(hotfix, 'stable')
76
- descriptionDev = Github::get_pull_request_description_from_api(hotfix, dev_branch)
77
- # init any submodules in the stable branch
133
+
134
+ commit_message = Git::get_description_from_user(description)
135
+ # The first instance of stable should be in the pull request title.
136
+ dev_commit_message = commit_message.sub('stable', dev_branch)
137
+
138
+ # Get command to init any submodules in the stable branch.
78
139
  update = Git::submodules_update("get")
79
140
 
80
141
  Git::run_safe([
81
142
  # Checkout the branch to make sure we have it locally.
82
- "git checkout \"#{hotfix}\"",
83
- "git rebase --preserve-merges origin/#{hotfix}",
84
- # Merge into stable
143
+ "git checkout #{hotfix.shellescape}",
144
+ "git rebase --preserve-merges origin/#{hotfix.shellescape}",
145
+ # Merge into stable.
85
146
  "git checkout stable",
86
- # pull the latest changes and rebase the unpushed commits if any.
147
+ # Pull the latest changes and rebase the unpushed commits if any.
87
148
  "git rebase --preserve-merges origin/stable",
88
- # merge the hotfix branch into stable
89
- "git merge --no-ff --edit -m #{description.shellescape} \"#{hotfix}\"",
149
+ # Merge the hotfix branch into stable.
150
+ "git merge --no-ff --no-edit -m #{commit_message.shellescape} #{hotfix.shellescape}",
90
151
  "#{update}",
91
- # push the the merge to our origin
92
- # Git::run_safe("git push origin")
93
- # Merge into master
152
+ # Merge into master.
94
153
  "git checkout #{dev_branch}",
95
- # pull the latest changes and rebase the unpushed master commits if any.
154
+ # Pull the latest changes and rebase the unpushed master commits if any.
96
155
  "git rebase origin/#{dev_branch}",
97
- # merge the hotfix branch into master
98
- "git merge --no-ff --edit -m #{descriptionDev.shellescape} \"#{hotfix}\"",
99
- # init any submodules in the master branch. Note: no need to change
156
+ # Merge the hotfix branch into master.
157
+ "git merge --no-ff --no-edit -m #{dev_commit_message.shellescape} #{hotfix.shellescape}",
158
+ # Init any submodules in the master branch. Note: no need to change
100
159
  # directories before calling git submodule since we are already in the
101
- # projects top-level directory
160
+ # projects top-level directory.
102
161
  "#{update}",
103
- # push the the merge to our origin
104
- # Git::run_safe("git push origin")
105
- # delete the local hotfix branch
106
- "git branch -d \"#{hotfix}\"",
107
- # delete the remote hotfix branch -- we'll leave this off for now
108
- # Git::run_safe("git push origin :\"#{hotfix}\"")
109
- # checkout stable branch
162
+ # Delete the local hotfix branch.
163
+ "git branch -d #{hotfix.shellescape}",
164
+ # Checkout stable branch.
110
165
  "git checkout stable"
111
166
  ])
112
167
 
@@ -0,0 +1,38 @@
1
+ #compdef feature
2
+
3
+ _feature() {
4
+ local curcontext="$curcontext" state line
5
+ typeset -A opt_args
6
+
7
+ _arguments \
8
+ '1: :->commands'\
9
+ '2: :->params'\
10
+ '3: :->choice'
11
+
12
+ case $state in
13
+ commands)
14
+ _arguments '1:Commands:(list start switch finish finish-issue merge pull prune status stashes clean github-test)'
15
+ ;;
16
+ params)
17
+ if [[ "$words[2]" == "prune" ]]; then
18
+ _arguments '2:Location:(local origin)'
19
+ fi
20
+ if [[ "$words[2]" == "switch" ||
21
+ "$words[2]" == "merge" ||
22
+ "$words[2]" == "finish" ]]; then
23
+ local -a featureBranches args
24
+ featureBranches="$(git branch -a | tr -d ' *' | grep -v 'hotfix-' | sed 's|remotes/origin/||')"
25
+ args="$(echo ${featureBranches} | tr "\$\'\\n\'" " ")"
26
+ _arguments '2:Branches:($(echo ${args}))'
27
+ fi
28
+ ;;
29
+ choice)
30
+ if [[ "$words[3]" == "local" || "$words[3]" == "origin" ]]; then
31
+ _arguments '3:Commands:(preview clean)'
32
+ fi
33
+ ;;
34
+ *)
35
+ esac
36
+ }
37
+
38
+ _feature "$@"
@@ -0,0 +1,28 @@
1
+ #compdef hotfix
2
+
3
+ _hotfix() {
4
+ local curcontext="$curcontext" state line
5
+ typeset -A opt_args
6
+
7
+ _arguments \
8
+ '1: :->commands'\
9
+ '2: :->params'
10
+ case $state in
11
+ commands)
12
+ _arguments '1:Commands:(list start switch finish finish-issue merge)'
13
+ ;;
14
+ params)
15
+ if [[ "$words[2]" != 'list' ||
16
+ "$words[2]" != 'finish-issue' ]]; then
17
+ local -a hotfixBranches args
18
+ hotfixBranches="$(git branch -a | tr -d ' *' | grep 'hotfix-' | sed -e 's|remotes/origin/||' -e 's|hotfix-||')"
19
+
20
+ args="$(echo ${hotfixBranches} | tr "\$\'\\n\'" " ")"
21
+ _arguments '2:Branches:($(echo ${args}))'
22
+ fi
23
+ ;;
24
+ *)
25
+ esac
26
+ }
27
+
28
+ _hotfix "$@"
@@ -10,7 +10,7 @@ _git-scripts()
10
10
  case "$cmd" in
11
11
  feature)
12
12
  if [ "$line" = "$cmd $cur" ]; then
13
- words="switch start finish stashes list merge pull status clean"
13
+ words="switch start finish finish-issue stashes list merge pull status clean prune"
14
14
  else
15
15
  # get branch names minus hotfixes
16
16
  words="$(git branch -a | tr -d ' *' | grep -v 'hotfix-' | sed 's|remotes/origin/||')"
@@ -18,7 +18,7 @@ _git-scripts()
18
18
  ;;
19
19
  hotfix)
20
20
  if [ "$line" = "$cmd $cur" ]; then
21
- words="switch start finish merge list clean"
21
+ words="switch start finish finish-issue merge list clean"
22
22
  else
23
23
  # get hotfix branch names
24
24
  words="$(git branch -a | tr -d ' *' | grep 'hotfix-' | sed -e 's|remotes/origin/||' -e 's|hotfix-||')"
data/lib/git.rb CHANGED
@@ -4,18 +4,57 @@ module Git
4
4
  return !clean
5
5
  end
6
6
 
7
+ def self.in_a_repo
8
+ return system("git rev-parse")
9
+ end
10
+
7
11
  # Return the development branch specified by the
8
12
  # feature.development-branch git config value
9
13
  def self.development_branch
10
14
  dev_branch = `git config feature.development-branch`.strip
11
15
  if !dev_branch || $? != 0
12
- $stderr.puts "No development branch specified"
13
- $stderr.puts " set it with: git config feature.development-branch master"
14
- exit 1;
16
+ die("No development branch specified; set it with: " +
17
+ "git config feature.development-branch master")
15
18
  end
16
19
  dev_branch
17
20
  end
18
21
 
22
+ # Returns the editor specified in the user's gitconfig.
23
+ def self.editor
24
+ editor = `git var GIT_EDITOR`.strip
25
+ unless editor
26
+ abort "Configure an editor for git:\n" +
27
+ "git config --global core.editor vim"
28
+ end
29
+ return editor
30
+ end
31
+
32
+ # Starts an editor with a file. Returns a string with the contents of that
33
+ # file.
34
+ def self.get_description_from_user(initial_message = '')
35
+ require 'tempfile'
36
+ editor = self::editor
37
+
38
+ file = Tempfile.new('merge-msg')
39
+ file.print(initial_message)
40
+ file.flush
41
+
42
+ if editor == 'vim'
43
+ params = "'+set ft=gitcommit' '+set textwidth=72'" +
44
+ " '+setlocal spell spelllang=en_us'"
45
+ else
46
+ params = ''
47
+ end
48
+ pid = spawn("#{editor} #{params} #{file.path}")
49
+ Process.wait pid
50
+
51
+ file.rewind
52
+ commit = file.read
53
+ file.unlink
54
+
55
+ return commit
56
+ end
57
+
19
58
  # Returns an array of branches that aren't merged into the specified branch
20
59
  def self.branches_not_merged_into(branch)
21
60
  self::all_branches - self::merged_branches(branch)
@@ -27,6 +66,8 @@ module Git
27
66
  self.branches_not_merged_into('stable')
28
67
  elsif type == :merged
29
68
  self.merged_branches('stable')
69
+ else
70
+ raise ArgumentError, 'Must specify :merged or :unmerged in hotfix_branches.'
30
71
  end
31
72
 
32
73
  branches.select {|branch| branch.include?('hotfix-') }
@@ -34,10 +75,14 @@ module Git
34
75
 
35
76
  # Returns an array of unmerged feature branches
36
77
  def self.feature_branches(type)
78
+ devBranch = development_branch()
79
+
37
80
  branches = if type == :unmerged
38
- self.branches_not_merged_into('master')
81
+ self.branches_not_merged_into(devBranch)
39
82
  elsif type == :merged
40
- self.merged_branches('master')
83
+ self.merged_branches(devBranch)
84
+ else
85
+ raise ArgumentError, 'Must specify :merged or :unmerged in feature_branches.'
41
86
  end
42
87
 
43
88
  branches.reject {|branch| branch.include?('hotfix-') }
@@ -88,12 +133,12 @@ module Git
88
133
  while command = commands.shift
89
134
  puts "> " + command
90
135
  unless system(command)
91
- puts "\tFailed on \`#{command}\`"
92
- puts "\tWould have run:"
93
- commands.each do |a|
94
- puts "\t" + a
95
- exit
136
+ puts highlight("\n\tERROR: failed on \`#{command}\`.")
137
+ puts "\n\tWould have run:"
138
+ commands.each do |command|
139
+ puts "\t# " + command
96
140
  end
141
+ abort
97
142
  end
98
143
  end
99
144
  end
@@ -163,7 +208,7 @@ module Git
163
208
  ##
164
209
  # Switch to the specified branch.
165
210
  # Because we use submodules, we have to check for updates to those
166
- # submodules when we checkout a branch
211
+ # submodules when we checkout a branch.
167
212
  #
168
213
  # args: --clean - remove every unstaged file, including non-existant
169
214
  # submodules
@@ -177,9 +222,10 @@ module Git
177
222
  end
178
223
 
179
224
  ##
180
- # Update / initialize submodules from the TLD
225
+ # Update / initialize submodules from the TLD or return the command that
226
+ # would do so as a string.
181
227
  #
182
- def self.submodules_update(mode = nil)
228
+ def self.submodules_update(mode = "")
183
229
  # capture only the path, not the newline
184
230
  basedir = `git rev-parse --show-toplevel`.split("\n").first
185
231
  command = "cd #{basedir} && git submodule --quiet update --init --recursive"
data/lib/github.rb CHANGED
@@ -78,8 +78,7 @@ module Github
78
78
  system("git config --global github.token #{auth[:token]}")
79
79
 
80
80
  unless success
81
- puts "Couldn't set git config"
82
- exit
81
+ die("Couldn't set git config")
83
82
  end
84
83
 
85
84
  return {:login => username, :oauth_token => auth[:token]}
@@ -108,8 +107,6 @@ module Github
108
107
  # Returns a hash containing a :title and :body
109
108
  ##
110
109
  def self.get_pull_request_description(branch_name = nil)
111
- require 'tempfile'
112
-
113
110
  if branch_name
114
111
  initial_message = Git::commit_message(branch_name).gsub("\r","")
115
112
  else
@@ -120,8 +117,20 @@ Body of pull-request
120
117
  MESSAGE
121
118
  end
122
119
 
120
+ return self::open_title_body_editor(initial_message)
121
+ end
122
+
123
+ ##
124
+ # Prompts the user (using $EDITOR) to confirm the title and body
125
+ # in the provided message.
126
+ #
127
+ # Returns a hash containing a :title and :body
128
+ ##
129
+ def self.open_title_body_editor(message)
130
+ require 'tempfile'
131
+
123
132
  msg = Tempfile.new('pull-message')
124
- msg.write(initial_message)
133
+ msg.write(message)
125
134
  msg.close
126
135
 
127
136
  # -c blah only works for vim
@@ -181,10 +190,7 @@ class OctokitWrapper
181
190
  begin
182
191
  return @client.send(meth,*args)
183
192
  rescue Octokit::Error => e
184
- $stderr.puts "=" * 80
185
- $stderr.puts "Github API Error"
186
- $stderr.puts e
187
- exit(1)
193
+ die("=" * 80 + "\nGithub API Error\n" + e.to_s)
188
194
  end
189
195
  end
190
196
  end
data/lib/helpers.rb CHANGED
@@ -12,10 +12,11 @@ def display_feature_help(command = nil, message = nil)
12
12
  display_help(
13
13
  :script_name => "Git Feature Branch Helper",
14
14
  :commands => {
15
- :list => "feature list",
15
+ :list => "feature list [-v]",
16
16
  :start => "feature start name-of-feature",
17
- :switch => "feature switch name-of-feature [--clean]",
18
- :finish => "feature finish name-of-feature",
17
+ :switch => "feature switch (name-of-feature | -n number-of-feature) [--clean]",
18
+ :finish => "feature finish [name-of-feature]",
19
+ :'finish-issue' => "feature finish-issue issue-number",
19
20
  :merge => "feature merge [name-of-feature]",
20
21
  :pull => "feature pull",
21
22
  :prune => "feature prune <local | origin> <preview | clean>",
@@ -34,10 +35,11 @@ def display_hotfix_help(command = nil, message = nil)
34
35
  display_help(
35
36
  :script_name => "Git Hotfix Helper",
36
37
  :commands => {
37
- :list => "hotfix list",
38
+ :list => "hotfix list [-v]",
38
39
  :start => "hotfix start name-of-hotfix",
39
- :switch => "hotfix switch name-of-hotfix",
40
+ :switch => "hotfix switch (name-of-hotfix | -n number-of-hotfix)",
40
41
  :finish => "hotfix finish [name-of-hotfix]",
42
+ :'finish-issue' => "hotfix finish-issue issue-number",
41
43
  :merge => "hotfix merge [name-of-hotfix]"
42
44
  },
43
45
  :command_name => 'hotfix',
@@ -113,7 +115,7 @@ end
113
115
  def confirm(question)
114
116
  loop do
115
117
  print(question)
116
- print(" (y/n):")
118
+ print(" (y/n): ")
117
119
  STDOUT.flush
118
120
  s = STDIN.gets
119
121
  exit if s == nil
@@ -124,13 +126,18 @@ def confirm(question)
124
126
  end
125
127
  end
126
128
 
127
- def die(message = nil)
128
- puts wrap_text(message) if message
129
- exit 1
129
+ def die(message = '')
130
+ abort wrap_text(message)
130
131
  end
131
132
 
132
133
  def highlight(str)
133
- return HIGHLIGHT + str + HIGHLIGHT_OFF;
134
+ return HIGHLIGHT + str + HIGHLIGHT_OFF
135
+ end
136
+
137
+ def get_branch_name_from_number(num)
138
+ octokit = Github::api
139
+
140
+ return octokit.pull_request(Github::get_github_repo, num).head.ref
134
141
  end
135
142
 
136
143
  def hotfix_branch(name)
@@ -142,7 +149,9 @@ def hotfix_branch(name)
142
149
  end
143
150
 
144
151
  def current_hotfix_branch()
145
- if ARGV[1]
152
+ if ARGV[1] == '-n'
153
+ branch = get_branch_name_from_number(ARGV[2])
154
+ elsif ARGV[1]
146
155
  branch = hotfix_branch(ARGV[1])
147
156
  else
148
157
  branch = Git::current_branch
@@ -0,0 +1,22 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "FEATURE\-FINISH\-ISSUE" "1" "August 2013" "iFixit" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBfeature\-finish\-issue\fR \- Finish this feature branch and attach it to an issue\.
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBfeature finish\fR \fIissue\-number\fR
11
+ .
12
+ .SH "DESCRIPTION"
13
+ Finish the current feature branch and optionally convert an existing issue into a pull request\. The pull\'s description defaults to the commit message from the last commit on the branch with the issue\'s original title and description underneath\.
14
+ .
15
+ .SH "COPYRIGHT"
16
+ Copyright (c) 2012\-2013 iFixit\.
17
+ .
18
+ .SH "SEE ALSO"
19
+ feature(1), feature\-finish(1), hotfix\-finish(1), hotfix\-finish\-issue(1)
20
+ .
21
+ .SH "WWW"
22
+ https://github\.com/iFixit/git\-scripts
@@ -0,0 +1,26 @@
1
+ feature-finish-issue(1) - Finish this feature branch and attach it to an issue.
2
+ ===============================================
3
+
4
+ ## SYNOPSIS
5
+
6
+ `feature finish` <issue-number>
7
+
8
+ ## DESCRIPTION
9
+
10
+ Finish the current feature branch and optionally convert an existing issue
11
+ into a pull request. The pull's description defaults to the commit message
12
+ from the last commit on the branch with the issue's original title and
13
+ description underneath.
14
+
15
+ ## COPYRIGHT
16
+
17
+ Copyright (c) 2012-2013 iFixit.
18
+
19
+ ## SEE ALSO
20
+
21
+ feature(1), feature-finish(1), hotfix-finish(1), hotfix-finish-issue(1)
22
+
23
+ ## WWW
24
+
25
+ https://github.com/iFixit/git-scripts
26
+