@@ -239,43 +239,64 @@ def test_get_upstream_branch_failure(mock_subproc_popen):
239
239
process_mock = Mock (returncode = 128 )
240
240
process_mock .communicate .side_effect = [
241
241
('' , "fatal: no such branch: 'blah'" .encode ('utf-8' )),
242
- ('' , "fatal: no upstream configured for branch" .encode ('utf-8' ))
242
+ ('' , "fatal: no upstream configured for branch" .encode ('utf-8' )),
243
+ ('' , "fatal: ambiguous argument 'blah@origin': unknown revision or path not in the working tree." .encode ('utf-8' ))
243
244
]
244
245
mock_subproc_popen .return_value = process_mock
245
246
246
- # When
247
+ # When: fatal: no such branch: 'blah'
247
248
with pytest .raises (Exception ) as error :
248
249
Git (root_dir = '/bin' ).get_upstream_branch (
249
250
current_path = 'test_curr_path' , branch_name = 'blah' )
250
251
252
+ # Then
253
+ mock_subproc_popen .assert_has_calls ([
254
+ call (
255
+ ['git' , 'rev-parse' , '--abbrev-ref' ,
256
+ 'blah@{upstream}' ],
257
+ stdout = PIPE ,
258
+ stderr = PIPE ,
259
+ cwd = '/bin/test_curr_path'
260
+ ),
261
+ call ().communicate ()
262
+ ], any_order = False )
251
263
assert "Error [fatal: no such branch: 'blah'] " \
252
264
"occurred while executing [git rev-parse --abbrev-ref blah@{upstream}] command to get upstream branch." == str (
253
265
error .value )
254
266
267
+ # When: fatal: no upstream configured for branch
255
268
actual_response = Git (root_dir = '/bin' ).get_upstream_branch (
256
269
current_path = 'test_curr_path' , branch_name = 'test' )
257
270
258
- assert None == actual_response
259
-
260
271
# Then
261
272
mock_subproc_popen .assert_has_calls ([
262
273
call (
263
274
['git' , 'rev-parse' , '--abbrev-ref' ,
264
- 'blah @{upstream}' ],
275
+ 'test @{upstream}' ],
265
276
stdout = PIPE ,
266
277
stderr = PIPE ,
267
278
cwd = '/bin/test_curr_path'
268
279
),
269
- call ().communicate (),
280
+ call ().communicate ()
281
+ ], any_order = False )
282
+ assert None == actual_response
283
+
284
+ # When: "fatal: ambiguous argument 'blah@origin': unknown revision or path not in the working tree.
285
+ actual_response = Git (root_dir = '/bin' ).get_upstream_branch (
286
+ current_path = 'test_curr_path' , branch_name = 'blah' )
287
+
288
+ # Then
289
+ mock_subproc_popen .assert_has_calls ([
270
290
call (
271
291
['git' , 'rev-parse' , '--abbrev-ref' ,
272
- 'test @{upstream}' ],
292
+ 'blah @{upstream}' ],
273
293
stdout = PIPE ,
274
294
stderr = PIPE ,
275
295
cwd = '/bin/test_curr_path'
276
296
),
277
297
call ().communicate ()
278
298
], any_order = False )
299
+ assert None == actual_response
279
300
280
301
281
302
@patch ('subprocess.Popen' )
0 commit comments