@@ -353,9 +353,18 @@ async def test_status(tmp_path, output, diff_output, expected):
353353 repository = tmp_path / "test_curr_path"
354354 (repository / ".git" / "rebase-merge" ).mkdir (parents = True )
355355
356+ # Determine if this is a first commit scenario
357+ is_first_commit = expected .get ("branch" ) == "(initial)"
358+
359+ # Build mock_execute.side_effect list
360+ # First: git status call
361+ # Second: git rev-parse --verify HEAD (for _is_first_commit)
362+ # Third: git diff call (with or without empty tree SHA based on is_first_commit)
363+ # Then: state detection calls (cherry pick, merge, rebase)
356364 mock_execute .side_effect = [
357- maybe_future ((0 , "\x00 " .join (output ) + "\x00 " , "" )),
358- maybe_future ((0 , "\x00 " .join (diff_output ) + "\x00 " , "" )),
365+ maybe_future ((0 , "\x00 " .join (output ) + "\x00 " , "" )), # git status
366+ maybe_future ((128 if is_first_commit else 0 , "" , "" )), # git rev-parse --verify HEAD
367+ maybe_future ((0 , "\x00 " .join (diff_output ) + "\x00 " , "" )), # git diff
359368 maybe_future ((0 if expected ["state" ] == 4 else 128 , "" , "cherry pick" )),
360369 maybe_future ((0 if expected ["state" ] == 2 else 128 , "" , "merge" )),
361370 maybe_future (
@@ -381,21 +390,57 @@ async def test_status(tmp_path, output, diff_output, expected):
381390 is_binary = False ,
382391 ),
383392 call (
384- [
385- "git" ,
386- "diff" ,
387- "--numstat" ,
388- "-z" ,
389- "--cached" ,
390- "4b825dc642cb6eb9a060e54bf8d69288fbee4904" ,
391- ],
393+ ["git" , "rev-parse" , "--verify" , "HEAD" ],
392394 cwd = str (repository ),
393395 timeout = 20 ,
394396 env = None ,
395397 username = None ,
396398 password = None ,
397399 is_binary = False ,
398400 ),
401+ ]
402+
403+ # Add diff command based on whether it's first commit
404+ if is_first_commit :
405+ expected_calls .append (
406+ call (
407+ [
408+ "git" ,
409+ "diff" ,
410+ "--numstat" ,
411+ "-z" ,
412+ "--cached" ,
413+ "4b825dc642cb6eb9a060e54bf8d69288fbee4904" ,
414+ ],
415+ cwd = str (repository ),
416+ timeout = 20 ,
417+ env = None ,
418+ username = None ,
419+ password = None ,
420+ is_binary = False ,
421+ )
422+ )
423+ else :
424+ expected_calls .append (
425+ call (
426+ [
427+ "git" ,
428+ "diff" ,
429+ "--numstat" ,
430+ "-z" ,
431+ "--cached" ,
432+ ],
433+ cwd = str (repository ),
434+ timeout = 20 ,
435+ env = None ,
436+ username = None ,
437+ password = None ,
438+ is_binary = False ,
439+ )
440+ )
441+
442+ # Add state detection calls
443+ expected_calls .extend ([
399444 call (
400445 ["git" , "show" , "--quiet" , "CHERRY_PICK_HEAD" ],
401446 cwd = str (repository ),
@@ -432,7 +477,7 @@ async def test_status(tmp_path, output, diff_output, expected):
432477 password = None ,
433478 is_binary = False ,
434479 ),
435- ]
480+ ])
436481
437482 if expected ["state" ] == 4 :
438483 expected_calls = expected_calls [:- 3 ]
0 commit comments