File tree Expand file tree Collapse file tree 3 files changed +63
-9
lines changed Expand file tree Collapse file tree 3 files changed +63
-9
lines changed Original file line number Diff line number Diff line change @@ -857,15 +857,31 @@ export class GitExtension implements IGitExtension {
857
857
* @throws {Git.GitResponseError } If the server response is not ok
858
858
* @throws {ServerConnection.NetworkError } If the request cannot be made
859
859
*/
860
- async showPrefix ( path : string ) : Promise < Git . IShowPrefixResult > {
861
- return await this . _taskHandler . execute < Git . IShowPrefixResult > (
862
- 'git:fetch:prefix_path' ,
863
- async ( ) => {
864
- return await requestAPI < Git . IShowPrefixResult > ( 'show_prefix' , 'POST' , {
865
- current_path : path
866
- } ) ;
860
+ async showPrefix ( path : string ) : Promise < string | null > {
861
+ try {
862
+ const data = await this . _taskHandler . execute < Git . IShowPrefixResult > (
863
+ 'git:fetch:prefix_path' ,
864
+ async ( ) => {
865
+ return await requestAPI < Git . IShowPrefixResult > (
866
+ 'show_prefix' ,
867
+ 'POST' ,
868
+ {
869
+ current_path : path
870
+ }
871
+ ) ;
872
+ }
873
+ ) ;
874
+ return data . under_repo_path || null ;
875
+ } catch ( error ) {
876
+ if (
877
+ error instanceof Git . GitResponseError &&
878
+ error . response . status === 500 &&
879
+ error . json . code === 128
880
+ ) {
881
+ return null ;
867
882
}
868
- ) ;
883
+ throw error ;
884
+ }
869
885
}
870
886
871
887
/**
Original file line number Diff line number Diff line change @@ -383,7 +383,7 @@ export interface IGitExtension extends IDisposable {
383
383
* @throws {Git.GitResponseError } If the server response is not ok
384
384
* @throws {ServerConnection.NetworkError } If the request cannot be made
385
385
*/
386
- showPrefix ( path : string ) : Promise < Git . IShowPrefixResult > ;
386
+ showPrefix ( path : string ) : Promise < string | null > ;
387
387
388
388
/**
389
389
* Get the top level path of repository 'path'
Original file line number Diff line number Diff line change @@ -119,6 +119,44 @@ describe('IGitExtension', () => {
119
119
} ) ;
120
120
} ) ;
121
121
122
+ describe ( '#showPrefix' , ( ) => {
123
+ it ( 'should return a string if the folder is a git repository' , async ( ) => {
124
+ const fakeRepo = '/repo' ;
125
+ mockResponses [ 'show_prefix' ] = {
126
+ body : ( ) => {
127
+ return { code : 0 , under_repo_path : fakeRepo } ;
128
+ }
129
+ } ;
130
+ const topLevel = await model . showPrefix ( '/repo/cwd' ) ;
131
+ expect ( topLevel ) . toEqual ( fakeRepo ) ;
132
+ } ) ;
133
+
134
+ it ( 'should return null if the repository is not a git repository' , async ( ) => {
135
+ mockResponses [ 'show_prefix' ] = {
136
+ body : ( ) => {
137
+ return { code : 128 } ;
138
+ } ,
139
+ status : 500
140
+ } ;
141
+ const topLevel = await model . showPrefix ( '/repo/cwd' ) ;
142
+ expect ( topLevel ) . toBeNull ( ) ;
143
+ } ) ;
144
+
145
+ it ( 'should throw an exception if the server otherwise' , async ( ) => {
146
+ mockResponses [ 'show_prefix' ] = {
147
+ body : ( ) => {
148
+ return { code : 128 } ;
149
+ } ,
150
+ status : 401
151
+ } ;
152
+ try {
153
+ await model . showPrefix ( '/repo/cwd' ) ;
154
+ } catch ( error ) {
155
+ expect ( error ) . toBeInstanceOf ( Git . GitResponseError ) ;
156
+ }
157
+ } ) ;
158
+ } ) ;
159
+
122
160
describe ( '#showTopLevel' , ( ) => {
123
161
it ( 'should return a string if the folder is a git repository' , async ( ) => {
124
162
const fakeRepo = '/path/to/repo' ;
You can’t perform that action at this time.
0 commit comments