Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit a8d5eb8

Browse files
authored
Merge pull request #2553 from atom/fix-failing-test
Catch the non-workdir error from git rev-parse
2 parents 2ad6f42 + 19d58a9 commit a8d5eb8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/models/workdir-cache.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ export default class WorkdirCache {
3838
const startDir = (await fs.stat(startPath)).isDirectory() ? startPath : path.dirname(startPath);
3939

4040
// Within a git worktree, return a non-empty string containing the path to the worktree root.
41-
// Within a gitdir or outside of a worktree, return an empty string.
42-
// Throw if startDir does not exist.
43-
const topLevel = await CompositeGitStrategy.create(startDir).exec(['rev-parse', '--show-toplevel']);
44-
if (/\S/.test(topLevel)) {
41+
// Throw if a gitdir, outside of a worktree, or startDir does not exist.
42+
const topLevel = await CompositeGitStrategy.create(startDir).exec(['rev-parse', '--show-toplevel'])
43+
.catch(e => {
44+
if (/this operation must be run in a work tree/.test(e.stdErr)) {
45+
return null;
46+
}
47+
throw e;
48+
});
49+
if (topLevel !== null) {
4550
return toNativePathSep(topLevel.trim());
4651
}
4752

0 commit comments

Comments
 (0)