@@ -173,7 +173,15 @@ exports.registerApi = env => {
173173 if ( config . autoStashAndPop ) {
174174 const repo = await getRepo ( repoPath ) ;
175175 const signature = await repo . defaultSignature ( ) ;
176- const oid = await nodegit . Stash . save ( repo , signature , 'Ungit: automatic stash' , 0 ) ;
176+ const oid = await nodegit . Stash . save (
177+ repo ,
178+ signature ,
179+ 'Ungit: automatic stash' ,
180+ nodegit . Stash . FLAGS . INCLUDE_UNTRACKED
181+ ) . catch ( err => {
182+ // TODO figure out which error is for emtpy repo
183+ console . error ( 'Stash failed' , err ) ;
184+ } ) ;
177185 const out = await fn ( ) ;
178186 if ( ! oid ) return out ;
179187 let index ;
@@ -939,14 +947,21 @@ exports.registerApi = env => {
939947 }
940948 ) ;
941949
942- app . get ( `${ exports . pathPrefix } /quickstatus` , ensureAuthenticated , ( req , res ) => {
943- const task = fs . isExists ( req . query . path ) . then ( exists => {
944- return exists
945- ? gitPromise . revParse ( req . query . path )
946- : { type : 'no-such-path' , gitRootPath : req . query . path } ;
947- } ) ;
948- jsonResultOrFailProm ( res , task ) ;
949- } ) ;
950+ app . get (
951+ `${ exports . pathPrefix } /quickstatus` ,
952+ ensureAuthenticated ,
953+ jw ( async req => {
954+ const repoPath = path . normalize ( req . query . path ) ;
955+ if ( ! ( await fs . isExists ( repoPath ) ) ) return { type : 'no-such-path' , gitRootPath : repoPath } ;
956+ try {
957+ const repo = await getRepo ( repoPath ) ;
958+ if ( repo . isBare ( ) ) return { type : 'bare' , gitRootPath : repo . path ( ) . replace ( / \/ $ / , '' ) } ;
959+ return { type : 'inited' , gitRootPath : repo . workdir ( ) . replace ( / \/ $ / , '' ) } ;
960+ } catch {
961+ return { type : 'uninited' , gitRootPath : repoPath } ;
962+ }
963+ } )
964+ ) ;
950965
951966 /**
952967 * @param {nodegit.Commit } c
@@ -1003,28 +1018,44 @@ exports.registerApi = env => {
10031018 } )
10041019 ) ;
10051020
1006- app . post ( `${ exports . pathPrefix } /stashes` , ensureAuthenticated , ensurePathExists , ( req , res ) => {
1007- jsonResultOrFailProm (
1008- res ,
1009- gitPromise ( [ 'stash' , 'save' , '--include-untracked' , req . body . message || '' ] , req . body . path )
1010- )
1011- . finally ( emitGitDirectoryChanged . bind ( null , req . body . path ) )
1012- . finally ( emitWorkingTreeChanged . bind ( null , req . body . path ) ) ;
1013- } ) ;
1021+ app . post (
1022+ `${ exports . pathPrefix } /stashes` ,
1023+ ensureAuthenticated ,
1024+ ensurePathExists ,
1025+ jw ( async req => {
1026+ const { path : repoPath , message = '' } = req . body ;
1027+ const repo = await getRepo ( repoPath ) ;
1028+ const signature = await repo . defaultSignature ( ) ;
1029+ const oid = await nodegit . Stash . save (
1030+ repo ,
1031+ signature ,
1032+ message ,
1033+ nodegit . Stash . FLAGS . INCLUDE_UNTRACKED
1034+ ) ;
1035+ await emitGitDirectoryChanged ( repoPath ) ;
1036+ await emitWorkingTreeChanged ( repoPath ) ;
1037+ return oid ;
1038+ } )
1039+ ) ;
10141040
10151041 app . delete (
10161042 `${ exports . pathPrefix } /stashes/:id` ,
10171043 ensureAuthenticated ,
10181044 ensurePathExists ,
1019- ( req , res ) => {
1020- const type = req . query . apply === 'true' ? 'apply' : 'drop' ;
1021- jsonResultOrFailProm (
1022- res ,
1023- gitPromise ( [ 'stash' , type , `stash@{${ req . params . id } }` ] , req . query . path )
1024- )
1025- . finally ( emitGitDirectoryChanged . bind ( null , req . query . path ) )
1026- . finally ( emitWorkingTreeChanged . bind ( null , req . query . path ) ) ;
1027- }
1045+ jw ( async req => {
1046+ const { path : repoPath , apply } = req . query ;
1047+ const { id } = req . params ;
1048+ const index = Number ( id ) ;
1049+ if ( isNaN ( index ) || index < 0 ) throw new Error ( `Invalid index ${ id } ` ) ;
1050+ const repo = await getRepo ( repoPath ) ;
1051+ if ( apply === 'true' ) {
1052+ await nodegit . Stash . apply ( repo , index ) ;
1053+ } else {
1054+ await nodegit . Stash . drop ( repo , index ) ;
1055+ }
1056+ await emitGitDirectoryChanged ( repoPath ) ;
1057+ await emitWorkingTreeChanged ( repoPath ) ;
1058+ } )
10281059 ) ;
10291060
10301061 app . get ( `${ exports . pathPrefix } /gitconfig` , ensureAuthenticated , ( req , res ) => {
0 commit comments