git-review 0.7.3 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/git-review.rb +34 -29
  2. metadata +4 -4
@@ -100,10 +100,39 @@ class GitReview
100
100
  puts 'Successfully closed request.' unless request_exists?(@pending_request['number'])
101
101
  end
102
102
 
103
+ # Prepare local repository to create a new request.
104
+ # Sets @local_branch.
105
+ def prepare
106
+ # People should work on local branches, but especially for single commit changes,
107
+ # more often than not, they don't. Therefore we create a branch for them,
108
+ # to be able to use code review the way it is intended.
109
+ if source_branch == target_branch
110
+ # Unless a branch name is already provided, ask for one.
111
+ if (branch_name = @args.shift).nil?
112
+ puts 'Please provide a name for the branch:'
113
+ branch_name = gets.chomp.gsub(/\W+/, '_').downcase
114
+ end
115
+ # Create the new branch (as a copy of the current one).
116
+ @local_branch = "review_#{Time.now.strftime("%y%m%d")}_#{branch_name}"
117
+ git_call "checkout -b #{@local_branch}"
118
+ if source_branch == @local_branch
119
+ # Go back to master and get rid of pending commits (as these are now on the new branch).
120
+ git_call "checkout #{target_branch}"
121
+ git_call "reset --hard origin/#{target_branch}"
122
+ git_call "checkout #{@local_branch}"
123
+ end
124
+ else
125
+ @local_branch = source_branch
126
+ end
127
+ end
128
+
103
129
  # Create a new request.
104
130
  # TODO: Support creating requests to other repositories and branches (like the original repo, this has been forked from).
105
131
  def create
132
+ # Prepare @local_branch.
106
133
  prepare
134
+ # Push latest commits to the remote branch (and by that, create it if necessary).
135
+ git_call "push --set-upstream origin #{@local_branch}"
107
136
  # Gather information.
108
137
  last_request_id = @pending_requests.collect{|req| req['number'] }.sort.last.to_i
109
138
  title = "[Review] Request from '#{git_config['github.login']}' @ '#{source}'"
@@ -160,6 +189,7 @@ class GitReview
160
189
  puts ' checkout <number> Checkout a specified request\'s changes to your local repository.'
161
190
  puts ' merge <number> Accept a specified request by merging it into master.'
162
191
  puts ' close <number> Close a specified request.'
192
+ puts ' prepare Creates a new local branch for a request.'
163
193
  puts ' create Create a new request.'
164
194
  end
165
195
 
@@ -167,7 +197,8 @@ class GitReview
167
197
  def request_exists?(request_id = nil)
168
198
  # NOTE: If request_id is set explicitly we might need to update to get the
169
199
  # latest changes from GitHub, as this is called from within another method.
170
- update unless request_id.nil?
200
+ automated = !request_id.nil?
201
+ update if automated
171
202
  request_id ||= @args.shift.to_i
172
203
  if request_id == 0
173
204
  puts 'Please specify a valid ID.'
@@ -175,7 +206,8 @@ class GitReview
175
206
  end
176
207
  @pending_request = @pending_requests.find{ |req| req['number'] == request_id }
177
208
  if @pending_request.nil?
178
- puts "Request '#{request_id}' does not exist."
209
+ # No output for automated checks.
210
+ puts "Request '#{request_id}' does not exist." unless automated
179
211
  return false
180
212
  end
181
213
  true
@@ -194,33 +226,6 @@ class GitReview
194
226
  end
195
227
  end
196
228
 
197
- # Get local and remote branches ready to create a new request.
198
- def prepare
199
- # People should work on local branches, but especially for single commit changes,
200
- # more often than not, they don't. Therefore we create a branch for them,
201
- # to be able to use code review the way it is intended.
202
- if source_branch == target_branch
203
- # Unless a branch name is already provided, ask for one.
204
- if (branch_name = @args.shift).nil?
205
- puts 'Please provide a name for the branch:'
206
- branch_name = gets.chomp.gsub(/\W+/, '_').downcase
207
- end
208
- # Create the new branch (as a copy of the current one).
209
- local_branch = "review_#{Time.now.strftime("%y%m%d")}_#{branch_name}"
210
- git_call "checkout -b #{local_branch}"
211
- if source_branch == local_branch
212
- # Go back to master and get rid of pending commits (as these are now on the new branch).
213
- git_call "checkout #{target_branch}"
214
- git_call "reset --hard origin/#{target_branch}"
215
- git_call "checkout #{local_branch}"
216
- end
217
- else
218
- local_branch = source_branch
219
- end
220
- # Push latest commits to the remote branch (and by that, create it if necessary).
221
- git_call "push --set-upstream origin #{local_branch}"
222
- end
223
-
224
229
  # System call to 'git'.
225
230
  def git_call(command, verbose = debug_mode)
226
231
  if verbose
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: 5
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 3
10
- version: 0.7.3
9
+ - 6
10
+ version: 0.7.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dominik Bamberger, Cristian Messel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-15 00:00:00 +01:00
18
+ date: 2011-12-14 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency