@simbo/git-changes 4.0.0 → 4.1.1

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @simbo/git-changes
2
2
 
3
+ ## 4.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - @simbo/find-git-repository-root@3.0.1
8
+
9
+ ## 4.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - d6894f3: Run `git status` with `@simbo/git-exec` instead of `execa`.
14
+
15
+ - `execa` is no longer a dependency.
16
+ - If `git status` fails, the message after `Failed to get Git changes:` is the
17
+ message of the `GitError`, with the command, the exit code, and the standard
18
+ error output, and `cause` is that `GitError` instead of an `ExecaError`.
19
+
20
+ Code that matches the error message beyond its prefix or checks `cause` for an
21
+ `ExecaError` needs an update.
22
+
3
23
  ## 4.0.0
4
24
 
5
25
  ### Major Changes
@@ -1,6 +1,6 @@
1
1
  import { cwd } from 'node:process';
2
2
  import { findGitRepositoryRoot } from '@simbo/find-git-repository-root';
3
- import { execa, ExecaError } from 'execa';
3
+ import { gitBuffer } from '@simbo/git-exec';
4
4
  import { parseGitStatusOutput } from './parse-git-status-output.js';
5
5
  /**
6
6
  * Gets the uncommitted Git changes in the specified working directory.
@@ -32,16 +32,15 @@ export async function getGitChanges(workingDir = cwd()) {
32
32
  * 'UU conflicted.ts\0'
33
33
  * 'R new.ts\0old.ts\0'
34
34
  * 'C copied.ts\0source.ts\0'
35
+ *
36
+ * The output is read as buffer, because `git()` trims the leading space of
37
+ * the first entry.
35
38
  */
36
- const { stdout: output } = await execa({ cwd: repoRoot }) `git status --porcelain --null --untracked-files=all`;
37
- return parseGitStatusOutput(output);
39
+ const output = await gitBuffer(['status', '--porcelain', '--null', '--untracked-files=all'], { cwd: repoRoot });
40
+ return parseGitStatusOutput(output.toString('utf8'));
38
41
  }
39
42
  catch (error) {
40
- const reason = error instanceof ExecaError
41
- ? error.shortMessage
42
- : error instanceof Error
43
- ? error.message
44
- : `Unknown error (${String(error)})`;
43
+ const reason = error instanceof Error ? error.message : `Unknown error (${String(error)})`;
45
44
  throw new Error(`Failed to get Git changes: ${reason}`, { cause: error });
46
45
  }
47
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"get-git-changes.js","sourceRoot":"","sources":["../src/get-git-changes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAG1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,UAAU,GAAG,GAAG,EAAE;IACpD,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAEzD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,kBAAkB,UAAU,oCAAoC,CAAC,CAAC;IACpF,CAAC;IAED,IAAI,CAAC;QACH;;;;;;;;;;;;;;;;;;WAkBG;QACH,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAA,qDAAqD,CAAC;QAE/G,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GACV,KAAK,YAAY,UAAU;YACzB,CAAC,CAAC,KAAK,CAAC,YAAY;YACpB,CAAC,CAAC,KAAK,YAAY,KAAK;gBACtB,CAAC,CAAC,KAAK,CAAC,OAAO;gBACf,CAAC,CAAC,kBAAkB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,8BAA8B,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC","sourcesContent":["import { cwd } from 'node:process';\n\nimport { findGitRepositoryRoot } from '@simbo/find-git-repository-root';\nimport { execa, ExecaError } from 'execa';\n\nimport type { GitChange } from './git-changes.types.js';\nimport { parseGitStatusOutput } from './parse-git-status-output.js';\n\n/**\n * Gets the uncommitted Git changes in the specified working directory.\n *\n * @param workingDir - The working directory of the Git repository. Defaults to the current working directory.\n * @returns A ReadonlyMap of file paths to their corresponding GitChange objects.\n */\nexport async function getGitChanges(workingDir = cwd()): Promise<ReadonlyMap<string, GitChange>> {\n const repoRoot = await findGitRepositoryRoot(workingDir);\n\n if (!repoRoot) {\n throw new Error(`The directory \"${workingDir}\" is not part of a Git repository.`);\n }\n\n try {\n /**\n * This command provides a machine-readable, null-separated output of the\n * current status of the Git repository, including staged and unstaged changes,\n * as well as untracked files. Untracked directories are listed as individual\n * files, regardless of the `status.showUntrackedFiles` configuration.\n * Paths are relative to the repository root.\n *\n * Example output (renamed and copied entries list the new path first):\n * '?? untracked.ts\\0'\n * ' M unstaged-modified.ts\\0'\n * 'M staged-modified.ts\\0'\n * 'MM both-modified.ts\\0'\n * ' D unstaged-deleted.ts\\0'\n * 'A staged-added.ts\\0'\n * ' T type-changed.ts\\0'\n * 'UU conflicted.ts\\0'\n * 'R new.ts\\0old.ts\\0'\n * 'C copied.ts\\0source.ts\\0'\n */\n const { stdout: output } = await execa({ cwd: repoRoot })`git status --porcelain --null --untracked-files=all`;\n\n return parseGitStatusOutput(output);\n } catch (error) {\n const reason =\n error instanceof ExecaError\n ? error.shortMessage\n : error instanceof Error\n ? error.message\n : `Unknown error (${String(error)})`;\n throw new Error(`Failed to get Git changes: ${reason}`, { cause: error });\n }\n}\n"]}
1
+ {"version":3,"file":"get-git-changes.js","sourceRoot":"","sources":["../src/get-git-changes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,UAAU,GAAG,GAAG,EAAE;IACpD,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAEzD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,kBAAkB,UAAU,oCAAoC,CAAC,CAAC;IACpF,CAAC;IAED,IAAI,CAAC;QACH;;;;;;;;;;;;;;;;;;;;;WAqBG;QACH,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,uBAAuB,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEhH,OAAO,oBAAoB,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;QAC3F,MAAM,IAAI,KAAK,CAAC,8BAA8B,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC","sourcesContent":["import { cwd } from 'node:process';\n\nimport { findGitRepositoryRoot } from '@simbo/find-git-repository-root';\nimport { gitBuffer } from '@simbo/git-exec';\n\nimport type { GitChange } from './git-changes.types.js';\nimport { parseGitStatusOutput } from './parse-git-status-output.js';\n\n/**\n * Gets the uncommitted Git changes in the specified working directory.\n *\n * @param workingDir - The working directory of the Git repository. Defaults to the current working directory.\n * @returns A ReadonlyMap of file paths to their corresponding GitChange objects.\n */\nexport async function getGitChanges(workingDir = cwd()): Promise<ReadonlyMap<string, GitChange>> {\n const repoRoot = await findGitRepositoryRoot(workingDir);\n\n if (!repoRoot) {\n throw new Error(`The directory \"${workingDir}\" is not part of a Git repository.`);\n }\n\n try {\n /**\n * This command provides a machine-readable, null-separated output of the\n * current status of the Git repository, including staged and unstaged changes,\n * as well as untracked files. Untracked directories are listed as individual\n * files, regardless of the `status.showUntrackedFiles` configuration.\n * Paths are relative to the repository root.\n *\n * Example output (renamed and copied entries list the new path first):\n * '?? untracked.ts\\0'\n * ' M unstaged-modified.ts\\0'\n * 'M staged-modified.ts\\0'\n * 'MM both-modified.ts\\0'\n * ' D unstaged-deleted.ts\\0'\n * 'A staged-added.ts\\0'\n * ' T type-changed.ts\\0'\n * 'UU conflicted.ts\\0'\n * 'R new.ts\\0old.ts\\0'\n * 'C copied.ts\\0source.ts\\0'\n *\n * The output is read as buffer, because `git()` trims the leading space of\n * the first entry.\n */\n const output = await gitBuffer(['status', '--porcelain', '--null', '--untracked-files=all'], { cwd: repoRoot });\n\n return parseGitStatusOutput(output.toString('utf8'));\n } catch (error) {\n const reason = error instanceof Error ? error.message : `Unknown error (${String(error)})`;\n throw new Error(`Failed to get Git changes: ${reason}`, { cause: error });\n }\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simbo/git-changes",
3
3
  "description": "A library to read, parse and provide Git changes information from `git status` for a local repository.",
4
- "version": "4.0.0",
4
+ "version": "4.1.1",
5
5
  "keywords": [
6
6
  "git",
7
7
  "changes",
@@ -37,12 +37,13 @@
37
37
  "README.md"
38
38
  ],
39
39
  "dependencies": {
40
- "@simbo/find-git-repository-root": "3.0.0",
41
- "execa": "^10.2.1"
40
+ "@simbo/find-git-repository-root": "3.0.1",
41
+ "@simbo/git-exec": "1.0.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@simbo/eslint-config": "5.0.0",
45
- "@simbo/tsconfig": "3.0.0",
45
+ "@simbo/git-fixture": "1.0.1",
46
+ "@simbo/tsconfig": "3.0.1",
46
47
  "@types/node": "^24.19.2",
47
48
  "@vitest/coverage-v8": "^5.1.1",
48
49
  "@vitest/ui": "^5.1.1",