@pnpm/network.git-utils 1000.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
4
+ Copyright (c) 2016-2026 Zoltan Kochan and other contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # @pnpm/git-utils
2
+
3
+ > Utilities for git
4
+
5
+ <!--@shields('npm')-->
6
+ [![npm version](https://img.shields.io/npm/v/@pnpm/git-utils.svg)](https://www.npmjs.com/package/@pnpm/git-utils)
7
+ <!--/@-->
8
+
9
+ ## Installation
10
+
11
+ ```
12
+ pnpm add @pnpm/git-utils
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ <!--@example('./example.js')-->
18
+ ```js
19
+ 'use strict'
20
+ const { getCurrentBranchName } = require('@pnpm-utils').default
21
+
22
+ main()
23
+ async function main() {
24
+ const branchName = await getCurrentBranch();
25
+ console.log(branchName)
26
+ }
27
+ ```
28
+ <!--/@-->
29
+
30
+ # License
31
+
32
+ MIT
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare function isGitRepo(): Promise<boolean>;
2
+ export declare function getCurrentBranch(): Promise<string | null>;
3
+ export declare function isWorkingTreeClean(): Promise<boolean>;
4
+ export declare function isRemoteHistoryClean(): Promise<boolean>;
package/lib/index.js ADDED
@@ -0,0 +1,48 @@
1
+ import { safeExeca as execa } from 'execa';
2
+ // git checks logic is from https://github.com/sindresorhus/np/blob/master/source/git-tasks.js
3
+ export async function isGitRepo() {
4
+ try {
5
+ await execa('git', ['rev-parse', '--git-dir']);
6
+ }
7
+ catch {
8
+ return false;
9
+ }
10
+ return true;
11
+ }
12
+ export async function getCurrentBranch() {
13
+ try {
14
+ const { stdout } = await execa('git', ['symbolic-ref', '--short', 'HEAD']);
15
+ return stdout;
16
+ }
17
+ catch {
18
+ // Command will fail with code 1 if the HEAD is detached.
19
+ return null;
20
+ }
21
+ }
22
+ export async function isWorkingTreeClean() {
23
+ try {
24
+ const { stdout: status } = await execa('git', ['status', '--porcelain']);
25
+ if (status !== '') {
26
+ return false;
27
+ }
28
+ return true;
29
+ }
30
+ catch {
31
+ return false;
32
+ }
33
+ }
34
+ export async function isRemoteHistoryClean() {
35
+ let history;
36
+ try { // Gracefully handle no remote set up.
37
+ const { stdout } = await execa('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']);
38
+ history = stdout;
39
+ }
40
+ catch {
41
+ history = null;
42
+ }
43
+ if (history && history !== '0') {
44
+ return false;
45
+ }
46
+ return true;
47
+ }
48
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@pnpm/network.git-utils",
3
+ "version": "1000.0.0",
4
+ "description": "Utilities for git",
5
+ "keywords": [
6
+ "pnpm",
7
+ "pnpm11",
8
+ "git",
9
+ "npm"
10
+ ],
11
+ "license": "MIT",
12
+ "funding": "https://opencollective.com/pnpm",
13
+ "repository": "https://github.com/pnpm/pnpm/tree/main/network/git-utils",
14
+ "homepage": "https://github.com/pnpm/pnpm/tree/main/network/git-utils#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/pnpm/pnpm/issues"
17
+ },
18
+ "type": "module",
19
+ "main": "lib/index.js",
20
+ "types": "lib/index.d.ts",
21
+ "exports": {
22
+ ".": "./lib/index.js"
23
+ },
24
+ "files": [
25
+ "lib",
26
+ "!*.map"
27
+ ],
28
+ "dependencies": {
29
+ "execa": "npm:safe-execa@0.3.0"
30
+ },
31
+ "devDependencies": {
32
+ "tempy": "3.0.0",
33
+ "@pnpm/network.git-utils": "1000.0.0"
34
+ },
35
+ "engines": {
36
+ "node": ">=22.13"
37
+ },
38
+ "jest": {
39
+ "preset": "@pnpm/jest-config"
40
+ },
41
+ "scripts": {
42
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
43
+ "_test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest",
44
+ "test": "pnpm run compile && pnpm run _test",
45
+ "fix": "tslint -c tslint.json src/**/*.ts test/**/*.ts --fix",
46
+ "compile-only": "tsc --build",
47
+ "compile": "tsgo --build && pnpm run lint --fix"
48
+ }
49
+ }