git-review 0.6.7 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/git-review.rb +25 -2
  2. metadata +3 -3
@@ -92,7 +92,7 @@ class GitReview
92
92
  puts 'Merge command:'
93
93
  puts " git #{exec_cmd}"
94
94
  puts
95
- git(exec_cmd)
95
+ git exec_cmd
96
96
  end
97
97
 
98
98
  # Close a specified request.
@@ -105,7 +105,7 @@ class GitReview
105
105
  # Create a new request.
106
106
  # TODO: Support creating requests to other repositories and branches (like the original repo, this has been forked from).
107
107
  def create
108
- # TODO: Create and push to a remote branch if necessary.
108
+ prepare
109
109
  # Gather information.
110
110
  last_request_id = @pending_requests.collect{|req| req['number'] }.sort.last.to_i
111
111
  title = "[Review] Request from '#{github_login}' @ '#{source}'"
@@ -196,6 +196,29 @@ class GitReview
196
196
  end
197
197
  end
198
198
 
199
+ # Get local and remote branches ready to create a new request.
200
+ def prepare
201
+ # People should work on local branches, but especially for single commit changes,
202
+ # more often than not, they don't. Therefore we create a branch for them,
203
+ # to be able to use code review the way it is intended.
204
+ if source_branch == target_branch
205
+ # Unless a branch name is already provided, ask for one.
206
+ if (branch_name = @args.shift).nil?
207
+ puts 'Please provide a name for the branch:'
208
+ branch_name = gets.chomp.gsub(/\W+/, '_').downcase
209
+ end
210
+ # Create the new branch (as a copy of the current one).
211
+ git "checkout -b --track review_#{Time.now.strftime("%y%m%d")}_#{branch_name}"
212
+ # Go back to master and get rid of pending commits (as these are now on the new branch).
213
+ local_branch = source_branch
214
+ git "checkout #{target_branch}"
215
+ git "reset --hard origin/#{target_branch}"
216
+ git "checkout #{local_branch}"
217
+ end
218
+ # Push latest commits to the remote branch (and by that, create it if necessary).
219
+ git "push origin"
220
+ end
221
+
199
222
  # System call to 'git'.
200
223
  def git(command, chomp = true)
201
224
  s = `git #{command}`
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-review
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 6
9
8
  - 7
10
- version: 0.6.7
9
+ - 0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dominik Bamberger, Cristian Messel