@@ -21,7 +21,6 @@ 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' ;
@@ -33,6 +32,10 @@ import type { Git } from '../git';
3332import { GitErrors } from '../git' ;
3433import type { LocalGitProvider } from '../localGitProvider' ;
3534
35+ type Operation = 'cherry-pick' | 'merge' | 'rebase-apply' | 'rebase-merge' | 'revert' ;
36+
37+ const orderedOperations : Operation [ ] = [ 'rebase-apply' , 'rebase-merge' , 'merge' , 'cherry-pick' , 'revert' ] ;
38+
3639export class StatusGitSubProvider implements GitStatusSubProvider {
3740 constructor (
3841 private readonly container : Container ,
@@ -49,16 +52,16 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
4952 async function getCore ( this : StatusGitSubProvider ) : Promise < GitPausedOperationStatus | undefined > {
5053 const gitDir = await this . provider . config . getGitDir ( repoPath ) ;
5154
52- type Operation = 'cherry-pick' | 'merge' | 'rebase-apply' | 'rebase-merge' | 'revert' ;
53- const operation = await new Promise < Operation | undefined > ( ( resolve , _ ) => {
55+ const operations = await new Promise < Set < Operation > > ( ( resolve , _ ) => {
5456 readdir ( gitDir . uri . fsPath , { withFileTypes : true } , ( err , entries ) => {
57+ const operations = new Set < Operation > ( ) ;
5558 if ( err != null ) {
56- resolve ( undefined ) ;
59+ resolve ( operations ) ;
5760 return ;
5861 }
5962
6063 if ( entries . length === 0 ) {
61- resolve ( undefined ) ;
64+ resolve ( operations ) ;
6265 return ;
6366 }
6467
@@ -67,32 +70,36 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
6770 if ( entry . isFile ( ) ) {
6871 switch ( entry . name ) {
6972 case 'CHERRY_PICK_HEAD' :
70- resolve ( 'cherry-pick' ) ;
71- return ;
73+ operations . add ( 'cherry-pick' ) ;
74+ break ;
7275 case 'MERGE_HEAD' :
73- resolve ( 'merge' ) ;
74- return ;
76+ operations . add ( 'merge' ) ;
77+ break ;
7578 case 'REVERT_HEAD' :
76- resolve ( 'revert' ) ;
77- return ;
79+ operations . add ( 'revert' ) ;
80+ break ;
7881 }
7982 } else if ( entry . isDirectory ( ) ) {
8083 switch ( entry . name ) {
8184 case 'rebase-apply' :
82- resolve ( 'rebase-apply' ) ;
83- return ;
85+ operations . add ( 'rebase-apply' ) ;
86+ break ;
8487 case 'rebase-merge' :
85- resolve ( 'rebase-merge' ) ;
86- return ;
88+ operations . add ( 'rebase-merge' ) ;
89+ break ;
8790 }
8891 }
8992 }
9093
91- resolve ( undefined ) ;
94+ resolve ( operations ) ;
9295 } ) ;
9396 } ) ;
9497
95- if ( operation == null ) return undefined ;
98+ if ( ! operations . size ) return undefined ;
99+
100+ const operation = [ ...operations ] . sort (
101+ ( a , b ) => orderedOperations . indexOf ( a ) - orderedOperations . indexOf ( b ) ,
102+ ) [ 0 ] ;
96103
97104 switch ( operation ) {
98105 case 'cherry-pick' : {
@@ -107,14 +114,14 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
107114 ) ?. trim ( ) ;
108115 if ( ! cherryPickHead ) return undefined ;
109116
110- const branch = ( await this . provider . branches . getBranch ( repoPath ) ) ! ;
117+ const current = ( await this . provider . branches . getCurrentBranchReference ( repoPath ) ) ! ;
111118
112119 return {
113120 type : 'cherry-pick' ,
114121 repoPath : repoPath ,
115122 // TODO: Validate that these are correct
116123 HEAD : createReference ( cherryPickHead , repoPath , { refType : 'revision' } ) ,
117- current : getReferenceFromBranch ( branch ) ,
124+ current : current ,
118125 incoming : createReference ( cherryPickHead , repoPath , { refType : 'revision' } ) ,
119126 } satisfies GitCherryPickStatus ;
120127 }
@@ -131,15 +138,15 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
131138 if ( ! mergeHead ) return undefined ;
132139
133140 const [ branchResult , mergeBaseResult , possibleSourceBranchesResult ] = await Promise . allSettled ( [
134- this . provider . branches . getBranch ( repoPath ) ,
141+ this . provider . branches . getCurrentBranchReference ( repoPath ) ,
135142 this . provider . refs . getMergeBase ( repoPath , 'MERGE_HEAD' , 'HEAD' ) ,
136143 this . provider . branches . getBranchesWithCommits ( repoPath , [ 'MERGE_HEAD' ] , undefined , {
137144 all : true ,
138145 mode : 'pointsAt' ,
139146 } ) ,
140147 ] ) ;
141148
142- const branch = getSettledValue ( branchResult ) ! ;
149+ const current = getSettledValue ( branchResult ) ! ;
143150 const mergeBase = getSettledValue ( mergeBaseResult ) ;
144151 const possibleSourceBranches = getSettledValue ( possibleSourceBranchesResult ) ;
145152
@@ -148,7 +155,7 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
148155 repoPath : repoPath ,
149156 mergeBase : mergeBase ,
150157 HEAD : createReference ( mergeHead , repoPath , { refType : 'revision' } ) ,
151- current : getReferenceFromBranch ( branch ) ,
158+ current : current ,
152159 incoming :
153160 possibleSourceBranches ?. length === 1
154161 ? createReference ( possibleSourceBranches [ 0 ] , repoPath , {
@@ -171,13 +178,13 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
171178 ) ?. trim ( ) ;
172179 if ( ! revertHead ) return undefined ;
173180
174- const branch = ( await this . provider . branches . getBranch ( repoPath ) ) ! ;
181+ const current = ( await this . provider . branches . getCurrentBranchReference ( repoPath ) ) ! ;
175182
176183 return {
177184 type : 'revert' ,
178185 repoPath : repoPath ,
179186 HEAD : createReference ( revertHead , repoPath , { refType : 'revision' } ) ,
180- current : getReferenceFromBranch ( branch ) ,
187+ current : current ,
181188 incoming : createReference ( revertHead , repoPath , { refType : 'revision' } ) ,
182189 } satisfies GitRevertStatus ;
183190 }
0 commit comments