-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spire): Do not use git binary and enable installing git hooks again
BREAKING CHANGE: Git hooks are now installed again.
- Loading branch information
Showing
7 changed files
with
121 additions
and
76 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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { createFixture } = require('spire-test-utils'); | ||
const { join } = require('path'); | ||
const getGitRoot = require('../getGitRoot'); | ||
|
||
describe('getGitRoot', () => { | ||
it('resolves root directory if .git directory exists', async () => { | ||
const fixture = await createFixture( | ||
{ | ||
'.git/config': `[remote "origin"] | ||
url = https://github.com/researchgate/spire.git`, | ||
}, | ||
{ git: false } | ||
); | ||
const subdir = join(fixture.cwd, 'some/other/sub/folder'); | ||
expect(await getGitRoot(subdir)).toBe(fixture.cwd); | ||
await fixture.clean(); | ||
}); | ||
|
||
it('does not resolve root directory if .git directory does not exists', async () => { | ||
const fixture = await createFixture({}, { git: false }); | ||
const subdir = join(fixture.cwd, 'some/other/sub/folder'); | ||
expect(await getGitRoot(subdir)).toBeNull(); | ||
await fixture.clean(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { resolve, dirname } = require('path'); | ||
const { pathExists } = require('fs-extra'); | ||
|
||
async function getGitRoot(dir) { | ||
var gitFolder = resolve(dir, '.git'); | ||
const exists = await pathExists(gitFolder); | ||
if (exists) { | ||
return dir; | ||
} | ||
const newDir = dirname(dir); | ||
// Reached top | ||
if (dir === newDir) { | ||
return null; | ||
} | ||
|
||
return getGitRoot(newDir); | ||
} | ||
|
||
module.exports = getGitRoot; |
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