diff --git a/source/git-api.js b/source/git-api.js index 5fc2cb82c..e8d54d51a 100644 --- a/source/git-api.js +++ b/source/git-api.js @@ -185,7 +185,15 @@ exports.registerApi = (env) => { if (config.autoStashAndPop) { const repo = await getRepo(repoPath); const signature = await repo.defaultSignature(); - const oid = await nodegit.Stash.save(repo, signature, 'Ungit: automatic stash', 0); + const oid = await nodegit.Stash.save( + repo, + signature, + 'Ungit: automatic stash', + nodegit.Stash.FLAGS.INCLUDE_UNTRACKED + ).catch(err => { + // TODO figure out which error is for emtpy repo + console.error('Stash failed', err); + }); const out = await fn(); if (!oid) return out; let index; @@ -951,6 +959,7 @@ exports.registerApi = (env) => { } ); +<<<<<<< HEAD app.get(`${exports.pathPrefix}/quickstatus`, ensureAuthenticated, (req, res) => { const task = fs.isExists(req.query.path).then((exists) => { return exists @@ -959,6 +968,23 @@ exports.registerApi = (env) => { }); jsonResultOrFailProm(res, task); }); +======= + app.get( + `${exports.pathPrefix}/quickstatus`, + ensureAuthenticated, + jw(async req => { + const repoPath = path.normalize(req.query.path); + if (!(await fs.isExists(repoPath))) return { type: 'no-such-path', gitRootPath: repoPath }; + try { + const repo = await getRepo(repoPath); + if (repo.isBare()) return { type: 'bare', gitRootPath: repo.path().replace(/\/$/, '') }; + return { type: 'inited', gitRootPath: repo.workdir().replace(/\/$/, '') }; + } catch { + return { type: 'uninited', gitRootPath: repoPath }; + } + }) + ); +>>>>>>> 0e2f0631... nodegit: save/apply/drop stash; quickstatus /** * @param {nodegit.Commit} c @@ -1015,28 +1041,44 @@ exports.registerApi = (env) => { }) ); - app.post(`${exports.pathPrefix}/stashes`, ensureAuthenticated, ensurePathExists, (req, res) => { - jsonResultOrFailProm( - res, - gitPromise(['stash', 'save', '--include-untracked', req.body.message || ''], req.body.path) - ) - .finally(emitGitDirectoryChanged.bind(null, req.body.path)) - .finally(emitWorkingTreeChanged.bind(null, req.body.path)); - }); + app.post( + `${exports.pathPrefix}/stashes`, + ensureAuthenticated, + ensurePathExists, + jw(async req => { + const { path: repoPath, message = '' } = req.body; + const repo = await getRepo(repoPath); + const signature = await repo.defaultSignature(); + const oid = await nodegit.Stash.save( + repo, + signature, + message, + nodegit.Stash.FLAGS.INCLUDE_UNTRACKED + ); + await emitGitDirectoryChanged(repoPath); + await emitWorkingTreeChanged(repoPath); + return oid; + }) + ); app.delete( `${exports.pathPrefix}/stashes/:id`, ensureAuthenticated, ensurePathExists, - (req, res) => { - const type = req.query.apply === 'true' ? 'apply' : 'drop'; - jsonResultOrFailProm( - res, - gitPromise(['stash', type, `stash@{${req.params.id}}`], req.query.path) - ) - .finally(emitGitDirectoryChanged.bind(null, req.query.path)) - .finally(emitWorkingTreeChanged.bind(null, req.query.path)); - } + jw(async req => { + const { path: repoPath, apply } = req.query; + const { id } = req.params; + const index = Number(id); + if (isNaN(index) || index < 0) throw new Error(`Invalid index ${id}`); + const repo = await getRepo(repoPath); + if (apply === 'true') { + await nodegit.Stash.apply(repo, index); + } else { + await nodegit.Stash.drop(repo, index); + } + await emitGitDirectoryChanged(repoPath); + await emitWorkingTreeChanged(repoPath); + }) ); app.get(`${exports.pathPrefix}/gitconfig`, ensureAuthenticated, (req, res) => { diff --git a/source/server.js b/source/server.js index 158024bd8..4761b3382 100644 --- a/source/server.js +++ b/source/server.js @@ -100,7 +100,6 @@ if (config.allowedIPs) { res .status(403) .send( - 403, '
You are trying to connect to an Ungit instance from an unathorized host.
' ); @@ -386,7 +385,7 @@ app.post('/api/userconfig', ensureAuthenticated, (req, res) => { }); app.get('/api/fs/exists', ensureAuthenticated, (req, res) => { - res.json(fs.existsSync(req.query['path'])); + res.json(fs.existsSync(req.query.path)); }); app.get('/api/fs/listDirectories', ensureAuthenticated, (req, res) => {