@simbo/is-git-repository-root 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/LICENSE.md +20 -0
- package/README.md +53 -0
- package/dist/is-git-repository-root.d.ts +11 -0
- package/dist/is-git-repository-root.js +24 -0
- package/dist/is-git-repository-root.js.map +1 -0
- package/package.json +67 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @simbo/is-git-repository-root
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 5092b1b: Initial Release
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [cc73cb0]
|
|
12
|
+
- Updated dependencies [cc9dd53]
|
|
13
|
+
- @simbo/git-constants@1.0.0
|
|
14
|
+
- @simbo/accessible@1.0.0
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2025 Simon Lepel <simbo@simbo.de> (https://simbo.de)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Is Git Repository Root
|
|
2
|
+
|
|
3
|
+
[📦 **`@simbo/is-git-repository-root`**](https://npmjs.com/package/@simbo/is-git-repository-root)
|
|
4
|
+
|
|
5
|
+
A lightweight utility for checking whether a directory is the root of a Git
|
|
6
|
+
repository.
|
|
7
|
+
|
|
8
|
+
It simply checks for the presence of a `.git` folder in the given directory.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- Detects if a directory is the root of a Git repository
|
|
13
|
+
|
|
14
|
+
- Defaults to checking the **current working directory**
|
|
15
|
+
|
|
16
|
+
- Async and Promise-based API
|
|
17
|
+
|
|
18
|
+
- Fully typed with TypeScript
|
|
19
|
+
|
|
20
|
+
- Zero dependencies (besides other `@simbo/*` packages)
|
|
21
|
+
|
|
22
|
+
⚠️ Git submodules and worktrees are not considered repository roots.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
Install `@simbo/is-git-repository-root` from the npm registry:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm i [-D] @simbo/is-git-repository-root
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
For a complete API reference, see the
|
|
35
|
+
[documentation](https://simbo.codes/packages/modules/_simbo_is-git-repository-root/).
|
|
36
|
+
|
|
37
|
+
### Example
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { isGitRepositoryRoot } from '@simbo/is-git-repository-root';
|
|
41
|
+
|
|
42
|
+
if (await isGitRepositoryRoot()) {
|
|
43
|
+
console.log('This is a Git repository root.');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (await isGitRepositoryRoot('/path/to/dir')) {
|
|
47
|
+
console.log('That directory is a Git repository root.');
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
[MIT © Simon Lepel](http://simbo.mit-license.org/2025/)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given directory is the root of a git repository.
|
|
3
|
+
*
|
|
4
|
+
* Only succeeds on directories that contain a `.git` folder.
|
|
5
|
+
*
|
|
6
|
+
* Git submodules or worktrees are not considered as roots.
|
|
7
|
+
*
|
|
8
|
+
* @param workingDir - The directory in which to check for the Git root. Defaults to the current working directory.
|
|
9
|
+
* @returns A promise that resolves to true if the directory is a Git root, false otherwise.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isGitRepositoryRoot(workingDir?: string): Promise<boolean>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { cwd } from 'node:process';
|
|
3
|
+
import { isDirectory } from '@simbo/accessible';
|
|
4
|
+
import { GIT_FOLDER } from '@simbo/git-constants';
|
|
5
|
+
/**
|
|
6
|
+
* Checks if the given directory is the root of a git repository.
|
|
7
|
+
*
|
|
8
|
+
* Only succeeds on directories that contain a `.git` folder.
|
|
9
|
+
*
|
|
10
|
+
* Git submodules or worktrees are not considered as roots.
|
|
11
|
+
*
|
|
12
|
+
* @param workingDir - The directory in which to check for the Git root. Defaults to the current working directory.
|
|
13
|
+
* @returns A promise that resolves to true if the directory is a Git root, false otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export async function isGitRepositoryRoot(workingDir = cwd()) {
|
|
16
|
+
try {
|
|
17
|
+
const path = resolve(workingDir, GIT_FOLDER);
|
|
18
|
+
return await isDirectory(path);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=is-git-repository-root.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-git-repository-root.js","sourceRoot":"","sources":["../src/is-git-repository-root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,UAAU,GAAG,GAAG,EAAE;IAC1D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAC7C,OAAO,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@simbo/is-git-repository-root",
|
|
3
|
+
"description": "A lightweight utility for checking whether a directory is the root of a Git repository.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"git",
|
|
7
|
+
"repository",
|
|
8
|
+
"root",
|
|
9
|
+
"is-root",
|
|
10
|
+
"git-root",
|
|
11
|
+
"detect",
|
|
12
|
+
"check",
|
|
13
|
+
"directory",
|
|
14
|
+
"cli",
|
|
15
|
+
"utility",
|
|
16
|
+
"typescript"
|
|
17
|
+
],
|
|
18
|
+
"author": "Simon Lepel <simbo@simbo.de> (https://simbo.de/)",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "http://github.com/simbo/packages/tree/main/packages/is-git-repository-root",
|
|
21
|
+
"repository": "github:simbo/packages",
|
|
22
|
+
"bugs": "https://github.com/simbo/packages/issues",
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": "./dist/is-git-repository-root.js"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"CHANGELOG.md",
|
|
32
|
+
"dist",
|
|
33
|
+
"LICENSE.md",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@simbo/accessible": "1.0.0",
|
|
38
|
+
"@simbo/git-constants": "1.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.6.2",
|
|
42
|
+
"@types/node": "^20.19.11",
|
|
43
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
44
|
+
"@vitest/ui": "^3.2.4",
|
|
45
|
+
"eslint": "^9.34.0",
|
|
46
|
+
"jiti": "^2.5.1",
|
|
47
|
+
"prettier": "^3.6.2",
|
|
48
|
+
"prettier-plugin-organize-attributes": "^1.0.0",
|
|
49
|
+
"typescript": "^5.9.2",
|
|
50
|
+
"vitest": "^3.2.4",
|
|
51
|
+
"@simbo/eslint-config": "1.0.2",
|
|
52
|
+
"@simbo/prettier-config": "1.0.3",
|
|
53
|
+
"@simbo/tsconfig": "1.0.3"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsc --project tsconfig.build.json",
|
|
57
|
+
"check:eslint": "eslint --config ./eslint.config.ts --max-warnings 0",
|
|
58
|
+
"check:format": "prettier --check .",
|
|
59
|
+
"check:types": "tsc --noEmit",
|
|
60
|
+
"clean:dist": "rm -rf dist",
|
|
61
|
+
"fix:eslint": "pnpm run check:eslint --fix",
|
|
62
|
+
"fix:format": "prettier --write .",
|
|
63
|
+
"test": "vitest run --coverage",
|
|
64
|
+
"test:ui": "pnpm run test:watch --ui",
|
|
65
|
+
"test:watch": "vitest dev --coverage"
|
|
66
|
+
}
|
|
67
|
+
}
|