workspace-tools 0.41.5 → 0.41.7

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.
Files changed (60) hide show
  1. package/lib/git/branchRefs.d.ts +36 -0
  2. package/lib/git/branchRefs.js +84 -0
  3. package/lib/git/branchRefs.js.map +1 -0
  4. package/lib/git/config.d.ts +16 -0
  5. package/lib/git/config.js +39 -4
  6. package/lib/git/config.js.map +1 -1
  7. package/lib/git/fetchRemote.d.ts +13 -0
  8. package/lib/git/fetchRemote.js +56 -0
  9. package/lib/git/fetchRemote.js.map +1 -0
  10. package/lib/git/getChanges.d.ts +54 -0
  11. package/lib/git/getChanges.js +138 -0
  12. package/lib/git/getChanges.js.map +1 -0
  13. package/lib/git/getCurrentHash.d.ts +8 -0
  14. package/lib/git/getCurrentHash.js +24 -0
  15. package/lib/git/getCurrentHash.js.map +1 -0
  16. package/lib/git/getDefaultRemote.d.ts +14 -3
  17. package/lib/git/getDefaultRemote.js +92 -53
  18. package/lib/git/getDefaultRemote.js.map +1 -1
  19. package/lib/git/getDefaultRemoteBranch.d.ts +29 -2
  20. package/lib/git/getDefaultRemoteBranch.js +61 -21
  21. package/lib/git/getDefaultRemoteBranch.js.map +1 -1
  22. package/lib/git/getFileAddedHash.d.ts +10 -0
  23. package/lib/git/getFileAddedHash.js +24 -0
  24. package/lib/git/getFileAddedHash.js.map +1 -0
  25. package/lib/git/getFileFromRef.d.ts +11 -0
  26. package/lib/git/getFileFromRef.js +22 -0
  27. package/lib/git/getFileFromRef.js.map +1 -0
  28. package/lib/git/getRecentCommitMessages.d.ts +10 -0
  29. package/lib/git/getRecentCommitMessages.js +27 -0
  30. package/lib/git/getRecentCommitMessages.js.map +1 -0
  31. package/lib/git/getRemotes.d.ts +14 -0
  32. package/lib/git/getRemotes.js +53 -0
  33. package/lib/git/getRemotes.js.map +1 -0
  34. package/lib/git/gitUtilities.d.ts +12 -212
  35. package/lib/git/gitUtilities.js +38 -448
  36. package/lib/git/gitUtilities.js.map +1 -1
  37. package/lib/git/index.d.ts +17 -5
  38. package/lib/git/index.js +123 -17
  39. package/lib/git/index.js.map +1 -1
  40. package/lib/git/init.d.ts +11 -0
  41. package/lib/git/init.js +48 -0
  42. package/lib/git/init.js.map +1 -0
  43. package/lib/git/listAllTrackedFiles.d.ts +12 -0
  44. package/lib/git/listAllTrackedFiles.js +25 -0
  45. package/lib/git/listAllTrackedFiles.js.map +1 -0
  46. package/lib/git/parseRemoteBranch.d.ts +26 -0
  47. package/lib/git/parseRemoteBranch.js +77 -0
  48. package/lib/git/parseRemoteBranch.js.map +1 -0
  49. package/lib/git/revertLocalChanges.d.ts +9 -0
  50. package/lib/git/revertLocalChanges.js +42 -0
  51. package/lib/git/revertLocalChanges.js.map +1 -0
  52. package/lib/git/stageAndCommit.d.ts +21 -0
  53. package/lib/git/stageAndCommit.js +69 -0
  54. package/lib/git/stageAndCommit.js.map +1 -0
  55. package/lib/git/types.d.ts +5 -2
  56. package/lib/git/types.js.map +1 -1
  57. package/lib/workspaces/getCatalogVersion.d.ts +8 -3
  58. package/lib/workspaces/getCatalogVersion.js +9 -3
  59. package/lib/workspaces/getCatalogVersion.js.map +1 -1
  60. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/git/getRemotes.ts"],"sourcesContent":["import { git, GitError, type GitProcessOutput } from \"./git.js\";\nimport type { GitCommonOptions } from \"./types.js\";\n\n/**\n * Get a mapping from remote names to fetch URLs.\n *\n * Note this returns the URLs directly from `git config --local --get-regexp 'remote\\..*\\.url'`,\n * which doesn't respect any `url.<base>.insteadOf` remappings (such as for ssh). This should be\n * fine for current usage: `parseRemoteBranch` only needs the names, and `getDefaultRemote`\n * compares parsed URLs from `package.json` `repository` and should be flexible about formats.\n *\n * If `options.throwOnError` is true, throws if no remotes are found or `cwd` isn't in a git repo.\n *\n * @returns An object mapping remote names to URLs.\n */\nexport function getRemotes(options: GitCommonOptions): Record<string, string> {\n let remotesResult: GitProcessOutput;\n try {\n // Get remote names and URLs, similar to `git remote -v` but without localization concerns.\n // --local ensures it errors if cwd is not in a git repo.\n remotesResult = git([\"config\", \"--local\", \"--get-regexp\", \"remote\\\\..*\\\\.url\"], {\n ...options,\n description: \"Getting git remotes\",\n });\n } catch (e) {\n if (e instanceof GitError) {\n if (e.gitOutput?.status === 1) {\n // Per git config docs, 1 means the key wasn't found, so fail with a clearer message\n // (this case will only be hit with throwOnError: true)\n throw new GitError(`No remotes defined in git repo at ${options.cwd}`, undefined, e.gitOutput);\n }\n if (e.gitOutput?.status === 128) {\n // 128 most commonly means not a git repository\n throw new GitError(`${options.cwd} is not in a git repository`, undefined, e.gitOutput);\n }\n }\n throw e;\n }\n\n if (!remotesResult.success) {\n // throwOnError was false/unset but no remotes were found\n return {};\n }\n\n const remotes: Record<string, string> = {};\n const remoteLines = remotesResult.stdout.trim().split(\"\\n\");\n for (const line of remoteLines) {\n const remoteMatch = line.match(/^remote\\.(.+?)\\.url\\s+(.*)$/);\n if (!remoteMatch) continue;\n const [, remoteName, remoteUrl] = remoteMatch;\n remotes[remoteName] = remoteUrl;\n }\n\n return remotes;\n}\n"],"names":["getRemotes","options","remotesResult","git","description","e","GitError","gitOutput","status","cwd","undefined","success","remotes","remoteLines","stdout","trim","split","line","remoteMatch","match","remoteName","remoteUrl"],"mappings":";;;;+BAegBA;;;eAAAA;;;qBAfqC;AAe9C,SAASA,WAAWC,OAAyB;IAClD,IAAIC;IACJ,IAAI;QACF,2FAA2F;QAC3F,yDAAyD;QACzDA,gBAAgBC,IAAAA,QAAG,EAAC;YAAC;YAAU;YAAW;YAAgB;SAAoB,EAAE;YAC9E,GAAGF,OAAO;YACVG,aAAa;QACf;IACF,EAAE,OAAOC,GAAG;QACV,IAAIA,aAAaC,aAAQ,EAAE;YACzB,IAAID,EAAEE,SAAS,EAAEC,WAAW,GAAG;gBAC7B,oFAAoF;gBACpF,uDAAuD;gBACvD,MAAM,IAAIF,aAAQ,CAAC,CAAC,kCAAkC,EAAEL,QAAQQ,GAAG,EAAE,EAAEC,WAAWL,EAAEE,SAAS;YAC/F;YACA,IAAIF,EAAEE,SAAS,EAAEC,WAAW,KAAK;gBAC/B,+CAA+C;gBAC/C,MAAM,IAAIF,aAAQ,CAAC,GAAGL,QAAQQ,GAAG,CAAC,2BAA2B,CAAC,EAAEC,WAAWL,EAAEE,SAAS;YACxF;QACF;QACA,MAAMF;IACR;IAEA,IAAI,CAACH,cAAcS,OAAO,EAAE;QAC1B,yDAAyD;QACzD,OAAO,CAAC;IACV;IAEA,MAAMC,UAAkC,CAAC;IACzC,MAAMC,cAAcX,cAAcY,MAAM,CAACC,IAAI,GAAGC,KAAK,CAAC;IACtD,KAAK,MAAMC,QAAQJ,YAAa;QAC9B,MAAMK,cAAcD,KAAKE,KAAK,CAAC;QAC/B,IAAI,CAACD,aAAa;QAClB,MAAM,GAAGE,YAAYC,UAAU,GAAGH;QAClCN,OAAO,CAACQ,WAAW,GAAGC;IACxB;IAEA,OAAOT;AACT"}
@@ -1,218 +1,18 @@
1
- import type { GetChangesBetweenRefsOptions, GitBranchOptions, GitCommitOptions, GitCommonOptions, GitFetchOptions, GitInitOptions, GitStageOptions, ParsedRemoteBranch, ParseRemoteBranchOptions } from "./types.js";
2
- /**
3
- * Get a list of files with untracked changes.
4
- * Throws an error on failure by default.
5
- *
6
- * @returns An array of file paths with untracked changes
7
- */
8
- export declare function getUntrackedChanges(options: GitCommonOptions): string[];
9
- /** @deprecated Use object params version */
10
- export declare function getUntrackedChanges(cwd: string): string[];
11
- /**
12
- * Fetch from the given remote (and optionally branch) or all remotes.
13
- * Throws an error on failure by default.
14
- */
15
- export declare function fetchRemote(options: GitFetchOptions): void;
16
- /** @deprecated Use object params version */
17
- export declare function fetchRemote(remote: string, cwd: string): void;
18
- /**
19
- * Fetch from the given remote and branch. Throws an error on failure.
20
- * @deprecated Use `fetchRemote({ remote, remoteBranch, cwd })`
21
- */
22
- export declare function fetchRemoteBranch(remote: string, remoteBranch: string, cwd: string): void;
23
- /**
24
- * Gets file paths with changes that have not been staged yet.
25
- * Throws an error on failure by default.
26
- *
27
- * @returns An array of relative file paths with unstaged changes
28
- */
29
- export declare function getUnstagedChanges(options: GitCommonOptions): string[];
30
- /** @deprecated Use object params version */
31
- export declare function getUnstagedChanges(cwd: string): string[];
32
- /**
33
- * Gets file paths with changes between the current branch and the given branch.
34
- * Throws an error on failure.
35
- *
36
- * @returns An array of relative file paths that have changed
37
- * @deprecated Use `getBranchChanges({ branch, cwd })`
38
- */
39
- export declare function getChanges(branch: string, cwd: string): string[];
40
- /**
41
- * Gets file paths with changes between the branch and the merge-base.
42
- * Throws an error on failure by default.
43
- *
44
- * @returns An array of relative file paths that have changed
45
- */
46
- export declare function getBranchChanges(options: GitBranchOptions): string[];
47
- /** @deprecated Use object params version */
48
- export declare function getBranchChanges(branch: string, cwd: string): string[];
49
- /**
50
- * Gets file paths with changes between two git references (commits, branches, tags).
51
- * Throws an error on failure by default.
52
- *
53
- * @returns An array of file paths that have changed
54
- */
55
- export declare function getChangesBetweenRefs(options: GetChangesBetweenRefsOptions): string[];
56
- /** @deprecated Use object param version */
57
- export declare function getChangesBetweenRefs(fromRef: string, toRef: string, options: string[], pattern: string, cwd: string): string[];
58
- /**
59
- * Gets all files with staged changes (files added to the index).
60
- * Throws an error on failure by default.
61
- *
62
- * @returns An array of relative file paths that have been staged
63
- */
64
- export declare function getStagedChanges(options: GitCommonOptions): string[];
65
- /** @deprecated Use object params version */
66
- export declare function getStagedChanges(cwd: string): string[];
67
- /**
68
- * Gets recent commit messages between the specified parent branch and HEAD.
69
- * By default, returns an empty array if the operation fails.
70
- *
71
- * @returns An array of commit message strings
72
- */
73
- export declare function getRecentCommitMessages(options: GitBranchOptions): string[];
74
- /** @deprecated Use object params version */
75
- export declare function getRecentCommitMessages(branch: string, cwd: string): string[];
76
- /**
77
- * Gets the user email from the git config.
78
- * @returns The email string if found, null otherwise
79
- */
80
- export declare function getUserEmail(options: GitCommonOptions): string | null;
81
- /** @deprecated Use object params version */
82
- export declare function getUserEmail(cwd: string): string | null;
83
- /**
84
- * Gets the current branch name.
85
- * In detached HEAD state, returns "HEAD".
86
- *
87
- * @returns The branch name if successful, null otherwise
88
- */
89
- export declare function getBranchName(options: GitCommonOptions): string | null;
90
- /** @deprecated Use object params version */
91
- export declare function getBranchName(cwd: string): string | null;
92
- /**
93
- * Gets the full reference path for a given branch.
94
- * `branch` here is the short branch name, e.g. `branch-name`.
95
- * @returns The full branch reference (e.g., `refs/heads/branch-name`) if found, null otherwise
96
- */
97
- export declare function getFullBranchRef(options: GitBranchOptions): string | null;
98
- /** @deprecated Use object params version */
99
- export declare function getFullBranchRef(branch: string, cwd: string): string | null;
100
- /**
101
- * Gets the short branch name from a full branch reference.
102
- * @returns The short branch name if successful, null otherwise
103
- */
104
- export declare function getShortBranchName(options: {
105
- /** The full branch reference (e.g., `refs/heads/branch-name`) */
106
- fullBranchRef: string;
107
- } & GitCommonOptions): string | null;
108
- /** @deprecated Use object params version */
109
- export declare function getShortBranchName(fullBranchRef: string, cwd: string): string | null;
110
- /**
111
- * Gets the current commit hash (SHA).
112
- * @returns The hash if successful, null otherwise
113
- */
114
- export declare function getCurrentHash(options: GitCommonOptions): string | null;
115
- /** @deprecated Use object params version */
116
- export declare function getCurrentHash(cwd: string): string | null;
117
- /**
118
- * Get the commit hash in which the file was first added.
119
- * @returns The commit hash if found, undefined otherwise
120
- */
121
- export declare function getFileAddedHash(options: {
122
- filename: string;
123
- } & GitCommonOptions): string | undefined;
124
- /** @deprecated Use object params version */
125
- export declare function getFileAddedHash(filename: string, cwd: string): string | undefined;
126
- /**
127
- * Run `git init` and verify that the `user.name` and `user.email` configs are set (at any level).
128
- * Throws an error if `git init` fails.
129
- *
130
- * If `user.email` and `user.name` aren't already set globally, and the missing value is provided
131
- * in params, set it at the repo level. Otherwise, throw an error.
132
- */
133
- export declare function init(options: GitInitOptions): void;
134
- /** @deprecated Use object params version */
135
- export declare function init(cwd: string, email?: string, username?: string): void;
136
- /**
137
- * Stages files matching the given patterns.
138
- */
139
- export declare function stage(options: GitStageOptions): void;
140
- /** @deprecated Use object params version */
141
- export declare function stage(patterns: string[], cwd: string): void;
142
- /**
143
- * Commit changes. Throws an error on failure by default.
144
- */
145
- export declare function commit(options: GitCommitOptions): void;
146
- /** @deprecated Use object params version */
147
- export declare function commit(message: string, cwd: string, options?: string[]): void;
148
- /**
149
- * Stages files matching the given patterns and creates a commit with the specified message.
150
- * Convenience function that combines `stage()` and `commit()`.
151
- * Throws an error on commit failure by default.
152
- */
153
- export declare function stageAndCommit(options: GitStageOptions & GitCommitOptions): void;
154
- /** @deprecated Use object params version */
155
- export declare function stageAndCommit(patterns: string[], message: string, cwd: string, commitOptions?: string[]): void;
156
- /**
157
- * Reverts all local changes (both staged and unstaged) by stashing them and then dropping the stash.
158
- * @returns True if the revert was successful, false otherwise. It will also be false if there were
159
- * no changes to revert. (To distinguish between this case and errors, use the `throwOnError` option.)
160
- */
161
- export declare function revertLocalChanges(options: GitCommonOptions): boolean;
162
- /** @deprecated Use object params version */
163
- export declare function revertLocalChanges(cwd: string): boolean;
1
+ export { getBranchName, getFullBranchRef, getRemoteBranch, getShortBranchName } from "./branchRefs.js";
2
+ export { getDefaultBranch, getUserEmail } from "./config.js";
3
+ export { fetchRemote, fetchRemoteBranch } from "./fetchRemote.js";
4
+ export { getBranchChanges, getChanges, getChangesBetweenRefs, getStagedChanges, getUnstagedChanges, getUntrackedChanges, } from "./getChanges.js";
5
+ export { getCurrentHash } from "./getCurrentHash.js";
6
+ export { getFileAddedHash } from "./getFileAddedHash.js";
7
+ export { getRecentCommitMessages } from "./getRecentCommitMessages.js";
8
+ export { init } from "./init.js";
9
+ export { listAllTrackedFiles } from "./listAllTrackedFiles.js";
10
+ export { parseRemoteBranch } from "./parseRemoteBranch.js";
11
+ export { revertLocalChanges } from "./revertLocalChanges.js";
12
+ export { commit, stage, stageAndCommit } from "./stageAndCommit.js";
164
13
  /**
165
14
  * Attempts to determine the parent branch of the current branch using `git show-branch`.
166
15
  * @returns The parent branch name if found, null otherwise
167
16
  * @deprecated Does not appear to be used
168
17
  */
169
18
  export declare function getParentBranch(cwd: string): string | null;
170
- /**
171
- * Gets the remote tracking branch for the specified branch.
172
- *
173
- * @returns The remote branch name (e.g., `origin/main`) if found, null otherwise
174
- */
175
- export declare function getRemoteBranch(options: GitBranchOptions): string | null;
176
- /** @deprecated Use object params version */
177
- export declare function getRemoteBranch(branch: string, cwd: string): string | null;
178
- /**
179
- * Get the remote and branch name from a full branch name that may include a remote prefix.
180
- * If the path doesn't start with one of `options.knownRemotes` (but has multiple segments),
181
- * the actual list of remotes will be fetched to see if one of those matches.
182
- *
183
- * NOTE: The additional verification is new in the object params version; the original version
184
- * incorrectly assumes the first segment before a slash is always a remote.
185
- */
186
- export declare function parseRemoteBranch(options: ParseRemoteBranchOptions): ParsedRemoteBranch;
187
- /**
188
- * @deprecated Use object params version, which does more verification. This version inaccurately
189
- * assumes the first segment before a slash is always a remote, which could lead to tricky bugs.
190
- */
191
- export declare function parseRemoteBranch(branch: string): ParsedRemoteBranch;
192
- /**
193
- * Gets the default branch based on `git config init.defaultBranch`, falling back to `master`.
194
- */
195
- export declare function getDefaultBranch(options: GitCommonOptions): string;
196
- /** @deprecated Use object params version */
197
- export declare function getDefaultBranch(cwd: string): string;
198
- /**
199
- * Lists all tracked files matching the given patterns.
200
- * Throws on error by default.
201
- * @returns An array of file paths, or an empty array if no files are found
202
- */
203
- export declare function listAllTrackedFiles(options: {
204
- /** File patterns to match (passed to git ls-files) */
205
- patterns: string[];
206
- } & GitCommonOptions): string[];
207
- /** @deprecated Use object params version */
208
- export declare function listAllTrackedFiles(patterns: string[], cwd: string): string[];
209
- /**
210
- * Get the content of a file at a specific git ref (commit, branch, tag, etc).
211
- * Returns undefined if the file doesn't exist at that ref or the command fails.
212
- */
213
- export declare function getFileFromVersion(params: {
214
- /** Repo-relative path to the file with *forward* slashes */
215
- filePath: string;
216
- /** git ref (branch, tag, commit SHA, etc) to get the file content from */
217
- ref: string;
218
- } & GitCommonOptions): string | undefined;