@@ -106,7 +106,7 @@ export default function githubFs(token, settings) {
106106 const [ repoName , branch ] = repoAtBranch . split ( '@' ) ;
107107 let sha = '' ;
108108 const getSha = async ( ) => {
109- if ( ! sha ) {
109+ if ( ! sha && path ) {
110110 const res = await repo . getSha ( branch , path ) ;
111111 sha = res . data . sha ;
112112 }
@@ -142,6 +142,7 @@ export default function githubFs(token, settings) {
142142 } ) ;
143143 } ,
144144 async readFile ( encoding ) {
145+ if ( ! path ) throw new Error ( 'Cannot read root directory' )
145146 await init ( ) ;
146147 await getSha ( ) ;
147148 let { data } = await repo . getBlob ( sha , 'blob' ) ;
@@ -154,6 +155,7 @@ export default function githubFs(token, settings) {
154155 return data ;
155156 } ,
156157 async writeFile ( data ) {
158+ if ( ! path ) throw new Error ( 'Cannot write to root directory' )
157159 const commitMessage = await getCommitMessage ( `update ${ path } ` ) ;
158160 await init ( ) ;
159161 await repo . writeFile ( branch , path , data , commitMessage ) ;
@@ -201,25 +203,29 @@ export default function githubFs(token, settings) {
201203 throw new Error ( 'Not implemented' ) ;
202204 } ,
203205 async delete ( ) {
206+ if ( ! path ) throw new Error ( 'Cannot delete root' ) ;
204207 await init ( ) ;
205208 await getSha ( ) ;
206209 const commitMessage = await getCommitMessage ( `delete ${ path } ` ) ;
207210 await repo . deleteFile ( branch , path , commitMessage , sha ) ;
208211 } ,
209212 async moveTo ( dest ) {
213+ if ( ! path ) throw new Error ( 'Cannot move root' ) ;
210214 await init ( ) ;
211215 const { path : destPath } = parseUrl ( dest ) ;
212216 const newName = Url . join ( destPath , Url . basename ( path ) ) ;
213217 const res = await move ( newName ) ;
214218 return res ;
215219 } ,
216220 async renameTo ( name ) {
221+ if ( ! path ) throw new Error ( 'Cannot rename root' ) ;
217222 await init ( ) ;
218223 const newName = Url . join ( Url . dirname ( path ) , name ) ;
219224 const res = await move ( newName ) ;
220225 return res ;
221226 } ,
222227 async exists ( ) {
228+ if ( ! path ) return true ;
223229 await init ( ) ;
224230 try {
225231 await repo . getSha ( branch , path ) ;
@@ -229,6 +235,14 @@ export default function githubFs(token, settings) {
229235 }
230236 } ,
231237 async stat ( ) {
238+ if ( ! path ) {
239+ return {
240+ length : 0 ,
241+ name : `github/${ user } /${ repoName } ` ,
242+ isDirectory : true ,
243+ isFile : false ,
244+ }
245+ }
232246 await init ( ) ;
233247 await getSha ( ) ;
234248 const content = await repo . getBlob ( sha ) ;
0 commit comments