@altano/repository-tools 2.1.0 → 2.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.
|
@@ -76,7 +76,12 @@ function repositoryExecSync(cwd, command, args) {
|
|
|
76
76
|
return execFileSync(command, args, {
|
|
77
77
|
cwd,
|
|
78
78
|
encoding: "utf8",
|
|
79
|
-
env: getEnvironment(command)
|
|
79
|
+
env: getEnvironment(command),
|
|
80
|
+
stdio: [
|
|
81
|
+
"ignore",
|
|
82
|
+
"pipe",
|
|
83
|
+
"pipe"
|
|
84
|
+
]
|
|
80
85
|
}).trim();
|
|
81
86
|
}
|
|
82
87
|
const createExecForDirectory = (cwd) => repositoryExec.bind(null, cwd);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repositoryCommand.js","names":[],"sources":["../src/repositoryCommand.ts"],"sourcesContent":["import { execFileAsync, execFileSync } from \"./exec.js\";\nimport {} from \"child_process\";\n\ntype RepositoryCommand =\n \"git\" | \"hg\" | \"jj\" | \"sl\" | \"svn\" | \"svnadmin\" | \"svnrdump\";\n\nconst environment = {\n git: {\n // non-interactive\n GIT_TERMINAL_PROMPT: \"0\",\n // don't use global config\n GIT_CONFIG_GLOBAL: \"/dev/null\",\n GIT_CONFIG_SYSTEM: \"/dev/null\",\n // user config\n GIT_COMMITTER_NAME: \"alan\",\n GIT_COMMITTER_EMAIL: \"alan@example.com\",\n GIT_AUTHOR_NAME: \"alan\",\n GIT_AUTHOR_EMAIL: \"alan@example.com\",\n },\n jj: {\n // don't use global config\n JJ_CONFIG: \"/dev/null\",\n // user config. Without an identity jj warns on stderr, which we treat as a\n // failed command.\n JJ_USER: \"alan\",\n JJ_EMAIL: \"alan@example.com\",\n },\n hg: {\n // don't use global config\n HGRCPATH: \"/dev/null\",\n // don't use global config\n HGUSER: \"alan\",\n EMAIL: \"alan@example.com\",\n },\n sl: {\n // don't use global config\n HGRCPATH: \"/dev/null\",\n // don't use global config\n HGUSER: \"alan\",\n EMAIL: \"alan@example.com\",\n },\n svn: {},\n svnadmin: {},\n svnrdump: {},\n} as const satisfies Record<RepositoryCommand, NodeJS.ProcessEnv>;\n\n/**\n * Environment variables that pin git to one particular repository, work tree,\n * index, or object store.\n *\n * Git exports several of these before running a hook, so every process a hook\n * spawns inherits them. We always point git at a directory of our choosing\n * (via cwd) and want an answer about *that* directory, so they have to go.\n *\n * GIT_DIR is the worst offender: when it is set and GIT_WORK_TREE isn't, git\n * skips repository discovery entirely and \"tells Git that you are at the top\n * level of the working tree\", so `git rev-parse --show-toplevel` echoes back\n * the directory we asked about instead of the root containing it.\n *\n * https://github.com/altano/npm-packages/issues/299\n *\n * Variables that only tune discovery, and that a user has to opt into\n * deliberately (GIT_CEILING_DIRECTORIES, GIT_DISCOVERY_ACROSS_FILESYSTEM), are\n * intentionally left alone.\n */\nconst gitRepositoryVariables = [\n \"GIT_DIR\",\n \"GIT_WORK_TREE\",\n \"GIT_COMMON_DIR\",\n \"GIT_INDEX_FILE\",\n \"GIT_INDEX_VERSION\",\n \"GIT_OBJECT_DIRECTORY\",\n \"GIT_ALTERNATE_OBJECT_DIRECTORIES\",\n \"GIT_NAMESPACE\",\n \"GIT_PREFIX\",\n \"GIT_QUARANTINE_PATH\",\n] as const;\n\n/**\n * Inherited environment variables to drop, per command. The other version\n * control systems have no equivalent of GIT_DIR: they're told which repository\n * to use with a flag, never with the environment.\n */\nconst removedEnvironment = {\n git: gitRepositoryVariables,\n // jj takes a repository with -R/--repository and finds one by walking up to\n // the closest .jj, a search git's variables have no say in. Verified: from a\n // subdirectory of a colocated repo, `jj root` answers correctly with GIT_DIR\n // set to a value that makes git itself bail out.\n jj: [],\n hg: [],\n sl: [],\n svn: [],\n svnadmin: [],\n svnrdump: [],\n} as const satisfies Record<RepositoryCommand, readonly string[]>;\n\nfunction getEnvironment(command: RepositoryCommand): NodeJS.ProcessEnv {\n const result: NodeJS.ProcessEnv = {\n ...process.env,\n ...environment[command],\n };\n for (const variable of removedEnvironment[command]) {\n delete result[variable];\n }\n return result;\n}\n\nexport async function repositoryExec(\n cwd: string,\n command: RepositoryCommand,\n args: readonly string[],\n): Promise<string> {\n // const msg = `Executing command: ${command} ${args.join(\" \")}`;\n // console.time(msg);\n return execFileAsync(command, args, {\n cwd: cwd,\n encoding: \"utf8\",\n env: getEnvironment(command),\n }).then(({ stdout, stderr }) => {\n // console.timeEnd(msg);\n return stderr ? Promise.reject(new Error(stderr.trim())) : stdout.trim();\n });\n}\n\nexport function repositoryExecSync(\n cwd: string,\n command: RepositoryCommand,\n args: readonly string[],\n): string {\n // const msg = `Executing command: ${command} ${args.join(\" \")}`;\n // console.time(msg);\n const result = execFileSync(command, args, {\n cwd: cwd,\n encoding: \"utf8\",\n env: getEnvironment(command),\n }).trim();\n // console.timeEnd(msg);\n return result;\n}\n\nexport const createExecForDirectory = (\n cwd: string,\n): ((command: RepositoryCommand, args: readonly string[]) => Promise<string>) =>\n repositoryExec.bind(null, cwd);\n\n// Not being used.\n// export const createExecSyncForDirectory = (\n// cwd: string,\n// ): ((command: RepositoryCommand, args: readonly string[]) => string) =>\n// repositoryExecSync.bind(null, cwd);\n"],"mappings":";;;AAMA,MAAM,cAAc;CAClB,KAAK;EAEH,qBAAqB;EAErB,mBAAmB;EACnB,mBAAmB;EAEnB,oBAAoB;EACpB,qBAAqB;EACrB,iBAAiB;EACjB,kBAAkB;CACpB;CACA,IAAI;EAEF,WAAW;EAGX,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EAEF,UAAU;EAEV,QAAQ;EACR,OAAO;CACT;CACA,IAAI;EAEF,UAAU;EAEV,QAAQ;EACR,OAAO;CACT;CACA,KAAK,CAAC;CACN,UAAU,CAAC;CACX,UAAU,CAAC;AACb;;;;;;AAuCA,MAAM,qBAAqB;CACzB,KAAK;EAlBL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CAS0B;CAK1B,IAAI,CAAC;CACL,IAAI,CAAC;CACL,IAAI,CAAC;CACL,KAAK,CAAC;CACN,UAAU,CAAC;CACX,UAAU,CAAC;AACb;AAEA,SAAS,eAAe,SAA+C;CACrE,MAAM,SAA4B;EAChC,GAAG,QAAQ;EACX,GAAG,YAAY;CACjB;CACA,KAAK,MAAM,YAAY,mBAAmB,UACxC,OAAO,OAAO;CAEhB,OAAO;AACT;AAEA,eAAsB,eACpB,KACA,SACA,MACiB;CAGjB,OAAO,cAAc,SAAS,MAAM;EAC7B;EACL,UAAU;EACV,KAAK,eAAe,OAAO;CAC7B,CAAC,CAAC,CAAC,MAAM,EAAE,QAAQ,aAAa;EAE9B,OAAO,SAAS,QAAQ,OAAO,IAAI,MAAM,OAAO,KAAK,CAAC,CAAC,IAAI,OAAO,KAAK;CACzE,CAAC;AACH;AAEA,SAAgB,mBACd,KACA,SACA,MACQ;
|
|
1
|
+
{"version":3,"file":"repositoryCommand.js","names":[],"sources":["../src/repositoryCommand.ts"],"sourcesContent":["import { execFileAsync, execFileSync } from \"./exec.js\";\nimport {} from \"child_process\";\n\ntype RepositoryCommand =\n \"git\" | \"hg\" | \"jj\" | \"sl\" | \"svn\" | \"svnadmin\" | \"svnrdump\";\n\nconst environment = {\n git: {\n // non-interactive\n GIT_TERMINAL_PROMPT: \"0\",\n // don't use global config\n GIT_CONFIG_GLOBAL: \"/dev/null\",\n GIT_CONFIG_SYSTEM: \"/dev/null\",\n // user config\n GIT_COMMITTER_NAME: \"alan\",\n GIT_COMMITTER_EMAIL: \"alan@example.com\",\n GIT_AUTHOR_NAME: \"alan\",\n GIT_AUTHOR_EMAIL: \"alan@example.com\",\n },\n jj: {\n // don't use global config\n JJ_CONFIG: \"/dev/null\",\n // user config. Without an identity jj warns on stderr, which we treat as a\n // failed command.\n JJ_USER: \"alan\",\n JJ_EMAIL: \"alan@example.com\",\n },\n hg: {\n // don't use global config\n HGRCPATH: \"/dev/null\",\n // don't use global config\n HGUSER: \"alan\",\n EMAIL: \"alan@example.com\",\n },\n sl: {\n // don't use global config\n HGRCPATH: \"/dev/null\",\n // don't use global config\n HGUSER: \"alan\",\n EMAIL: \"alan@example.com\",\n },\n svn: {},\n svnadmin: {},\n svnrdump: {},\n} as const satisfies Record<RepositoryCommand, NodeJS.ProcessEnv>;\n\n/**\n * Environment variables that pin git to one particular repository, work tree,\n * index, or object store.\n *\n * Git exports several of these before running a hook, so every process a hook\n * spawns inherits them. We always point git at a directory of our choosing\n * (via cwd) and want an answer about *that* directory, so they have to go.\n *\n * GIT_DIR is the worst offender: when it is set and GIT_WORK_TREE isn't, git\n * skips repository discovery entirely and \"tells Git that you are at the top\n * level of the working tree\", so `git rev-parse --show-toplevel` echoes back\n * the directory we asked about instead of the root containing it.\n *\n * https://github.com/altano/npm-packages/issues/299\n *\n * Variables that only tune discovery, and that a user has to opt into\n * deliberately (GIT_CEILING_DIRECTORIES, GIT_DISCOVERY_ACROSS_FILESYSTEM), are\n * intentionally left alone.\n */\nconst gitRepositoryVariables = [\n \"GIT_DIR\",\n \"GIT_WORK_TREE\",\n \"GIT_COMMON_DIR\",\n \"GIT_INDEX_FILE\",\n \"GIT_INDEX_VERSION\",\n \"GIT_OBJECT_DIRECTORY\",\n \"GIT_ALTERNATE_OBJECT_DIRECTORIES\",\n \"GIT_NAMESPACE\",\n \"GIT_PREFIX\",\n \"GIT_QUARANTINE_PATH\",\n] as const;\n\n/**\n * Inherited environment variables to drop, per command. The other version\n * control systems have no equivalent of GIT_DIR: they're told which repository\n * to use with a flag, never with the environment.\n */\nconst removedEnvironment = {\n git: gitRepositoryVariables,\n // jj takes a repository with -R/--repository and finds one by walking up to\n // the closest .jj, a search git's variables have no say in. Verified: from a\n // subdirectory of a colocated repo, `jj root` answers correctly with GIT_DIR\n // set to a value that makes git itself bail out.\n jj: [],\n hg: [],\n sl: [],\n svn: [],\n svnadmin: [],\n svnrdump: [],\n} as const satisfies Record<RepositoryCommand, readonly string[]>;\n\nfunction getEnvironment(command: RepositoryCommand): NodeJS.ProcessEnv {\n const result: NodeJS.ProcessEnv = {\n ...process.env,\n ...environment[command],\n };\n for (const variable of removedEnvironment[command]) {\n delete result[variable];\n }\n return result;\n}\n\nexport async function repositoryExec(\n cwd: string,\n command: RepositoryCommand,\n args: readonly string[],\n): Promise<string> {\n // const msg = `Executing command: ${command} ${args.join(\" \")}`;\n // console.time(msg);\n return execFileAsync(command, args, {\n cwd: cwd,\n encoding: \"utf8\",\n env: getEnvironment(command),\n }).then(({ stdout, stderr }) => {\n // console.timeEnd(msg);\n return stderr ? Promise.reject(new Error(stderr.trim())) : stdout.trim();\n });\n}\n\nexport function repositoryExecSync(\n cwd: string,\n command: RepositoryCommand,\n args: readonly string[],\n): string {\n // const msg = `Executing command: ${command} ${args.join(\" \")}`;\n // console.time(msg);\n const result = execFileSync(command, args, {\n cwd: cwd,\n encoding: \"utf8\",\n env: getEnvironment(command),\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n }).trim();\n // console.timeEnd(msg);\n return result;\n}\n\nexport const createExecForDirectory = (\n cwd: string,\n): ((command: RepositoryCommand, args: readonly string[]) => Promise<string>) =>\n repositoryExec.bind(null, cwd);\n\n// Not being used.\n// export const createExecSyncForDirectory = (\n// cwd: string,\n// ): ((command: RepositoryCommand, args: readonly string[]) => string) =>\n// repositoryExecSync.bind(null, cwd);\n"],"mappings":";;;AAMA,MAAM,cAAc;CAClB,KAAK;EAEH,qBAAqB;EAErB,mBAAmB;EACnB,mBAAmB;EAEnB,oBAAoB;EACpB,qBAAqB;EACrB,iBAAiB;EACjB,kBAAkB;CACpB;CACA,IAAI;EAEF,WAAW;EAGX,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EAEF,UAAU;EAEV,QAAQ;EACR,OAAO;CACT;CACA,IAAI;EAEF,UAAU;EAEV,QAAQ;EACR,OAAO;CACT;CACA,KAAK,CAAC;CACN,UAAU,CAAC;CACX,UAAU,CAAC;AACb;;;;;;AAuCA,MAAM,qBAAqB;CACzB,KAAK;EAlBL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CAS0B;CAK1B,IAAI,CAAC;CACL,IAAI,CAAC;CACL,IAAI,CAAC;CACL,KAAK,CAAC;CACN,UAAU,CAAC;CACX,UAAU,CAAC;AACb;AAEA,SAAS,eAAe,SAA+C;CACrE,MAAM,SAA4B;EAChC,GAAG,QAAQ;EACX,GAAG,YAAY;CACjB;CACA,KAAK,MAAM,YAAY,mBAAmB,UACxC,OAAO,OAAO;CAEhB,OAAO;AACT;AAEA,eAAsB,eACpB,KACA,SACA,MACiB;CAGjB,OAAO,cAAc,SAAS,MAAM;EAC7B;EACL,UAAU;EACV,KAAK,eAAe,OAAO;CAC7B,CAAC,CAAC,CAAC,MAAM,EAAE,QAAQ,aAAa;EAE9B,OAAO,SAAS,QAAQ,OAAO,IAAI,MAAM,OAAO,KAAK,CAAC,CAAC,IAAI,OAAO,KAAK;CACzE,CAAC;AACH;AAEA,SAAgB,mBACd,KACA,SACA,MACQ;CAUR,OAPe,aAAa,SAAS,MAAM;EACpC;EACL,UAAU;EACV,KAAK,eAAe,OAAO;EAC3B,OAAO;GAAC;GAAU;GAAQ;EAAM;CAClC,CAAC,CAAC,CAAC,KAES;AACd;AAEA,MAAa,0BACX,QAEA,eAAe,KAAK,MAAM,GAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altano/repository-tools",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Misc tools for dealing with repositories of multiple version control systems (git, svn, etc)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"repository",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"typescript": "^6.0.3",
|
|
53
53
|
"vite": "^8.1.5",
|
|
54
54
|
"vitest": "^4.1.10",
|
|
55
|
-
"@altano/disposable-directory": "0.0.3",
|
|
56
55
|
"@altano/build-config": "0.0.1",
|
|
56
|
+
"@altano/disposable-directory": "0.0.3",
|
|
57
57
|
"@altano/tsconfig": "0.0.1",
|
|
58
58
|
"@altano/testing": "0.0.1"
|
|
59
59
|
},
|