-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to stop git.find at a directory
- Loading branch information
1 parent
17527e5
commit 8d48579
Showing
4 changed files
with
32 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
const is = require('./is.js') | ||
const { dirname } = require('path') | ||
const { dirname, normalize } = require('path') | ||
|
||
module.exports = async ({ cwd = process.cwd() } = {}) => { | ||
if (await is({ cwd })) { | ||
return cwd | ||
} | ||
while (cwd !== dirname(cwd)) { | ||
cwd = dirname(cwd) | ||
module.exports = async ({ cwd = process.cwd(), root = normalize('/') } = {}) => { | ||
while (true) { | ||
if (await is({ cwd })) { | ||
return cwd | ||
} | ||
const next = dirname(cwd) | ||
if (cwd === root || cwd === next) { | ||
return null | ||
} | ||
cwd = next | ||
} | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
// not an airtight indicator, but a good gut-check to even bother trying | ||
const { promisify } = require('util') | ||
const fs = require('fs') | ||
const stat = promisify(fs.stat) | ||
const fs = require('fs/promises') | ||
const { join } = require('path') | ||
module.exports = ({ cwd = process.cwd() } = {}) => | ||
stat(cwd + '/.git').then(() => true, () => false) | ||
fs.stat(join(cwd, '.git')).then(() => true, () => false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters