@@ -85,6 +85,11 @@ type GitStateModule = {
8585 source ?: ReviewSource ,
8686 options ?: { showWhitespace ?: boolean } ,
8787 ) => Promise < RepositoryState > ;
88+ readWalkthroughRepositoryState : (
89+ launchPath : string ,
90+ source ?: ReviewSource ,
91+ options ?: { showWhitespace ?: boolean } ,
92+ ) => Promise < RepositoryState > ;
8893 readWorkingTreeState : (
8994 launchPath : string ,
9095 options ?: { eagerContents ?: boolean ; showWhitespace ?: boolean } ,
@@ -116,6 +121,7 @@ const {
116121 readDiffSectionContent,
117122 readRepositoryChangeSignature,
118123 readRepositoryState,
124+ readWalkthroughRepositoryState,
119125 readWorkingTreeState,
120126 resolvePullRequestContentRefs,
121127 selectUnresolvedReviewComments,
@@ -694,6 +700,35 @@ test('readRepositoryState and history handle fresh repositories', async () => {
694700 } ) ;
695701} ) ;
696702
703+ test ( 'readWalkthroughRepositoryState falls back to HEAD only for a clean implicit source' , ( ) =>
704+ withRepo ( async ( repo ) => {
705+ await writeRepoFile ( repo , 'example.txt' , 'before\n' ) ;
706+ await commitAll ( repo , 'initial commit' ) ;
707+ await writeRepoFile ( repo , 'example.txt' , 'after\n' ) ;
708+ await commitAll ( repo , 'update example' ) ;
709+
710+ const cleanState = await readWalkthroughRepositoryState ( repo ) ;
711+ expect ( cleanState . source ) . toMatchObject ( { type : 'commit' } ) ;
712+ expect ( cleanState . commitMetadata ?. subject ) . toBe ( 'update example' ) ;
713+
714+ const explicitWorkingTreeState = await readWalkthroughRepositoryState ( repo , {
715+ type : 'working-tree' ,
716+ } ) ;
717+ expect ( explicitWorkingTreeState . source ) . toEqual ( { type : 'working-tree' } ) ;
718+ expect ( explicitWorkingTreeState . files ) . toEqual ( [ ] ) ;
719+
720+ await writeRepoFile ( repo , 'example.txt' , 'local\n' ) ;
721+ const dirtyState = await readWalkthroughRepositoryState ( repo ) ;
722+ expect ( dirtyState . source ) . toEqual ( { type : 'working-tree' } ) ;
723+ } ) ) ;
724+
725+ test ( 'readWalkthroughRepositoryState keeps a fresh repository on the working tree' , ( ) =>
726+ withRepo ( async ( repo ) => {
727+ const state = await readWalkthroughRepositoryState ( repo ) ;
728+ expect ( state . source ) . toEqual ( { type : 'working-tree' } ) ;
729+ expect ( state . files ) . toEqual ( [ ] ) ;
730+ } ) ) ;
731+
697732test ( 'readRepositoryState reports commit metadata for root commits' , async ( ) => {
698733 await withRepo ( async ( repo ) => {
699734 await writeRepoFile ( repo , 'notes/todo.txt' , 'write tests\nship polish\n' ) ;
0 commit comments