@@ -21,18 +21,22 @@ import type { GitBranchReference, GitTagReference } from '../../../../git/models
2121import { GitStatus } from '../../../../git/models/status' ;
2222import type { GitStatusFile } from '../../../../git/models/statusFile' ;
2323import { parseGitStatus } from '../../../../git/parsers/statusParser' ;
24- import { getReferenceFromBranch } from '../../../../git/utils/-webview/reference.utils' ;
2524import { createReference } from '../../../../git/utils/reference.utils' ;
2625import { configuration } from '../../../../system/-webview/configuration' ;
2726import { splitPath } from '../../../../system/-webview/path' ;
2827import { gate } from '../../../../system/decorators/-webview/gate' ;
2928import { log } from '../../../../system/decorators/log' ;
3029import { Logger } from '../../../../system/logger' ;
30+ import { getLogScope , setLogScopeExit } from '../../../../system/logger.scope' ;
3131import { getSettledValue } from '../../../../system/promise' ;
3232import type { Git } from '../git' ;
3333import { GitErrors } from '../git' ;
3434import type { LocalGitProvider } from '../localGitProvider' ;
3535
36+ type Operation = 'cherry-pick' | 'merge' | 'rebase-apply' | 'rebase-merge' | 'revert' ;
37+
38+ const orderedOperations : Operation [ ] = [ 'rebase-apply' , 'rebase-merge' , 'merge' , 'cherry-pick' , 'revert' ] ;
39+
3640export class StatusGitSubProvider implements GitStatusSubProvider {
3741 constructor (
3842 private readonly container : Container ,
@@ -44,21 +48,23 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
4448 @gate ( )
4549 @log ( )
4650 async getPausedOperationStatus ( repoPath : string ) : Promise < GitPausedOperationStatus | undefined > {
51+ const scope = getLogScope ( ) ;
52+
4753 let status = this . cache . pausedOperationStatus ?. get ( repoPath ) ;
4854 if ( status == null ) {
4955 async function getCore ( this : StatusGitSubProvider ) : Promise < GitPausedOperationStatus | undefined > {
5056 const gitDir = await this . provider . getGitDir ( repoPath ) ;
5157
52- type Operation = 'cherry-pick' | 'merge' | 'rebase-apply' | 'rebase-merge' | 'revert' ;
53- const operation = await new Promise < Operation | undefined > ( ( resolve , _ ) => {
58+ const operations = await new Promise < Set < Operation > > ( ( resolve , _ ) => {
5459 readdir ( gitDir . uri . fsPath , { withFileTypes : true } , ( err , entries ) => {
60+ const operations = new Set < Operation > ( ) ;
5561 if ( err != null ) {
56- resolve ( undefined ) ;
62+ resolve ( operations ) ;
5763 return ;
5864 }
5965
6066 if ( entries . length === 0 ) {
61- resolve ( undefined ) ;
67+ resolve ( operations ) ;
6268 return ;
6369 }
6470
@@ -67,33 +73,39 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
6773 if ( entry . isFile ( ) ) {
6874 switch ( entry . name ) {
6975 case 'CHERRY_PICK_HEAD' :
70- resolve ( 'cherry-pick' ) ;
71- return ;
76+ operations . add ( 'cherry-pick' ) ;
77+ break ;
7278 case 'MERGE_HEAD' :
73- resolve ( 'merge' ) ;
74- return ;
79+ operations . add ( 'merge' ) ;
80+ break ;
7581 case 'REVERT_HEAD' :
76- resolve ( 'revert' ) ;
77- return ;
82+ operations . add ( 'revert' ) ;
83+ break ;
7884 }
7985 } else if ( entry . isDirectory ( ) ) {
8086 switch ( entry . name ) {
8187 case 'rebase-apply' :
82- resolve ( 'rebase-apply' ) ;
83- return ;
88+ operations . add ( 'rebase-apply' ) ;
89+ break ;
8490 case 'rebase-merge' :
85- resolve ( 'rebase-merge' ) ;
86- return ;
91+ operations . add ( 'rebase-merge' ) ;
92+ break ;
8793 }
8894 }
8995 }
9096
91- resolve ( undefined ) ;
97+ resolve ( operations ) ;
9298 } ) ;
9399 } ) ;
94100
95- if ( operation == null ) return undefined ;
101+ if ( ! operations . size ) return undefined ;
102+
103+ const sortedOperations = [ ...operations ] . sort (
104+ ( a , b ) => orderedOperations . indexOf ( a ) - orderedOperations . indexOf ( b ) ,
105+ ) ;
106+ Logger . log ( `Detected paused operations: ${ sortedOperations . join ( ', ' ) } ` ) ;
96107
108+ const operation = sortedOperations [ 0 ] ;
97109 switch ( operation ) {
98110 case 'cherry-pick' : {
99111 const cherryPickHead = (
@@ -105,16 +117,19 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
105117 'CHERRY_PICK_HEAD' ,
106118 )
107119 ) ?. trim ( ) ;
108- if ( ! cherryPickHead ) return undefined ;
120+ if ( ! cherryPickHead ) {
121+ setLogScopeExit ( scope , 'No CHERRY_PICK_HEAD found' ) ;
122+ return undefined ;
123+ }
109124
110- const branch = ( await this . provider . branches . getBranch ( repoPath ) ) ! ;
125+ const current = ( await this . provider . branches . getCurrentBranchReference ( repoPath ) ) ! ;
111126
112127 return {
113128 type : 'cherry-pick' ,
114129 repoPath : repoPath ,
115130 // TODO: Validate that these are correct
116131 HEAD : createReference ( cherryPickHead , repoPath , { refType : 'revision' } ) ,
117- current : getReferenceFromBranch ( branch ) ,
132+ current : current ,
118133 incoming : createReference ( cherryPickHead , repoPath , { refType : 'revision' } ) ,
119134 } satisfies GitCherryPickStatus ;
120135 }
@@ -128,18 +143,21 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
128143 'MERGE_HEAD' ,
129144 )
130145 ) ?. trim ( ) ;
131- if ( ! mergeHead ) return undefined ;
146+ if ( ! mergeHead ) {
147+ setLogScopeExit ( scope , 'No MERGE_HEAD found' ) ;
148+ return undefined ;
149+ }
132150
133151 const [ branchResult , mergeBaseResult , possibleSourceBranchesResult ] = await Promise . allSettled ( [
134- this . provider . branches . getBranch ( repoPath ) ,
152+ this . provider . branches . getCurrentBranchReference ( repoPath ) ,
135153 this . provider . branches . getMergeBase ( repoPath , 'MERGE_HEAD' , 'HEAD' ) ,
136154 this . provider . branches . getBranchesWithCommits ( repoPath , [ 'MERGE_HEAD' ] , undefined , {
137155 all : true ,
138156 mode : 'pointsAt' ,
139157 } ) ,
140158 ] ) ;
141159
142- const branch = getSettledValue ( branchResult ) ! ;
160+ const current = getSettledValue ( branchResult ) ! ;
143161 const mergeBase = getSettledValue ( mergeBaseResult ) ;
144162 const possibleSourceBranches = getSettledValue ( possibleSourceBranchesResult ) ;
145163
@@ -148,7 +166,7 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
148166 repoPath : repoPath ,
149167 mergeBase : mergeBase ,
150168 HEAD : createReference ( mergeHead , repoPath , { refType : 'revision' } ) ,
151- current : getReferenceFromBranch ( branch ) ,
169+ current : current ,
152170 incoming :
153171 possibleSourceBranches ?. length === 1
154172 ? createReference ( possibleSourceBranches [ 0 ] , repoPath , {
@@ -169,22 +187,28 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
169187 'REVERT_HEAD' ,
170188 )
171189 ) ?. trim ( ) ;
172- if ( ! revertHead ) return undefined ;
190+ if ( ! revertHead ) {
191+ setLogScopeExit ( scope , 'No REVERT_HEAD found' ) ;
192+ return undefined ;
193+ }
173194
174- const branch = ( await this . provider . branches . getBranch ( repoPath ) ) ! ;
195+ const current = ( await this . provider . branches . getCurrentBranchReference ( repoPath ) ) ! ;
175196
176197 return {
177198 type : 'revert' ,
178199 repoPath : repoPath ,
179200 HEAD : createReference ( revertHead , repoPath , { refType : 'revision' } ) ,
180- current : getReferenceFromBranch ( branch ) ,
201+ current : current ,
181202 incoming : createReference ( revertHead , repoPath , { refType : 'revision' } ) ,
182203 } satisfies GitRevertStatus ;
183204 }
184205 case 'rebase-apply' :
185206 case 'rebase-merge' : {
186207 let branch = await this . git . readDotGitFile ( gitDir , [ operation , 'head-name' ] ) ;
187- if ( ! branch ) return undefined ;
208+ if ( ! branch ) {
209+ setLogScopeExit ( scope , `No '${ operation } /head-name' found` ) ;
210+ return undefined ;
211+ }
188212
189213 const [
190214 rebaseHeadResult ,
@@ -212,7 +236,10 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
212236
213237 const origHead = getSettledValue ( origHeadResult ) ;
214238 const onto = getSettledValue ( ontoResult ) ;
215- if ( origHead == null || onto == null ) return undefined ;
239+ if ( origHead == null || onto == null ) {
240+ setLogScopeExit ( scope , `Neither '${ operation } /orig-head' nor '${ operation } /onto' found` ) ;
241+ return undefined ;
242+ }
216243
217244 const rebaseHead = getSettledValue ( rebaseHeadResult ) ?. trim ( ) ;
218245
0 commit comments