workspace-tools 0.41.5 → 0.41.6
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/lib/git/gitUtilities.d.ts +2 -2
- package/lib/git/gitUtilities.js +4 -4
- package/lib/git/gitUtilities.js.map +1 -1
- package/lib/workspaces/getCatalogVersion.d.ts +8 -3
- package/lib/workspaces/getCatalogVersion.js +9 -3
- package/lib/workspaces/getCatalogVersion.js.map +1 -1
- package/package.json +1 -1
|
@@ -210,8 +210,8 @@ export declare function listAllTrackedFiles(patterns: string[], cwd: string): st
|
|
|
210
210
|
* Get the content of a file at a specific git ref (commit, branch, tag, etc).
|
|
211
211
|
* Returns undefined if the file doesn't exist at that ref or the command fails.
|
|
212
212
|
*/
|
|
213
|
-
export declare function
|
|
214
|
-
/**
|
|
213
|
+
export declare function getFileFromRef(params: {
|
|
214
|
+
/** cwd-relative path to the file with *forward* slashes */
|
|
215
215
|
filePath: string;
|
|
216
216
|
/** git ref (branch, tag, commit SHA, etc) to get the file content from */
|
|
217
217
|
ref: string;
|
package/lib/git/gitUtilities.js
CHANGED
|
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
17
17
|
getCurrentHash: null,
|
|
18
18
|
getDefaultBranch: null,
|
|
19
19
|
getFileAddedHash: null,
|
|
20
|
-
|
|
20
|
+
getFileFromRef: null,
|
|
21
21
|
getFullBranchRef: null,
|
|
22
22
|
getParentBranch: null,
|
|
23
23
|
getRecentCommitMessages: null,
|
|
@@ -71,8 +71,8 @@ _export(exports, {
|
|
|
71
71
|
get getFileAddedHash () {
|
|
72
72
|
return getFileAddedHash;
|
|
73
73
|
},
|
|
74
|
-
get
|
|
75
|
-
return
|
|
74
|
+
get getFileFromRef () {
|
|
75
|
+
return getFileFromRef;
|
|
76
76
|
},
|
|
77
77
|
get getFullBranchRef () {
|
|
78
78
|
return getFullBranchRef;
|
|
@@ -547,7 +547,7 @@ function listAllTrackedFiles(patternsOrOptions, cwd) {
|
|
|
547
547
|
});
|
|
548
548
|
return (0, _git.processGitOutput)(results);
|
|
549
549
|
}
|
|
550
|
-
function
|
|
550
|
+
function getFileFromRef(params) {
|
|
551
551
|
const { filePath, ref, ...options } = params;
|
|
552
552
|
const result = (0, _git.git)([
|
|
553
553
|
"show",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/git/gitUtilities.ts"],"sourcesContent":["//\n// Assorted other git utilities\n// (could be split into separate files later if desired)\n//\n\nimport { getConfigValue } from \"./config.js\";\nimport { git, processGitOutput } from \"./git.js\";\nimport type {\n GetChangesBetweenRefsOptions,\n GitBranchOptions,\n GitCommitOptions,\n GitCommonOptions,\n GitFetchOptions,\n GitInitOptions,\n GitStageOptions,\n ParsedRemoteBranch,\n ParseRemoteBranchOptions,\n} from \"./types.js\";\n\nconst diffArgs = [\"--no-pager\", \"diff\", \"--name-only\", \"--relative\"];\n\n/**\n * Get a list of files with untracked changes.\n * Throws an error on failure by default.\n *\n * @returns An array of file paths with untracked changes\n */\n// TODO: move to getChanges.ts\nexport function getUntrackedChanges(options: GitCommonOptions): string[];\n/** @deprecated Use object params version */\nexport function getUntrackedChanges(cwd: string): string[];\nexport function getUntrackedChanges(cwdOrOptions: string | GitCommonOptions): string[] {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git([\"ls-files\", \"--others\", \"--exclude-standard\"], {\n description: \"Gathering information about untracked changes\",\n throwOnError: true,\n ...options,\n });\n return processGitOutput(results, { excludeNodeModules: true });\n}\n\n/**\n * Fetch from the given remote (and optionally branch) or all remotes.\n * Throws an error on failure by default.\n */\n// TODO: move to fetch.ts\nexport function fetchRemote(options: GitFetchOptions): void;\n/** @deprecated Use object params version */\nexport function fetchRemote(remote: string, cwd: string): void;\nexport function fetchRemote(remoteOrOptions: string | GitFetchOptions, cwd?: string): void {\n const { remote, remoteBranch, options, ...gitOptions } =\n typeof remoteOrOptions === \"string\"\n ? ({ remote: remoteOrOptions, cwd: cwd! } satisfies GitFetchOptions)\n : remoteOrOptions;\n\n if (remoteBranch && !remote) {\n throw new Error('Must provide \"remote\" when using \"remoteBranch\" option');\n }\n\n const fetchArgs = [\n \"fetch\",\n \"--\",\n ...(remote ? [remote] : []),\n ...(remoteBranch ? [remoteBranch] : []),\n ...(options || []),\n ];\n\n git(fetchArgs, {\n description: remote\n ? `Fetching ${remoteBranch ? `branch \"${remoteBranch}\" from ` : \"\"}remote \"${remote}\"`\n : \"Fetching all remotes\",\n throwOnError: true,\n ...gitOptions,\n });\n}\n\n/**\n * Fetch from the given remote and branch. Throws an error on failure.\n * @deprecated Use `fetchRemote({ remote, remoteBranch, cwd })`\n */\n// TODO: move to fetch.ts\nexport function fetchRemoteBranch(remote: string, remoteBranch: string, cwd: string): void {\n fetchRemote({ remote, remoteBranch, cwd, throwOnError: true });\n}\n\n/**\n * Gets file paths with changes that have not been staged yet.\n * Throws an error on failure by default.\n *\n * @returns An array of relative file paths with unstaged changes\n */\n// TODO: move to getChanges.ts\nexport function getUnstagedChanges(options: GitCommonOptions): string[];\n/** @deprecated Use object params version */\nexport function getUnstagedChanges(cwd: string): string[];\nexport function getUnstagedChanges(cwdOrOptions: string | GitCommonOptions): string[] {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git(diffArgs, {\n description: \"Gathering information about unstaged changes\",\n throwOnError: true,\n ...options,\n });\n return processGitOutput(results, { excludeNodeModules: true });\n}\n\n/**\n * Gets file paths with changes between the current branch and the given branch.\n * Throws an error on failure.\n *\n * @returns An array of relative file paths that have changed\n * @deprecated Use `getBranchChanges({ branch, cwd })`\n */\n// TODO: move to getChanges.ts\nexport function getChanges(branch: string, cwd: string): string[] {\n return getChangesBetweenRefs({ fromRef: branch, cwd, throwOnError: true });\n}\n\n/**\n * Gets file paths with changes between the branch and the merge-base.\n * Throws an error on failure by default.\n *\n * @returns An array of relative file paths that have changed\n */\n// TODO: move to getChanges.ts\nexport function getBranchChanges(options: GitBranchOptions): string[];\n/** @deprecated Use object params version */\nexport function getBranchChanges(branch: string, cwd: string): string[];\nexport function getBranchChanges(branchOrOptions: string | GitBranchOptions, cwd?: string): string[] {\n const { branch, ...options } =\n typeof branchOrOptions === \"string\" ? { branch: branchOrOptions, cwd: cwd! } : branchOrOptions;\n\n return getChangesBetweenRefs({ fromRef: branch, throwOnError: true, ...options });\n}\n\n/**\n * Gets file paths with changes between two git references (commits, branches, tags).\n * Throws an error on failure by default.\n *\n * @returns An array of file paths that have changed\n */\n// TODO: move to getChanges.ts\nexport function getChangesBetweenRefs(options: GetChangesBetweenRefsOptions): string[];\n/** @deprecated Use object param version */\nexport function getChangesBetweenRefs(\n fromRef: string,\n toRef: string,\n options: string[],\n pattern: string,\n cwd: string\n): string[];\nexport function getChangesBetweenRefs(\n fromRef: string | GetChangesBetweenRefsOptions,\n toRef?: string,\n options?: string[],\n pattern?: string,\n cwd?: string\n): string[] {\n let gitOptions: GitCommonOptions;\n if (typeof fromRef === \"string\") {\n gitOptions = { cwd: cwd! };\n } else {\n ({ fromRef, toRef, options, pattern, ...gitOptions } = fromRef);\n }\n\n const range = `${fromRef}...${toRef || \"\"}`;\n const results = git([...diffArgs, ...(options || []), range, ...(pattern ? [\"--\", pattern] : [])], {\n description: `Gathering information about changes between refs (${range})`,\n throwOnError: true,\n ...gitOptions,\n });\n return processGitOutput(results, { excludeNodeModules: true });\n}\n\n/**\n * Gets all files with staged changes (files added to the index).\n * Throws an error on failure by default.\n *\n * @returns An array of relative file paths that have been staged\n */\n// TODO: move to getChanges.ts\nexport function getStagedChanges(options: GitCommonOptions): string[];\n/** @deprecated Use object params version */\nexport function getStagedChanges(cwd: string): string[];\nexport function getStagedChanges(cwdOrOptions: string | GitCommonOptions): string[] {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git([...diffArgs, \"--staged\"], {\n description: \"Gathering information about staged changes\",\n throwOnError: true,\n ...options,\n });\n return processGitOutput(results, { excludeNodeModules: true });\n}\n\n/**\n * Gets recent commit messages between the specified parent branch and HEAD.\n * By default, returns an empty array if the operation fails.\n *\n * @returns An array of commit message strings\n */\n// TODO: move to history.ts\nexport function getRecentCommitMessages(options: GitBranchOptions): string[];\n/** @deprecated Use object params version */\nexport function getRecentCommitMessages(branch: string, cwd: string): string[];\nexport function getRecentCommitMessages(branchOrOptions: string | GitBranchOptions, cwd?: string): string[] {\n const { branch, ...options } =\n typeof branchOrOptions === \"string\" ? { branch: branchOrOptions, cwd: cwd! } : branchOrOptions;\n\n const results = git([\"log\", \"--decorate\", \"--pretty=format:%s\", `${branch}..HEAD`], {\n description: `Getting recent commit messages for branch \"${branch}\"`,\n ...options,\n });\n return processGitOutput(results);\n}\n\n/**\n * Gets the user email from the git config.\n * @returns The email string if found, null otherwise\n */\n// TODO: move to config.ts\nexport function getUserEmail(options: GitCommonOptions): string | null;\n/** @deprecated Use object params version */\nexport function getUserEmail(cwd: string): string | null;\nexport function getUserEmail(cwdOrOptions: string | GitCommonOptions): string | null {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n return getConfigValue({ key: \"user.email\", ...options });\n}\n\n/**\n * Gets the current branch name.\n * In detached HEAD state, returns \"HEAD\".\n *\n * @returns The branch name if successful, null otherwise\n */\n// TODO: move to refs.ts\nexport function getBranchName(options: GitCommonOptions): string | null;\n/** @deprecated Use object params version */\nexport function getBranchName(cwd: string): string | null;\nexport function getBranchName(cwdOrOptions: string | GitCommonOptions): string | null {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git([\"rev-parse\", \"--abbrev-ref\", \"HEAD\"], {\n description: \"Getting current branch name\",\n ...options,\n });\n return results.success ? results.stdout : null;\n}\n\n/**\n * Gets the full reference path for a given branch.\n * `branch` here is the short branch name, e.g. `branch-name`.\n * @returns The full branch reference (e.g., `refs/heads/branch-name`) if found, null otherwise\n */\n// TODO: move to refs.ts\nexport function getFullBranchRef(options: GitBranchOptions): string | null;\n/** @deprecated Use object params version */\nexport function getFullBranchRef(branch: string, cwd: string): string | null;\nexport function getFullBranchRef(branchOrOptions: string | GitBranchOptions, cwd?: string): string | null {\n const { branch, ...options } =\n typeof branchOrOptions === \"string\" ? { branch: branchOrOptions, cwd: cwd! } : branchOrOptions;\n\n const showRefResults = git([\"show-ref\", \"--heads\", branch], options);\n\n return showRefResults.success ? showRefResults.stdout.split(\" \")[1] : null;\n}\n\n/**\n * Gets the short branch name from a full branch reference.\n * @returns The short branch name if successful, null otherwise\n */\n// TODO: move to refs.ts\nexport function getShortBranchName(\n options: {\n /** The full branch reference (e.g., `refs/heads/branch-name`) */\n fullBranchRef: string;\n } & GitCommonOptions\n): string | null;\n/** @deprecated Use object params version */\nexport function getShortBranchName(fullBranchRef: string, cwd: string): string | null;\nexport function getShortBranchName(\n refOrOptions: string | ({ fullBranchRef: string } & GitCommonOptions),\n cwd?: string\n): string | null {\n const { fullBranchRef, ...options } =\n typeof refOrOptions === \"string\" ? { fullBranchRef: refOrOptions, cwd: cwd! } : refOrOptions;\n\n // The original command `git name-rev --name-only` returned unreliable results if multiple\n // named refs point to the same commit as the branch.\n const showRefResults = git([\"rev-parse\", \"--abbrev-ref\", fullBranchRef], options);\n\n return showRefResults.success ? showRefResults.stdout || null : null;\n}\n\n/**\n * Gets the current commit hash (SHA).\n * @returns The hash if successful, null otherwise\n */\n// TODO: move to refs.ts\nexport function getCurrentHash(options: GitCommonOptions): string | null;\n/** @deprecated Use object params version */\nexport function getCurrentHash(cwd: string): string | null;\nexport function getCurrentHash(cwdOrOptions: string | GitCommonOptions): string | null {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git([\"rev-parse\", \"HEAD\"], {\n description: \"Getting current git hash\",\n ...options,\n });\n\n return results.success ? results.stdout : null;\n}\n\n/**\n * Get the commit hash in which the file was first added.\n * @returns The commit hash if found, undefined otherwise\n */\n// TODO: move to history.ts\nexport function getFileAddedHash(options: { filename: string } & GitCommonOptions): string | undefined;\n/** @deprecated Use object params version */\nexport function getFileAddedHash(filename: string, cwd: string): string | undefined;\nexport function getFileAddedHash(\n filenameOrOptions: string | ({ filename: string } & GitCommonOptions),\n cwd?: string\n): string | undefined {\n const { filename, ...options } =\n typeof filenameOrOptions === \"string\" ? { filename: filenameOrOptions, cwd: cwd! } : filenameOrOptions;\n\n const results = git([\"rev-list\", \"--max-count=1\", \"HEAD\", filename], options);\n\n return results.success ? results.stdout.trim() : undefined;\n}\n\n/**\n * Run `git init` and verify that the `user.name` and `user.email` configs are set (at any level).\n * Throws an error if `git init` fails.\n *\n * If `user.email` and `user.name` aren't already set globally, and the missing value is provided\n * in params, set it at the repo level. Otherwise, throw an error.\n */\n// TODO: move to init.ts\nexport function init(options: GitInitOptions): void;\n/** @deprecated Use object params version */\nexport function init(cwd: string, email?: string, username?: string): void;\nexport function init(cwdOrOptions: string | GitInitOptions, _email?: string, _username?: string): void {\n const { email, username, ...options } =\n typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions, email: _email, username: _username } : cwdOrOptions;\n\n git([\"init\"], { ...options, throwOnError: true });\n\n if (!getConfigValue({ key: \"user.name\", ...options })) {\n if (!username) {\n throw new Error(\"must include a username when initializing git repo\");\n }\n git([\"config\", \"user.name\", username], options);\n }\n\n if (!getUserEmail(options)) {\n if (!email) {\n throw new Error(\"must include a email when initializing git repo\");\n }\n git([\"config\", \"user.email\", email], options);\n }\n}\n\n/**\n * Stages files matching the given patterns.\n */\n// TODO: move to stageAndCommit.ts\nexport function stage(options: GitStageOptions): void;\n/** @deprecated Use object params version */\nexport function stage(patterns: string[], cwd: string): void;\nexport function stage(patternsOrOptions: string[] | GitStageOptions, cwd?: string): void {\n const { patterns, ...options } = Array.isArray(patternsOrOptions)\n ? { patterns: patternsOrOptions, cwd: cwd! }\n : patternsOrOptions;\n\n for (const pattern of patterns) {\n git([\"add\", pattern], { ...options, description: `Staging changes (git add ${pattern})` });\n }\n}\n\n/**\n * Commit changes. Throws an error on failure by default.\n */\n// TODO: move to stageAndCommit.ts\nexport function commit(options: GitCommitOptions): void;\n/** @deprecated Use object params version */\nexport function commit(message: string, cwd: string, options?: string[]): void;\nexport function commit(messageOrOptions: string | GitCommitOptions, _cwd?: string, _options?: string[]): void {\n const { message, options, ...gitOptions } =\n typeof messageOrOptions === \"string\"\n ? { message: messageOrOptions, cwd: _cwd!, options: _options }\n : messageOrOptions;\n\n git([\"commit\", \"-m\", message, ...(options || [])], {\n throwOnError: true,\n description: \"Committing changes\",\n ...gitOptions,\n });\n}\n\n/**\n * Stages files matching the given patterns and creates a commit with the specified message.\n * Convenience function that combines `stage()` and `commit()`.\n * Throws an error on commit failure by default.\n */\n// TODO: move to stageAndCommit.ts\nexport function stageAndCommit(options: GitStageOptions & GitCommitOptions): void;\n/** @deprecated Use object params version */\nexport function stageAndCommit(patterns: string[], message: string, cwd: string, commitOptions?: string[]): void;\nexport function stageAndCommit(\n patternsOrOptions: string[] | (GitStageOptions & GitCommitOptions),\n message?: string,\n cwd?: string,\n commitOptions?: string[]\n): void {\n const options: GitStageOptions & GitCommitOptions = Array.isArray(patternsOrOptions)\n ? { patterns: patternsOrOptions, message: message!, cwd: cwd!, options: commitOptions }\n : patternsOrOptions;\n\n stage(options);\n commit(options);\n}\n\n/**\n * Reverts all local changes (both staged and unstaged) by stashing them and then dropping the stash.\n * @returns True if the revert was successful, false otherwise. It will also be false if there were\n * no changes to revert. (To distinguish between this case and errors, use the `throwOnError` option.)\n */\n// TODO: move to revertLocalChanges.ts\nexport function revertLocalChanges(options: GitCommonOptions): boolean;\n/** @deprecated Use object params version */\nexport function revertLocalChanges(cwd: string): boolean;\nexport function revertLocalChanges(cwdOrOptions: string | GitCommonOptions): boolean {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const stash = `workspace-tools_${new Date().getTime()}`;\n if (!git([\"stash\", \"push\", \"-u\", \"-m\", stash], options).success) {\n return false;\n }\n\n const results = git([\"stash\", \"list\"], options);\n if (results.success) {\n const matched = results.stdout\n .split(/\\n/)\n .find((line) => line.includes(stash))\n ?.match(/^[^:]+/);\n\n if (matched) {\n git([\"stash\", \"drop\", matched[0]], options);\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Attempts to determine the parent branch of the current branch using `git show-branch`.\n * @returns The parent branch name if found, null otherwise\n * @deprecated Does not appear to be used\n */\nexport function getParentBranch(cwd: string): string | null {\n const branchName = getBranchName({ cwd });\n\n if (!branchName || branchName === \"HEAD\") {\n return null;\n }\n\n const showBranchResult = git([\"show-branch\", \"-a\"], { cwd });\n\n if (showBranchResult.success) {\n const showBranchLines = showBranchResult.stdout.split(/\\n/);\n const parentLine = showBranchLines.find(\n (line) => line.includes(\"*\") && !line.includes(branchName) && !line.includes(\"publish_\")\n );\n\n const matched = parentLine?.match(/\\[(.*)\\]/);\n return matched ? matched[1] : null;\n }\n\n return null;\n}\n\n/**\n * Gets the remote tracking branch for the specified branch.\n *\n * @returns The remote branch name (e.g., `origin/main`) if found, null otherwise\n */\n// TODO: move to refs.ts\nexport function getRemoteBranch(options: GitBranchOptions): string | null;\n/** @deprecated Use object params version */\nexport function getRemoteBranch(branch: string, cwd: string): string | null;\nexport function getRemoteBranch(branchOrOptions: string | GitBranchOptions, cwd?: string): string | null {\n const options: GitBranchOptions =\n typeof branchOrOptions === \"string\" ? { branch: branchOrOptions, cwd: cwd! } : branchOrOptions;\n\n const results = git([\"rev-parse\", \"--abbrev-ref\", \"--symbolic-full-name\", `${options.branch}@{u}`], options);\n\n return results.success ? results.stdout.trim() : null;\n}\n\n/**\n * Get the remote and branch name from a full branch name that may include a remote prefix.\n * If the path doesn't start with one of `options.knownRemotes` (but has multiple segments),\n * the actual list of remotes will be fetched to see if one of those matches.\n *\n * NOTE: The additional verification is new in the object params version; the original version\n * incorrectly assumes the first segment before a slash is always a remote.\n */\n// TODO: move to parseRemoteBranch.ts\nexport function parseRemoteBranch(options: ParseRemoteBranchOptions): ParsedRemoteBranch;\n/**\n * @deprecated Use object params version, which does more verification. This version inaccurately\n * assumes the first segment before a slash is always a remote, which could lead to tricky bugs.\n */\nexport function parseRemoteBranch(branch: string): ParsedRemoteBranch;\nexport function parseRemoteBranch(branchOrOptions: string | ParseRemoteBranchOptions): ParsedRemoteBranch {\n if (typeof branchOrOptions === \"string\") {\n const branch = branchOrOptions;\n const firstSlashPos = branch.indexOf(\"/\", 0);\n return {\n remote: branch.substring(0, firstSlashPos),\n remoteBranch: branch.substring(firstSlashPos + 1),\n };\n }\n\n const { branch, knownRemotes = [\"origin\", \"upstream\"], ...options } = branchOrOptions;\n\n if (!branch.includes(\"/\")) {\n return { remote: \"\", remoteBranch: branch };\n }\n\n let remote = knownRemotes.find((r) => branch.startsWith(`${r}/`));\n\n if (!remote) {\n const remotes = git([\"remote\"], options).stdout.trim().split(/\\n/);\n remote = remotes.find((r) => branch.startsWith(`${r}/`));\n }\n\n if (remote) {\n return { remote, remoteBranch: branch.slice(remote.length + 1) };\n }\n return { remote: \"\", remoteBranch: branch };\n}\n\n/**\n * Gets the default branch based on `git config init.defaultBranch`, falling back to `master`.\n */\n// TODO: move to config.ts\nexport function getDefaultBranch(options: GitCommonOptions): string;\n/** @deprecated Use object params version */\nexport function getDefaultBranch(cwd: string): string;\nexport function getDefaultBranch(cwdOrOptions: string | GitCommonOptions): string {\n const options = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n // Default to the legacy 'master' for backwards compat and old git clients\n return getConfigValue({ key: \"init.defaultBranch\", ...options }) || \"master\";\n}\n\n/**\n * Lists all tracked files matching the given patterns.\n * Throws on error by default.\n * @returns An array of file paths, or an empty array if no files are found\n */\n// TODO: move to history.ts\nexport function listAllTrackedFiles(\n options: {\n /** File patterns to match (passed to git ls-files) */\n patterns: string[];\n } & GitCommonOptions\n): string[];\n/** @deprecated Use object params version */\nexport function listAllTrackedFiles(patterns: string[], cwd: string): string[];\nexport function listAllTrackedFiles(\n patternsOrOptions: string[] | ({ patterns: string[] } & GitCommonOptions),\n cwd?: string\n): string[] {\n const { patterns, ...options } = Array.isArray(patternsOrOptions)\n ? { patterns: patternsOrOptions, cwd: cwd! }\n : patternsOrOptions;\n\n const results = git([\"ls-files\", ...patterns], { throwOnError: true, ...options });\n\n return processGitOutput(results);\n}\n\n/**\n * Get the content of a file at a specific git ref (commit, branch, tag, etc).\n * Returns undefined if the file doesn't exist at that ref or the command fails.\n */\nexport function getFileFromVersion(\n params: {\n /** Repo-relative path to the file with *forward* slashes */\n filePath: string;\n /** git ref (branch, tag, commit SHA, etc) to get the file content from */\n ref: string;\n } & GitCommonOptions\n): string | undefined {\n const { filePath, ref, ...options } = params;\n const result = git([\"show\", `${ref}:${filePath}`], {\n description: `Getting file ${filePath} at ref ${ref}`,\n ...options,\n });\n return result.success ? result.stdout : undefined;\n}\n"],"names":["commit","fetchRemote","fetchRemoteBranch","getBranchChanges","getBranchName","getChanges","getChangesBetweenRefs","getCurrentHash","getDefaultBranch","getFileAddedHash","getFileFromVersion","getFullBranchRef","getParentBranch","getRecentCommitMessages","getRemoteBranch","getShortBranchName","getStagedChanges","getUnstagedChanges","getUntrackedChanges","getUserEmail","init","listAllTrackedFiles","parseRemoteBranch","revertLocalChanges","stage","stageAndCommit","diffArgs","cwdOrOptions","options","cwd","results","git","description","throwOnError","processGitOutput","excludeNodeModules","remoteOrOptions","remote","remoteBranch","gitOptions","Error","fetchArgs","branch","fromRef","branchOrOptions","toRef","pattern","range","getConfigValue","key","success","stdout","showRefResults","split","refOrOptions","fullBranchRef","filenameOrOptions","filename","trim","undefined","_email","_username","email","username","patternsOrOptions","patterns","Array","isArray","messageOrOptions","_cwd","_options","message","commitOptions","stash","Date","getTime","matched","find","line","includes","match","branchName","showBranchResult","showBranchLines","parentLine","firstSlashPos","indexOf","substring","knownRemotes","r","startsWith","remotes","slice","length","params","filePath","ref","result"],"mappings":"AAAA,EAAE;AACF,+BAA+B;AAC/B,wDAAwD;AACxD,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAmYcA;eAAAA;;QApVAC;eAAAA;;QAgCAC;eAAAA;;QA+CAC;eAAAA;;QA+GAC;eAAAA;;QA7HAC;eAAAA;;QAqCAC;eAAAA;;QAuJAC;eAAAA;;QA4PAC;eAAAA;;QAzOAC;eAAAA;;QA+QAC;eAAAA;;QA9UAC;eAAAA;;QA6MAC;eAAAA;;QAlQAC;eAAAA;;QAiSAC;eAAAA;;QAtNAC;eAAAA;;QAhGAC;eAAAA;;QAzFAC;eAAAA;;QAjEAC;eAAAA;;QAkMAC;eAAAA;;QAwHAC;eAAAA;;QAuOAC;eAAAA;;QAzDAC;eAAAA;;QApFAC;eAAAA;;QA9DAC;eAAAA;;QAuCAC;eAAAA;;;wBAvZe;qBACO;AAatC,MAAMC,WAAW;IAAC;IAAc;IAAQ;IAAe;CAAa;AAY7D,SAASR,oBAAoBS,YAAuC;IACzE,MAAMC,UAA4B,OAAOD,iBAAiB,WAAW;QAAEE,KAAKF;IAAa,IAAIA;IAE7F,MAAMG,UAAUC,IAAAA,QAAG,EAAC;QAAC;QAAY;QAAY;KAAqB,EAAE;QAClEC,aAAa;QACbC,cAAc;QACd,GAAGL,OAAO;IACZ;IACA,OAAOM,IAAAA,qBAAgB,EAACJ,SAAS;QAAEK,oBAAoB;IAAK;AAC9D;AAUO,SAASlC,YAAYmC,eAAyC,EAAEP,GAAY;IACjF,MAAM,EAAEQ,MAAM,EAAEC,YAAY,EAAEV,OAAO,EAAE,GAAGW,YAAY,GACpD,OAAOH,oBAAoB,WACtB;QAAEC,QAAQD;QAAiBP,KAAKA;IAAK,IACtCO;IAEN,IAAIE,gBAAgB,CAACD,QAAQ;QAC3B,MAAM,IAAIG,MAAM;IACl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AekC;KAAS,EAAE;QAAEhC,cAAc;QAAM,GAAGL,OAAO;IAAC;IAEhF,OAAOM,IAAAA,qBAAgB,EAACJ;AAC1B;AAMO,SAASpB,mBACdoF,MAKoB;IAEpB,MAAM,EAAEC,QAAQ,EAAEC,GAAG,EAAE,GAAGpE,SAAS,GAAGkE;IACtC,MAAMG,SAASlE,IAAAA,QAAG,EAAC;QAAC;QAAQ,GAAGiE,IAAI,CAAC,EAAED,UAAU;KAAC,EAAE;QACjD/D,aAAa,CAAC,aAAa,EAAE+D,SAAS,QAAQ,EAAEC,KAAK;QACrD,GAAGpE,OAAO;IACZ;IACA,OAAOqE,OAAO/C,OAAO,GAAG+C,OAAO9C,MAAM,GAAGQ;AAC1C"}
|
|
1
|
+
{"version":3,"sources":["../../src/git/gitUtilities.ts"],"sourcesContent":["//\n// Assorted other git utilities\n// (could be split into separate files later if desired)\n//\n\nimport { getConfigValue } from \"./config.js\";\nimport { git, processGitOutput } from \"./git.js\";\nimport type {\n GetChangesBetweenRefsOptions,\n GitBranchOptions,\n GitCommitOptions,\n GitCommonOptions,\n GitFetchOptions,\n GitInitOptions,\n GitStageOptions,\n ParsedRemoteBranch,\n ParseRemoteBranchOptions,\n} from \"./types.js\";\n\nconst diffArgs = [\"--no-pager\", \"diff\", \"--name-only\", \"--relative\"];\n\n/**\n * Get a list of files with untracked changes.\n * Throws an error on failure by default.\n *\n * @returns An array of file paths with untracked changes\n */\n// TODO: move to getChanges.ts\nexport function getUntrackedChanges(options: GitCommonOptions): string[];\n/** @deprecated Use object params version */\nexport function getUntrackedChanges(cwd: string): string[];\nexport function getUntrackedChanges(cwdOrOptions: string | GitCommonOptions): string[] {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git([\"ls-files\", \"--others\", \"--exclude-standard\"], {\n description: \"Gathering information about untracked changes\",\n throwOnError: true,\n ...options,\n });\n return processGitOutput(results, { excludeNodeModules: true });\n}\n\n/**\n * Fetch from the given remote (and optionally branch) or all remotes.\n * Throws an error on failure by default.\n */\n// TODO: move to fetch.ts\nexport function fetchRemote(options: GitFetchOptions): void;\n/** @deprecated Use object params version */\nexport function fetchRemote(remote: string, cwd: string): void;\nexport function fetchRemote(remoteOrOptions: string | GitFetchOptions, cwd?: string): void {\n const { remote, remoteBranch, options, ...gitOptions } =\n typeof remoteOrOptions === \"string\"\n ? ({ remote: remoteOrOptions, cwd: cwd! } satisfies GitFetchOptions)\n : remoteOrOptions;\n\n if (remoteBranch && !remote) {\n throw new Error('Must provide \"remote\" when using \"remoteBranch\" option');\n }\n\n const fetchArgs = [\n \"fetch\",\n \"--\",\n ...(remote ? [remote] : []),\n ...(remoteBranch ? [remoteBranch] : []),\n ...(options || []),\n ];\n\n git(fetchArgs, {\n description: remote\n ? `Fetching ${remoteBranch ? `branch \"${remoteBranch}\" from ` : \"\"}remote \"${remote}\"`\n : \"Fetching all remotes\",\n throwOnError: true,\n ...gitOptions,\n });\n}\n\n/**\n * Fetch from the given remote and branch. Throws an error on failure.\n * @deprecated Use `fetchRemote({ remote, remoteBranch, cwd })`\n */\n// TODO: move to fetch.ts\nexport function fetchRemoteBranch(remote: string, remoteBranch: string, cwd: string): void {\n fetchRemote({ remote, remoteBranch, cwd, throwOnError: true });\n}\n\n/**\n * Gets file paths with changes that have not been staged yet.\n * Throws an error on failure by default.\n *\n * @returns An array of relative file paths with unstaged changes\n */\n// TODO: move to getChanges.ts\nexport function getUnstagedChanges(options: GitCommonOptions): string[];\n/** @deprecated Use object params version */\nexport function getUnstagedChanges(cwd: string): string[];\nexport function getUnstagedChanges(cwdOrOptions: string | GitCommonOptions): string[] {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git(diffArgs, {\n description: \"Gathering information about unstaged changes\",\n throwOnError: true,\n ...options,\n });\n return processGitOutput(results, { excludeNodeModules: true });\n}\n\n/**\n * Gets file paths with changes between the current branch and the given branch.\n * Throws an error on failure.\n *\n * @returns An array of relative file paths that have changed\n * @deprecated Use `getBranchChanges({ branch, cwd })`\n */\n// TODO: move to getChanges.ts\nexport function getChanges(branch: string, cwd: string): string[] {\n return getChangesBetweenRefs({ fromRef: branch, cwd, throwOnError: true });\n}\n\n/**\n * Gets file paths with changes between the branch and the merge-base.\n * Throws an error on failure by default.\n *\n * @returns An array of relative file paths that have changed\n */\n// TODO: move to getChanges.ts\nexport function getBranchChanges(options: GitBranchOptions): string[];\n/** @deprecated Use object params version */\nexport function getBranchChanges(branch: string, cwd: string): string[];\nexport function getBranchChanges(branchOrOptions: string | GitBranchOptions, cwd?: string): string[] {\n const { branch, ...options } =\n typeof branchOrOptions === \"string\" ? { branch: branchOrOptions, cwd: cwd! } : branchOrOptions;\n\n return getChangesBetweenRefs({ fromRef: branch, throwOnError: true, ...options });\n}\n\n/**\n * Gets file paths with changes between two git references (commits, branches, tags).\n * Throws an error on failure by default.\n *\n * @returns An array of file paths that have changed\n */\n// TODO: move to getChanges.ts\nexport function getChangesBetweenRefs(options: GetChangesBetweenRefsOptions): string[];\n/** @deprecated Use object param version */\nexport function getChangesBetweenRefs(\n fromRef: string,\n toRef: string,\n options: string[],\n pattern: string,\n cwd: string\n): string[];\nexport function getChangesBetweenRefs(\n fromRef: string | GetChangesBetweenRefsOptions,\n toRef?: string,\n options?: string[],\n pattern?: string,\n cwd?: string\n): string[] {\n let gitOptions: GitCommonOptions;\n if (typeof fromRef === \"string\") {\n gitOptions = { cwd: cwd! };\n } else {\n ({ fromRef, toRef, options, pattern, ...gitOptions } = fromRef);\n }\n\n const range = `${fromRef}...${toRef || \"\"}`;\n const results = git([...diffArgs, ...(options || []), range, ...(pattern ? [\"--\", pattern] : [])], {\n description: `Gathering information about changes between refs (${range})`,\n throwOnError: true,\n ...gitOptions,\n });\n return processGitOutput(results, { excludeNodeModules: true });\n}\n\n/**\n * Gets all files with staged changes (files added to the index).\n * Throws an error on failure by default.\n *\n * @returns An array of relative file paths that have been staged\n */\n// TODO: move to getChanges.ts\nexport function getStagedChanges(options: GitCommonOptions): string[];\n/** @deprecated Use object params version */\nexport function getStagedChanges(cwd: string): string[];\nexport function getStagedChanges(cwdOrOptions: string | GitCommonOptions): string[] {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git([...diffArgs, \"--staged\"], {\n description: \"Gathering information about staged changes\",\n throwOnError: true,\n ...options,\n });\n return processGitOutput(results, { excludeNodeModules: true });\n}\n\n/**\n * Gets recent commit messages between the specified parent branch and HEAD.\n * By default, returns an empty array if the operation fails.\n *\n * @returns An array of commit message strings\n */\n// TODO: move to history.ts\nexport function getRecentCommitMessages(options: GitBranchOptions): string[];\n/** @deprecated Use object params version */\nexport function getRecentCommitMessages(branch: string, cwd: string): string[];\nexport function getRecentCommitMessages(branchOrOptions: string | GitBranchOptions, cwd?: string): string[] {\n const { branch, ...options } =\n typeof branchOrOptions === \"string\" ? { branch: branchOrOptions, cwd: cwd! } : branchOrOptions;\n\n const results = git([\"log\", \"--decorate\", \"--pretty=format:%s\", `${branch}..HEAD`], {\n description: `Getting recent commit messages for branch \"${branch}\"`,\n ...options,\n });\n return processGitOutput(results);\n}\n\n/**\n * Gets the user email from the git config.\n * @returns The email string if found, null otherwise\n */\n// TODO: move to config.ts\nexport function getUserEmail(options: GitCommonOptions): string | null;\n/** @deprecated Use object params version */\nexport function getUserEmail(cwd: string): string | null;\nexport function getUserEmail(cwdOrOptions: string | GitCommonOptions): string | null {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n return getConfigValue({ key: \"user.email\", ...options });\n}\n\n/**\n * Gets the current branch name.\n * In detached HEAD state, returns \"HEAD\".\n *\n * @returns The branch name if successful, null otherwise\n */\n// TODO: move to refs.ts\nexport function getBranchName(options: GitCommonOptions): string | null;\n/** @deprecated Use object params version */\nexport function getBranchName(cwd: string): string | null;\nexport function getBranchName(cwdOrOptions: string | GitCommonOptions): string | null {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git([\"rev-parse\", \"--abbrev-ref\", \"HEAD\"], {\n description: \"Getting current branch name\",\n ...options,\n });\n return results.success ? results.stdout : null;\n}\n\n/**\n * Gets the full reference path for a given branch.\n * `branch` here is the short branch name, e.g. `branch-name`.\n * @returns The full branch reference (e.g., `refs/heads/branch-name`) if found, null otherwise\n */\n// TODO: move to refs.ts\nexport function getFullBranchRef(options: GitBranchOptions): string | null;\n/** @deprecated Use object params version */\nexport function getFullBranchRef(branch: string, cwd: string): string | null;\nexport function getFullBranchRef(branchOrOptions: string | GitBranchOptions, cwd?: string): string | null {\n const { branch, ...options } =\n typeof branchOrOptions === \"string\" ? { branch: branchOrOptions, cwd: cwd! } : branchOrOptions;\n\n const showRefResults = git([\"show-ref\", \"--heads\", branch], options);\n\n return showRefResults.success ? showRefResults.stdout.split(\" \")[1] : null;\n}\n\n/**\n * Gets the short branch name from a full branch reference.\n * @returns The short branch name if successful, null otherwise\n */\n// TODO: move to refs.ts\nexport function getShortBranchName(\n options: {\n /** The full branch reference (e.g., `refs/heads/branch-name`) */\n fullBranchRef: string;\n } & GitCommonOptions\n): string | null;\n/** @deprecated Use object params version */\nexport function getShortBranchName(fullBranchRef: string, cwd: string): string | null;\nexport function getShortBranchName(\n refOrOptions: string | ({ fullBranchRef: string } & GitCommonOptions),\n cwd?: string\n): string | null {\n const { fullBranchRef, ...options } =\n typeof refOrOptions === \"string\" ? { fullBranchRef: refOrOptions, cwd: cwd! } : refOrOptions;\n\n // The original command `git name-rev --name-only` returned unreliable results if multiple\n // named refs point to the same commit as the branch.\n const showRefResults = git([\"rev-parse\", \"--abbrev-ref\", fullBranchRef], options);\n\n return showRefResults.success ? showRefResults.stdout || null : null;\n}\n\n/**\n * Gets the current commit hash (SHA).\n * @returns The hash if successful, null otherwise\n */\n// TODO: move to refs.ts\nexport function getCurrentHash(options: GitCommonOptions): string | null;\n/** @deprecated Use object params version */\nexport function getCurrentHash(cwd: string): string | null;\nexport function getCurrentHash(cwdOrOptions: string | GitCommonOptions): string | null {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git([\"rev-parse\", \"HEAD\"], {\n description: \"Getting current git hash\",\n ...options,\n });\n\n return results.success ? results.stdout : null;\n}\n\n/**\n * Get the commit hash in which the file was first added.\n * @returns The commit hash if found, undefined otherwise\n */\n// TODO: move to history.ts\nexport function getFileAddedHash(options: { filename: string } & GitCommonOptions): string | undefined;\n/** @deprecated Use object params version */\nexport function getFileAddedHash(filename: string, cwd: string): string | undefined;\nexport function getFileAddedHash(\n filenameOrOptions: string | ({ filename: string } & GitCommonOptions),\n cwd?: string\n): string | undefined {\n const { filename, ...options } =\n typeof filenameOrOptions === \"string\" ? { filename: filenameOrOptions, cwd: cwd! } : filenameOrOptions;\n\n const results = git([\"rev-list\", \"--max-count=1\", \"HEAD\", filename], options);\n\n return results.success ? results.stdout.trim() : undefined;\n}\n\n/**\n * Run `git init` and verify that the `user.name` and `user.email` configs are set (at any level).\n * Throws an error if `git init` fails.\n *\n * If `user.email` and `user.name` aren't already set globally, and the missing value is provided\n * in params, set it at the repo level. Otherwise, throw an error.\n */\n// TODO: move to init.ts\nexport function init(options: GitInitOptions): void;\n/** @deprecated Use object params version */\nexport function init(cwd: string, email?: string, username?: string): void;\nexport function init(cwdOrOptions: string | GitInitOptions, _email?: string, _username?: string): void {\n const { email, username, ...options } =\n typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions, email: _email, username: _username } : cwdOrOptions;\n\n git([\"init\"], { ...options, throwOnError: true });\n\n if (!getConfigValue({ key: \"user.name\", ...options })) {\n if (!username) {\n throw new Error(\"must include a username when initializing git repo\");\n }\n git([\"config\", \"user.name\", username], options);\n }\n\n if (!getUserEmail(options)) {\n if (!email) {\n throw new Error(\"must include a email when initializing git repo\");\n }\n git([\"config\", \"user.email\", email], options);\n }\n}\n\n/**\n * Stages files matching the given patterns.\n */\n// TODO: move to stageAndCommit.ts\nexport function stage(options: GitStageOptions): void;\n/** @deprecated Use object params version */\nexport function stage(patterns: string[], cwd: string): void;\nexport function stage(patternsOrOptions: string[] | GitStageOptions, cwd?: string): void {\n const { patterns, ...options } = Array.isArray(patternsOrOptions)\n ? { patterns: patternsOrOptions, cwd: cwd! }\n : patternsOrOptions;\n\n for (const pattern of patterns) {\n git([\"add\", pattern], { ...options, description: `Staging changes (git add ${pattern})` });\n }\n}\n\n/**\n * Commit changes. Throws an error on failure by default.\n */\n// TODO: move to stageAndCommit.ts\nexport function commit(options: GitCommitOptions): void;\n/** @deprecated Use object params version */\nexport function commit(message: string, cwd: string, options?: string[]): void;\nexport function commit(messageOrOptions: string | GitCommitOptions, _cwd?: string, _options?: string[]): void {\n const { message, options, ...gitOptions } =\n typeof messageOrOptions === \"string\"\n ? { message: messageOrOptions, cwd: _cwd!, options: _options }\n : messageOrOptions;\n\n git([\"commit\", \"-m\", message, ...(options || [])], {\n throwOnError: true,\n description: \"Committing changes\",\n ...gitOptions,\n });\n}\n\n/**\n * Stages files matching the given patterns and creates a commit with the specified message.\n * Convenience function that combines `stage()` and `commit()`.\n * Throws an error on commit failure by default.\n */\n// TODO: move to stageAndCommit.ts\nexport function stageAndCommit(options: GitStageOptions & GitCommitOptions): void;\n/** @deprecated Use object params version */\nexport function stageAndCommit(patterns: string[], message: string, cwd: string, commitOptions?: string[]): void;\nexport function stageAndCommit(\n patternsOrOptions: string[] | (GitStageOptions & GitCommitOptions),\n message?: string,\n cwd?: string,\n commitOptions?: string[]\n): void {\n const options: GitStageOptions & GitCommitOptions = Array.isArray(patternsOrOptions)\n ? { patterns: patternsOrOptions, message: message!, cwd: cwd!, options: commitOptions }\n : patternsOrOptions;\n\n stage(options);\n commit(options);\n}\n\n/**\n * Reverts all local changes (both staged and unstaged) by stashing them and then dropping the stash.\n * @returns True if the revert was successful, false otherwise. It will also be false if there were\n * no changes to revert. (To distinguish between this case and errors, use the `throwOnError` option.)\n */\n// TODO: move to revertLocalChanges.ts\nexport function revertLocalChanges(options: GitCommonOptions): boolean;\n/** @deprecated Use object params version */\nexport function revertLocalChanges(cwd: string): boolean;\nexport function revertLocalChanges(cwdOrOptions: string | GitCommonOptions): boolean {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const stash = `workspace-tools_${new Date().getTime()}`;\n if (!git([\"stash\", \"push\", \"-u\", \"-m\", stash], options).success) {\n return false;\n }\n\n const results = git([\"stash\", \"list\"], options);\n if (results.success) {\n const matched = results.stdout\n .split(/\\n/)\n .find((line) => line.includes(stash))\n ?.match(/^[^:]+/);\n\n if (matched) {\n git([\"stash\", \"drop\", matched[0]], options);\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Attempts to determine the parent branch of the current branch using `git show-branch`.\n * @returns The parent branch name if found, null otherwise\n * @deprecated Does not appear to be used\n */\nexport function getParentBranch(cwd: string): string | null {\n const branchName = getBranchName({ cwd });\n\n if (!branchName || branchName === \"HEAD\") {\n return null;\n }\n\n const showBranchResult = git([\"show-branch\", \"-a\"], { cwd });\n\n if (showBranchResult.success) {\n const showBranchLines = showBranchResult.stdout.split(/\\n/);\n const parentLine = showBranchLines.find(\n (line) => line.includes(\"*\") && !line.includes(branchName) && !line.includes(\"publish_\")\n );\n\n const matched = parentLine?.match(/\\[(.*)\\]/);\n return matched ? matched[1] : null;\n }\n\n return null;\n}\n\n/**\n * Gets the remote tracking branch for the specified branch.\n *\n * @returns The remote branch name (e.g., `origin/main`) if found, null otherwise\n */\n// TODO: move to refs.ts\nexport function getRemoteBranch(options: GitBranchOptions): string | null;\n/** @deprecated Use object params version */\nexport function getRemoteBranch(branch: string, cwd: string): string | null;\nexport function getRemoteBranch(branchOrOptions: string | GitBranchOptions, cwd?: string): string | null {\n const options: GitBranchOptions =\n typeof branchOrOptions === \"string\" ? { branch: branchOrOptions, cwd: cwd! } : branchOrOptions;\n\n const results = git([\"rev-parse\", \"--abbrev-ref\", \"--symbolic-full-name\", `${options.branch}@{u}`], options);\n\n return results.success ? results.stdout.trim() : null;\n}\n\n/**\n * Get the remote and branch name from a full branch name that may include a remote prefix.\n * If the path doesn't start with one of `options.knownRemotes` (but has multiple segments),\n * the actual list of remotes will be fetched to see if one of those matches.\n *\n * NOTE: The additional verification is new in the object params version; the original version\n * incorrectly assumes the first segment before a slash is always a remote.\n */\n// TODO: move to parseRemoteBranch.ts\nexport function parseRemoteBranch(options: ParseRemoteBranchOptions): ParsedRemoteBranch;\n/**\n * @deprecated Use object params version, which does more verification. This version inaccurately\n * assumes the first segment before a slash is always a remote, which could lead to tricky bugs.\n */\nexport function parseRemoteBranch(branch: string): ParsedRemoteBranch;\nexport function parseRemoteBranch(branchOrOptions: string | ParseRemoteBranchOptions): ParsedRemoteBranch {\n if (typeof branchOrOptions === \"string\") {\n const branch = branchOrOptions;\n const firstSlashPos = branch.indexOf(\"/\", 0);\n return {\n remote: branch.substring(0, firstSlashPos),\n remoteBranch: branch.substring(firstSlashPos + 1),\n };\n }\n\n const { branch, knownRemotes = [\"origin\", \"upstream\"], ...options } = branchOrOptions;\n\n if (!branch.includes(\"/\")) {\n return { remote: \"\", remoteBranch: branch };\n }\n\n let remote = knownRemotes.find((r) => branch.startsWith(`${r}/`));\n\n if (!remote) {\n const remotes = git([\"remote\"], options).stdout.trim().split(/\\n/);\n remote = remotes.find((r) => branch.startsWith(`${r}/`));\n }\n\n if (remote) {\n return { remote, remoteBranch: branch.slice(remote.length + 1) };\n }\n return { remote: \"\", remoteBranch: branch };\n}\n\n/**\n * Gets the default branch based on `git config init.defaultBranch`, falling back to `master`.\n */\n// TODO: move to config.ts\nexport function getDefaultBranch(options: GitCommonOptions): string;\n/** @deprecated Use object params version */\nexport function getDefaultBranch(cwd: string): string;\nexport function getDefaultBranch(cwdOrOptions: string | GitCommonOptions): string {\n const options = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n // Default to the legacy 'master' for backwards compat and old git clients\n return getConfigValue({ key: \"init.defaultBranch\", ...options }) || \"master\";\n}\n\n/**\n * Lists all tracked files matching the given patterns.\n * Throws on error by default.\n * @returns An array of file paths, or an empty array if no files are found\n */\n// TODO: move to history.ts\nexport function listAllTrackedFiles(\n options: {\n /** File patterns to match (passed to git ls-files) */\n patterns: string[];\n } & GitCommonOptions\n): string[];\n/** @deprecated Use object params version */\nexport function listAllTrackedFiles(patterns: string[], cwd: string): string[];\nexport function listAllTrackedFiles(\n patternsOrOptions: string[] | ({ patterns: string[] } & GitCommonOptions),\n cwd?: string\n): string[] {\n const { patterns, ...options } = Array.isArray(patternsOrOptions)\n ? { patterns: patternsOrOptions, cwd: cwd! }\n : patternsOrOptions;\n\n const results = git([\"ls-files\", ...patterns], { throwOnError: true, ...options });\n\n return processGitOutput(results);\n}\n\n/**\n * Get the content of a file at a specific git ref (commit, branch, tag, etc).\n * Returns undefined if the file doesn't exist at that ref or the command fails.\n */\nexport function getFileFromRef(\n params: {\n /** cwd-relative path to the file with *forward* slashes */\n filePath: string;\n /** git ref (branch, tag, commit SHA, etc) to get the file content from */\n ref: string;\n } & GitCommonOptions\n): string | undefined {\n const { filePath, ref, ...options } = params;\n const result = git([\"show\", `${ref}:${filePath}`], {\n description: `Getting file ${filePath} at ref ${ref}`,\n ...options,\n });\n return result.success ? result.stdout : undefined;\n}\n"],"names":["commit","fetchRemote","fetchRemoteBranch","getBranchChanges","getBranchName","getChanges","getChangesBetweenRefs","getCurrentHash","getDefaultBranch","getFileAddedHash","getFileFromRef","getFullBranchRef","getParentBranch","getRecentCommitMessages","getRemoteBranch","getShortBranchName","getStagedChanges","getUnstagedChanges","getUntrackedChanges","getUserEmail","init","listAllTrackedFiles","parseRemoteBranch","revertLocalChanges","stage","stageAndCommit","diffArgs","cwdOrOptions","options","cwd","results","git","description","throwOnError","processGitOutput","excludeNodeModules","remoteOrOptions","remote","remoteBranch","gitOptions","Error","fetchArgs","branch","fromRef","branchOrOptions","toRef","pattern","range","getConfigValue","key","success","stdout","showRefResults","split","refOrOptions","fullBranchRef","filenameOrOptions","filename","trim","undefined","_email","_username","email","username","patternsOrOptions","patterns","Array","isArray","messageOrOptions","_cwd","_options","message","commitOptions","stash","Date","getTime","matched","find","line","includes","match","branchName","showBranchResult","showBranchLines","parentLine","firstSlashPos","indexOf","substring","knownRemotes","r","startsWith","remotes","slice","length","params","filePath","ref","result"],"mappings":"AAAA,EAAE;AACF,+BAA+B;AAC/B,wDAAwD;AACxD,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAmYcA;eAAAA;;QApVAC;eAAAA;;QAgCAC;eAAAA;;QA+CAC;eAAAA;;QA+GAC;eAAAA;;QA7HAC;eAAAA;;QAqCAC;eAAAA;;QAuJAC;eAAAA;;QA4PAC;eAAAA;;QAzOAC;eAAAA;;QA+QAC;eAAAA;;QA9UAC;eAAAA;;QA6MAC;eAAAA;;QAlQAC;eAAAA;;QAiSAC;eAAAA;;QAtNAC;eAAAA;;QAhGAC;eAAAA;;QAzFAC;eAAAA;;QAjEAC;eAAAA;;QAkMAC;eAAAA;;QAwHAC;eAAAA;;QAuOAC;eAAAA;;QAzDAC;eAAAA;;QApFAC;eAAAA;;QA9DAC;eAAAA;;QAuCAC;eAAAA;;;wBAvZe;qBACO;AAatC,MAAMC,WAAW;IAAC;IAAc;IAAQ;IAAe;CAAa;AAY7D,SAASR,oBAAoBS,YAAuC;IACzE,MAAMC,UAA4B,OAAOD,iBAAiB,WAAW;QAAEE,KAAKF;IAAa,IAAIA;IAE7F,MAAMG,UAAUC,IAAAA,QAAG,EAAC;QAAC;QAAY;QAAY;KAAqB,EAAE;QAClEC,aAAa;QACbC,cAAc;QACd,GAAGL,OAAO;IACZ;IACA,OAAOM,IAAAA,qBAAgB,EAACJ,SAAS;QAAEK,oBAAoB;IAAK;AAC9D;AAUO,SAASlC,YAA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;AACtE;AAgBO,SAASP,oBACd2C,iBAAyE,EACzEnC,GAAY;IAEZ,MAAM,EAAEoC,QAAQ,EAAE,GAAGrC,SAAS,GAAGsC,MAAMC,OAAO,CAACH,qBAC3C;QAAEC,UAAUD;QAAmBnC,KAAKA;IAAK,IACzCmC;IAEJ,MAAMlC,UAAUC,IAAAA,QAAG,EAAC;QAAC;WAAekC;KAAS,EAAE;QAAEhC,cAAc;QAAM,GAAGL,OAAO;IAAC;IAEhF,OAAOM,IAAAA,qBAAgB,EAACJ;AAC1B;AAMO,SAASpB,eACdoF,MAKoB;IAEpB,MAAM,EAAEC,QAAQ,EAAEC,GAAG,EAAE,GAAGpE,SAAS,GAAGkE;IACtC,MAAMG,SAASlE,IAAAA,QAAG,EAAC;QAAC;QAAQ,GAAGiE,IAAI,CAAC,EAAED,UAAU;KAAC,EAAE;QACjD/D,aAAa,CAAC,aAAa,EAAE+D,SAAS,QAAQ,EAAEC,KAAK;QACrD,GAAGpE,OAAO;IACZ;IACA,OAAOqE,OAAO/C,OAAO,GAAG+C,OAAO9C,MAAM,GAAGQ;AAC1C"}
|
|
@@ -9,18 +9,23 @@ export declare function isCatalogVersion(version: string): boolean;
|
|
|
9
9
|
*
|
|
10
10
|
* Throws an error if there's anything invalid about the catalog spec (no catalogs defined,
|
|
11
11
|
* no matching catalog, catalog doesn't contain `name`, recursive catalog version).
|
|
12
|
+
* If `allowNotFound` is true, it will return undefined if no match instead.
|
|
12
13
|
*
|
|
13
14
|
* Returns undefined if the version doesn't start with `catalog:`.
|
|
14
15
|
* @see https://pnpm.io/catalogs
|
|
15
16
|
* @see https://yarnpkg.com/features/catalogs
|
|
16
17
|
*
|
|
17
|
-
* @param name - Dependency package name
|
|
18
|
-
* @param version - Dependency version spec, e.g. `catalog:my-catalog` or `catalog:`,
|
|
19
|
-
* or some non-catalog spec like `^1.2.3`
|
|
20
18
|
* @returns Actual version spec from the catalog, or undefined if not a catalog version
|
|
19
|
+
* (or undefined if `allowNotFound` is true and the package isn't in the catalog)
|
|
21
20
|
*/
|
|
22
21
|
export declare function getCatalogVersion(params: {
|
|
22
|
+
/** Dependency package name */
|
|
23
23
|
name: string;
|
|
24
|
+
/**
|
|
25
|
+
* Dependency version spec, e.g. `catalog:my-catalog` or `catalog:`, or some non-catalog
|
|
26
|
+
* spec like `^1.2.3`
|
|
27
|
+
*/
|
|
24
28
|
version: string;
|
|
25
29
|
catalogs: Catalogs | undefined;
|
|
30
|
+
allowNotFound?: boolean;
|
|
26
31
|
}): string | undefined;
|
|
@@ -25,11 +25,14 @@ function isCatalogVersion(version) {
|
|
|
25
25
|
return version.startsWith(catalogPrefix);
|
|
26
26
|
}
|
|
27
27
|
function getCatalogVersion(params) {
|
|
28
|
-
const { name, version, catalogs } = params;
|
|
28
|
+
const { name, version, catalogs, allowNotFound } = params;
|
|
29
29
|
if (!isCatalogVersion(version)) {
|
|
30
30
|
return undefined;
|
|
31
31
|
}
|
|
32
32
|
if (!catalogs) {
|
|
33
|
+
if (allowNotFound) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
33
36
|
throw new Error(`Dependency "${name}" uses a catalog version "${version}" but no catalogs are defined.`);
|
|
34
37
|
}
|
|
35
38
|
const catalogName = version.slice(catalogPrefix.length);
|
|
@@ -39,11 +42,14 @@ function getCatalogVersion(params) {
|
|
|
39
42
|
// and yarn install would have errored if a named catalog "default" was referenced but not defined.)
|
|
40
43
|
catalogName === "default" ? catalogs.named?.default || catalogs.default : catalogName ? catalogs.named?.[catalogName] : catalogs.default;
|
|
41
44
|
const catalogNameStr = catalogName ? `catalogs.${catalogName}` : "the default catalog";
|
|
42
|
-
if (!checkCatalog) {
|
|
45
|
+
if (!checkCatalog && !allowNotFound) {
|
|
43
46
|
throw new Error(`Dependency "${name}" uses a catalog version "${version}" but ${catalogNameStr} is not defined.`);
|
|
44
47
|
}
|
|
45
|
-
const actualSpec = checkCatalog[name];
|
|
48
|
+
const actualSpec = checkCatalog?.[name];
|
|
46
49
|
if (!actualSpec) {
|
|
50
|
+
if (allowNotFound) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
47
53
|
throw new Error(`Dependency "${name}" uses a catalog version "${version}", but ${catalogNameStr} doesn't define a version for "${name}".`);
|
|
48
54
|
}
|
|
49
55
|
if (isCatalogVersion(actualSpec)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/workspaces/getCatalogVersion.ts"],"sourcesContent":["import type { Catalogs } from \"../types/Catalogs.js\";\n\nconst catalogPrefix = \"catalog:\";\n\n/**\n * Returns true if the version starts with `catalog:`.\n */\nexport function isCatalogVersion(version: string): boolean {\n return version.startsWith(catalogPrefix);\n}\n\n/**\n * Given a dependency package name and a version spec string, if the version starts with `catalog:`,\n * look up the actual version spec (not the final resolved version) from the given catalogs.\n *\n * Throws an error if there's anything invalid about the catalog spec (no catalogs defined,\n * no matching catalog, catalog doesn't contain `name`, recursive catalog version).\n *\n * Returns undefined if the version doesn't start with `catalog:`.\n * @see https://pnpm.io/catalogs\n * @see https://yarnpkg.com/features/catalogs\n *\n * @
|
|
1
|
+
{"version":3,"sources":["../../src/workspaces/getCatalogVersion.ts"],"sourcesContent":["import type { Catalogs } from \"../types/Catalogs.js\";\n\nconst catalogPrefix = \"catalog:\";\n\n/**\n * Returns true if the version starts with `catalog:`.\n */\nexport function isCatalogVersion(version: string): boolean {\n return version.startsWith(catalogPrefix);\n}\n\n/**\n * Given a dependency package name and a version spec string, if the version starts with `catalog:`,\n * look up the actual version spec (not the final resolved version) from the given catalogs.\n *\n * Throws an error if there's anything invalid about the catalog spec (no catalogs defined,\n * no matching catalog, catalog doesn't contain `name`, recursive catalog version).\n * If `allowNotFound` is true, it will return undefined if no match instead.\n *\n * Returns undefined if the version doesn't start with `catalog:`.\n * @see https://pnpm.io/catalogs\n * @see https://yarnpkg.com/features/catalogs\n *\n * @returns Actual version spec from the catalog, or undefined if not a catalog version\n * (or undefined if `allowNotFound` is true and the package isn't in the catalog)\n */\nexport function getCatalogVersion(params: {\n /** Dependency package name */\n name: string;\n /**\n * Dependency version spec, e.g. `catalog:my-catalog` or `catalog:`, or some non-catalog\n * spec like `^1.2.3`\n */\n version: string;\n catalogs: Catalogs | undefined;\n allowNotFound?: boolean;\n}): string | undefined {\n const { name, version, catalogs, allowNotFound } = params;\n\n if (!isCatalogVersion(version)) {\n return undefined;\n }\n\n if (!catalogs) {\n if (allowNotFound) {\n return undefined;\n }\n throw new Error(`Dependency \"${name}\" uses a catalog version \"${version}\" but no catalogs are defined.`);\n }\n\n const catalogName = version.slice(catalogPrefix.length);\n const checkCatalog =\n // Explicit catalog:default refers to the default catalog in pnpm, or a catalog named \"default\"\n // in yarn... Check for the yarn case first or fall back to .default. (getCatalogs should have\n // removed the named \"default\" catalog from namedCatalogs in managers where they're the same,\n // and yarn install would have errored if a named catalog \"default\" was referenced but not defined.)\n catalogName === \"default\"\n ? catalogs.named?.default || catalogs.default\n : // Otherwise use either the given named catalog, or the default if no name was specified\n catalogName\n ? catalogs.named?.[catalogName]\n : catalogs.default;\n const catalogNameStr = catalogName ? `catalogs.${catalogName}` : \"the default catalog\";\n\n if (!checkCatalog && !allowNotFound) {\n throw new Error(`Dependency \"${name}\" uses a catalog version \"${version}\" but ${catalogNameStr} is not defined.`);\n }\n\n const actualSpec = checkCatalog?.[name];\n if (!actualSpec) {\n if (allowNotFound) {\n return undefined;\n }\n throw new Error(\n `Dependency \"${name}\" uses a catalog version \"${version}\", but ${catalogNameStr} doesn't define a version for \"${name}\".`\n );\n }\n\n if (isCatalogVersion(actualSpec)) {\n throw new Error(\n `Dependency \"${name}\" resolves to a recursive catalog version \"${actualSpec}\", which is not supported.`\n );\n }\n\n return actualSpec;\n}\n"],"names":["getCatalogVersion","isCatalogVersion","catalogPrefix","version","startsWith","params","name","catalogs","allowNotFound","undefined","Error","catalogName","slice","length","checkCatalog","named","default","catalogNameStr","actualSpec"],"mappings":";;;;;;;;;;;;;;;QA0BgBA;eAAAA;;QAnBAC;eAAA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