@pnpm/network.git-utils 1100.0.1 → 1100.0.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ # @pnpm/network.git-utils
2
+
3
+ ## 1100.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Republished every package: the tarballs published by the v11.13.1 through v11.16.0 releases were missing most of their compiled files due to a packing bug [#13164](https://github.com/pnpm/pnpm/issues/13164).
package/lib/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
1
3
  import { safeExeca as execa } from 'execa';
2
4
  export async function isGitRepo(opts = {}) {
3
5
  try {
@@ -9,6 +11,9 @@ export async function isGitRepo(opts = {}) {
9
11
  return true;
10
12
  }
11
13
  export async function getCurrentBranch(opts = {}) {
14
+ const branch = readBranchFromHeadFile(opts.cwd);
15
+ if (branch !== undefined)
16
+ return branch;
12
17
  try {
13
18
  const { stdout } = await execa('git', ['symbolic-ref', '--short', 'HEAD'], { cwd: opts.cwd });
14
19
  return stdout;
@@ -44,4 +49,51 @@ export async function isRemoteHistoryClean(opts = {}) {
44
49
  }
45
50
  return true;
46
51
  }
52
+ /**
53
+ * Reads the current branch name from `.git/HEAD` without spawning a git subprocess.
54
+ *
55
+ * Returns:
56
+ * - `string` — the branch name extracted from `ref: refs/heads/<name>`
57
+ * - `null` — HEAD is detached (a raw commit SHA, not a symbolic ref)
58
+ * - `undefined` — `.git/HEAD` could not be read (not a git repo, worktree
59
+ * layout not recognized, permissions error, etc.); caller should fall
60
+ * back to `git symbolic-ref`.
61
+ */
62
+ function readBranchFromHeadFile(cwd) {
63
+ const baseDir = cwd ?? process.cwd();
64
+ const dotGitPath = path.join(baseDir, '.git');
65
+ let gitDir;
66
+ try {
67
+ const stat = fs.statSync(dotGitPath);
68
+ if (stat.isDirectory()) {
69
+ gitDir = dotGitPath;
70
+ }
71
+ else if (stat.isFile()) {
72
+ // `.git` is a file — worktree or submodule. It contains `gitdir: <path>`.
73
+ const content = fs.readFileSync(dotGitPath, 'utf8').trim();
74
+ const match = content.match(/^gitdir:\s*(.+)/);
75
+ if (!match)
76
+ return undefined;
77
+ gitDir = path.isAbsolute(match[1]) ? match[1] : path.resolve(baseDir, match[1]);
78
+ }
79
+ else {
80
+ // `.git` is neither a directory nor a regular file (e.g. a FIFO or
81
+ // device); don't read it. Fall back to `git symbolic-ref`.
82
+ return undefined;
83
+ }
84
+ }
85
+ catch {
86
+ return undefined;
87
+ }
88
+ try {
89
+ const head = fs.readFileSync(path.join(gitDir, 'HEAD'), 'utf8').trim();
90
+ const match = head.match(/^ref:\s*refs\/heads\/(.+)/);
91
+ if (match)
92
+ return match[1];
93
+ return null;
94
+ }
95
+ catch {
96
+ return undefined;
97
+ }
98
+ }
47
99
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/network.git-utils",
3
- "version": "1100.0.1",
3
+ "version": "1100.0.3",
4
4
  "description": "Utilities for git",
5
5
  "keywords": [
6
6
  "pnpm",
@@ -10,8 +10,11 @@
10
10
  ],
11
11
  "license": "MIT",
12
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",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/pnpm/pnpm/tree/main/pnpm11/network/git-utils"
16
+ },
17
+ "homepage": "https://github.com/pnpm/pnpm/tree/main/pnpm11/network/git-utils#readme",
15
18
  "bugs": {
16
19
  "url": "https://github.com/pnpm/pnpm/issues"
17
20
  },
@@ -29,9 +32,9 @@
29
32
  "execa": "npm:safe-execa@0.3.0"
30
33
  },
31
34
  "devDependencies": {
32
- "@jest/globals": "30.3.0",
33
- "tempy": "3.0.0",
34
- "@pnpm/network.git-utils": "1100.0.1"
35
+ "@jest/globals": "30.4.1",
36
+ "@pnpm/network.git-utils": "1100.0.3",
37
+ "tempy": "3.0.0"
35
38
  },
36
39
  "engines": {
37
40
  "node": ">=22.13"