@altano/repository-tools 2.0.4 → 2.1.0

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/README.md CHANGED
@@ -7,6 +7,7 @@ Misc tools for dealing with repositories of multiple version control systems
7
7
  ## Supported Version Control Systems
8
8
 
9
9
  - git
10
+ - jujutsu (jj), colocated with git or not
10
11
  - mercurial
11
12
  - sapling
12
13
  - subversion
package/dist/findRoot.js CHANGED
@@ -8,6 +8,18 @@ async function findGitRoot(directory) {
8
8
  "--show-toplevel"
9
9
  ]);
10
10
  }
11
+ /**
12
+ * `--ignore-working-copy` keeps this a read-only operation. Every other jj
13
+ * command snapshots the working copy first, which takes the working-copy lock
14
+ * and writes a new operation to the repository we were only asked to locate.
15
+ */
16
+ async function findJujutsuRoot(directory) {
17
+ return repositoryExec(directory, "jj", [
18
+ "--ignore-working-copy",
19
+ "--quiet",
20
+ "root"
21
+ ]);
22
+ }
11
23
  async function findSaplingRoot(directory) {
12
24
  return repositoryExec(directory, "sl", ["--quiet", "root"]);
13
25
  }
@@ -23,6 +35,7 @@ async function findSubversionRoot(directory) {
23
35
  }
24
36
  const findMethods = [
25
37
  findGitRoot,
38
+ findJujutsuRoot,
26
39
  findSubversionRoot,
27
40
  findSaplingRoot,
28
41
  findMercurialRoot
@@ -1 +1 @@
1
- {"version":3,"file":"findRoot.js","names":[],"sources":["../src/findRoot.ts"],"sourcesContent":["import { repositoryExec } from \"./repositoryCommand.js\";\n\nasync function findGitRoot(directory: string): Promise<string> {\n return repositoryExec(directory, \"git\", [\n \"rev-parse\",\n \"--quiet\",\n \"--show-toplevel\",\n ]);\n}\n\nasync function findSaplingRoot(directory: string): Promise<string> {\n return repositoryExec(directory, \"sl\", [\"--quiet\", \"root\"]);\n}\n\nasync function findMercurialRoot(directory: string): Promise<string> {\n return repositoryExec(directory, \"hg\", [\"--quiet\", \"root\"]);\n}\n\nasync function findSubversionRoot(directory: string): Promise<string> {\n return repositoryExec(directory, \"svn\", [\"info\", \"--show-item\", \"wc-root\"]);\n}\n\n// Version control systems to check for. Highest-precedence checks go first.\nconst findMethods = [\n findGitRoot, // most used and fastest check\n findSubversionRoot, // next highest market share\n findSaplingRoot, // much smaller market share, but much faster\n findMercurialRoot, // slow af\n] as const;\n\n/**\n * Find the root path of the repository containing the given directory.\n *\n * @returns null if not found or the path of the repository root as a string\n */\nexport async function findRoot(\n /**\n * The directory path of anything in a version-controlled repository\n */\n directory: string,\n): Promise<string | null> {\n for (const method of findMethods) {\n try {\n const result = await method(directory);\n /* v8 ignore if */\n if (result != null && result !== \"\") {\n return result;\n }\n } catch (e: unknown) {\n if (e instanceof Error && \"code\" in e && e.code === \"ENOTDIR\") {\n // rethrow error when given directory path isn't a directory\n throw new Error(`Given path isn't a directory: ${directory}`);\n }\n }\n }\n return null;\n}\n"],"mappings":";;;AAEA,eAAe,YAAY,WAAoC;CAC7D,OAAO,eAAe,WAAW,OAAO;EACtC;EACA;EACA;CACF,CAAC;AACH;AAEA,eAAe,gBAAgB,WAAoC;CACjE,OAAO,eAAe,WAAW,MAAM,CAAC,WAAW,MAAM,CAAC;AAC5D;AAEA,eAAe,kBAAkB,WAAoC;CACnE,OAAO,eAAe,WAAW,MAAM,CAAC,WAAW,MAAM,CAAC;AAC5D;AAEA,eAAe,mBAAmB,WAAoC;CACpE,OAAO,eAAe,WAAW,OAAO;EAAC;EAAQ;EAAe;CAAS,CAAC;AAC5E;AAGA,MAAM,cAAc;CAClB;CACA;CACA;CACA;AACF;;;;;;AAOA,eAAsB,SAIpB,WACwB;CACxB,KAAK,MAAM,UAAU,aACnB,IAAI;EACF,MAAM,SAAS,MAAM,OAAO,SAAS;;EAErC,IAAI,UAAU,QAAQ,WAAW,IAC/B,OAAO;CAEX,SAAS,GAAY;EACnB,IAAI,aAAa,SAAS,UAAU,KAAK,EAAE,SAAS,WAElD,MAAM,IAAI,MAAM,iCAAiC,WAAW;CAEhE;CAEF,OAAO;AACT"}
1
+ {"version":3,"file":"findRoot.js","names":[],"sources":["../src/findRoot.ts"],"sourcesContent":["import { repositoryExec } from \"./repositoryCommand.js\";\n\nasync function findGitRoot(directory: string): Promise<string> {\n return repositoryExec(directory, \"git\", [\n \"rev-parse\",\n \"--quiet\",\n \"--show-toplevel\",\n ]);\n}\n\n/**\n * `--ignore-working-copy` keeps this a read-only operation. Every other jj\n * command snapshots the working copy first, which takes the working-copy lock\n * and writes a new operation to the repository we were only asked to locate.\n */\nasync function findJujutsuRoot(directory: string): Promise<string> {\n return repositoryExec(directory, \"jj\", [\n \"--ignore-working-copy\",\n \"--quiet\",\n \"root\",\n ]);\n}\n\nasync function findSaplingRoot(directory: string): Promise<string> {\n return repositoryExec(directory, \"sl\", [\"--quiet\", \"root\"]);\n}\n\nasync function findMercurialRoot(directory: string): Promise<string> {\n return repositoryExec(directory, \"hg\", [\"--quiet\", \"root\"]);\n}\n\nasync function findSubversionRoot(directory: string): Promise<string> {\n return repositoryExec(directory, \"svn\", [\"info\", \"--show-item\", \"wc-root\"]);\n}\n\n// Version control systems to check for. Highest-precedence checks go first.\nconst findMethods = [\n findGitRoot, // most used and fastest check\n // Runs almost as fast as git's check. A colocated jj repo (jj's default) has\n // a .git too and never reaches this, so this only works for non-colocated\n // repos and jj workspace directories, which git can't see at all.\n findJujutsuRoot,\n findSubversionRoot, // next highest market share\n findSaplingRoot, // much smaller market share, but much faster\n findMercurialRoot, // slow af\n] as const;\n\n/**\n * Find the root path of the repository containing the given directory.\n *\n * @returns null if not found or the path of the repository root as a string\n */\nexport async function findRoot(\n /**\n * The directory path of anything in a version-controlled repository\n */\n directory: string,\n): Promise<string | null> {\n for (const method of findMethods) {\n try {\n const result = await method(directory);\n /* v8 ignore if */\n if (result != null && result !== \"\") {\n return result;\n }\n } catch (e: unknown) {\n if (e instanceof Error && \"code\" in e && e.code === \"ENOTDIR\") {\n // rethrow error when given directory path isn't a directory\n throw new Error(`Given path isn't a directory: ${directory}`);\n }\n }\n }\n return null;\n}\n"],"mappings":";;;AAEA,eAAe,YAAY,WAAoC;CAC7D,OAAO,eAAe,WAAW,OAAO;EACtC;EACA;EACA;CACF,CAAC;AACH;;;;;;AAOA,eAAe,gBAAgB,WAAoC;CACjE,OAAO,eAAe,WAAW,MAAM;EACrC;EACA;EACA;CACF,CAAC;AACH;AAEA,eAAe,gBAAgB,WAAoC;CACjE,OAAO,eAAe,WAAW,MAAM,CAAC,WAAW,MAAM,CAAC;AAC5D;AAEA,eAAe,kBAAkB,WAAoC;CACnE,OAAO,eAAe,WAAW,MAAM,CAAC,WAAW,MAAM,CAAC;AAC5D;AAEA,eAAe,mBAAmB,WAAoC;CACpE,OAAO,eAAe,WAAW,OAAO;EAAC;EAAQ;EAAe;CAAS,CAAC;AAC5E;AAGA,MAAM,cAAc;CAClB;CAIA;CACA;CACA;CACA;AACF;;;;;;AAOA,eAAsB,SAIpB,WACwB;CACxB,KAAK,MAAM,UAAU,aACnB,IAAI;EACF,MAAM,SAAS,MAAM,OAAO,SAAS;;EAErC,IAAI,UAAU,QAAQ,WAAW,IAC/B,OAAO;CAEX,SAAS,GAAY;EACnB,IAAI,aAAa,SAAS,UAAU,KAAK,EAAE,SAAS,WAElD,MAAM,IAAI,MAAM,iCAAiC,WAAW;CAEhE;CAEF,OAAO;AACT"}
@@ -8,6 +8,18 @@ function findGitRoot(cwd) {
8
8
  "--show-toplevel"
9
9
  ]);
10
10
  }
11
+ /**
12
+ * `--ignore-working-copy` keeps this a read-only operation. Every other jj
13
+ * command snapshots the working copy first, which takes the working-copy lock
14
+ * and writes a new operation to the repository we were only asked to locate.
15
+ */
16
+ function findJujutsuRoot(cwd) {
17
+ return repositoryExecSync(cwd, "jj", [
18
+ "--ignore-working-copy",
19
+ "--quiet",
20
+ "root"
21
+ ]);
22
+ }
11
23
  function findSaplingRoot(cwd) {
12
24
  return repositoryExecSync(cwd, "sl", ["--quiet", "root"]);
13
25
  }
@@ -23,6 +35,7 @@ function findSubversionRoot(cwd) {
23
35
  }
24
36
  const findMethods = [
25
37
  findGitRoot,
38
+ findJujutsuRoot,
26
39
  findSubversionRoot,
27
40
  findSaplingRoot,
28
41
  findMercurialRoot
@@ -1 +1 @@
1
- {"version":3,"file":"findRootSync.js","names":[],"sources":["../src/findRootSync.ts"],"sourcesContent":["import { repositoryExecSync } from \"./repositoryCommand.js\";\n\nfunction findGitRoot(cwd: string): string {\n return repositoryExecSync(cwd, \"git\", [\n \"rev-parse\",\n \"--quiet\",\n \"--show-toplevel\",\n ]);\n}\n\nfunction findSaplingRoot(cwd: string): string {\n return repositoryExecSync(cwd, \"sl\", [\"--quiet\", \"root\"]);\n}\n\nfunction findMercurialRoot(cwd: string): string {\n return repositoryExecSync(cwd, \"hg\", [\"--quiet\", \"root\"]);\n}\n\nfunction findSubversionRoot(cwd: string): string {\n return repositoryExecSync(cwd, \"svn\", [\"info\", \"--show-item\", \"wc-root\"]);\n}\n\n// Version control systems to check for. Highest-precedence checks go first.\nconst findMethods = [\n findGitRoot, // most used and fastest check\n findSubversionRoot, // next highest market share\n findSaplingRoot, // much smaller market share, but much faster\n findMercurialRoot, // slow af\n] as const;\n\n/**\n * Find the root path of the repository containing the given directory.\n *\n * @returns null if not found or the path of the repository root as a string\n */\nexport function findRootSync(\n /**\n * The directory path of anything in a version-controlled repository\n */\n directory: string,\n): string | null {\n for (const method of findMethods) {\n try {\n const result = method(directory);\n if (result != null && result !== \"\") {\n return result;\n }\n } catch (e: unknown) {\n if (e instanceof Error && \"code\" in e && e.code === \"ENOTDIR\") {\n // rethrow error when given directory path isn't a directory\n throw new Error(`Given path isn't a directory: ${directory}`);\n }\n }\n }\n return null;\n}\n"],"mappings":";;;AAEA,SAAS,YAAY,KAAqB;CACxC,OAAO,mBAAmB,KAAK,OAAO;EACpC;EACA;EACA;CACF,CAAC;AACH;AAEA,SAAS,gBAAgB,KAAqB;CAC5C,OAAO,mBAAmB,KAAK,MAAM,CAAC,WAAW,MAAM,CAAC;AAC1D;AAEA,SAAS,kBAAkB,KAAqB;CAC9C,OAAO,mBAAmB,KAAK,MAAM,CAAC,WAAW,MAAM,CAAC;AAC1D;AAEA,SAAS,mBAAmB,KAAqB;CAC/C,OAAO,mBAAmB,KAAK,OAAO;EAAC;EAAQ;EAAe;CAAS,CAAC;AAC1E;AAGA,MAAM,cAAc;CAClB;CACA;CACA;CACA;AACF;;;;;;AAOA,SAAgB,aAId,WACe;CACf,KAAK,MAAM,UAAU,aACnB,IAAI;EACF,MAAM,SAAS,OAAO,SAAS;EAC/B,IAAI,UAAU,QAAQ,WAAW,IAC/B,OAAO;CAEX,SAAS,GAAY;EACnB,IAAI,aAAa,SAAS,UAAU,KAAK,EAAE,SAAS,WAElD,MAAM,IAAI,MAAM,iCAAiC,WAAW;CAEhE;CAEF,OAAO;AACT"}
1
+ {"version":3,"file":"findRootSync.js","names":[],"sources":["../src/findRootSync.ts"],"sourcesContent":["import { repositoryExecSync } from \"./repositoryCommand.js\";\n\nfunction findGitRoot(cwd: string): string {\n return repositoryExecSync(cwd, \"git\", [\n \"rev-parse\",\n \"--quiet\",\n \"--show-toplevel\",\n ]);\n}\n\n/**\n * `--ignore-working-copy` keeps this a read-only operation. Every other jj\n * command snapshots the working copy first, which takes the working-copy lock\n * and writes a new operation to the repository we were only asked to locate.\n */\nfunction findJujutsuRoot(cwd: string): string {\n return repositoryExecSync(cwd, \"jj\", [\n \"--ignore-working-copy\",\n \"--quiet\",\n \"root\",\n ]);\n}\n\nfunction findSaplingRoot(cwd: string): string {\n return repositoryExecSync(cwd, \"sl\", [\"--quiet\", \"root\"]);\n}\n\nfunction findMercurialRoot(cwd: string): string {\n return repositoryExecSync(cwd, \"hg\", [\"--quiet\", \"root\"]);\n}\n\nfunction findSubversionRoot(cwd: string): string {\n return repositoryExecSync(cwd, \"svn\", [\"info\", \"--show-item\", \"wc-root\"]);\n}\n\n// Version control systems to check for. Highest-precedence checks go first.\nconst findMethods = [\n findGitRoot, // most used and fastest check\n // Runs almost as fast as git's check. A colocated jj repo (jj's default) has\n // a .git too and never reaches this, so this only works for non-colocated\n // repos and jj workspace directories, which git can't see at all.\n findJujutsuRoot,\n findSubversionRoot, // next highest market share\n findSaplingRoot, // much smaller market share, but much faster\n findMercurialRoot, // slow af\n] as const;\n\n/**\n * Find the root path of the repository containing the given directory.\n *\n * @returns null if not found or the path of the repository root as a string\n */\nexport function findRootSync(\n /**\n * The directory path of anything in a version-controlled repository\n */\n directory: string,\n): string | null {\n for (const method of findMethods) {\n try {\n const result = method(directory);\n if (result != null && result !== \"\") {\n return result;\n }\n } catch (e: unknown) {\n if (e instanceof Error && \"code\" in e && e.code === \"ENOTDIR\") {\n // rethrow error when given directory path isn't a directory\n throw new Error(`Given path isn't a directory: ${directory}`);\n }\n }\n }\n return null;\n}\n"],"mappings":";;;AAEA,SAAS,YAAY,KAAqB;CACxC,OAAO,mBAAmB,KAAK,OAAO;EACpC;EACA;EACA;CACF,CAAC;AACH;;;;;;AAOA,SAAS,gBAAgB,KAAqB;CAC5C,OAAO,mBAAmB,KAAK,MAAM;EACnC;EACA;EACA;CACF,CAAC;AACH;AAEA,SAAS,gBAAgB,KAAqB;CAC5C,OAAO,mBAAmB,KAAK,MAAM,CAAC,WAAW,MAAM,CAAC;AAC1D;AAEA,SAAS,kBAAkB,KAAqB;CAC9C,OAAO,mBAAmB,KAAK,MAAM,CAAC,WAAW,MAAM,CAAC;AAC1D;AAEA,SAAS,mBAAmB,KAAqB;CAC/C,OAAO,mBAAmB,KAAK,OAAO;EAAC;EAAQ;EAAe;CAAS,CAAC;AAC1E;AAGA,MAAM,cAAc;CAClB;CAIA;CACA;CACA;CACA;AACF;;;;;;AAOA,SAAgB,aAId,WACe;CACf,KAAK,MAAM,UAAU,aACnB,IAAI;EACF,MAAM,SAAS,OAAO,SAAS;EAC/B,IAAI,UAAU,QAAQ,WAAW,IAC/B,OAAO;CAEX,SAAS,GAAY;EACnB,IAAI,aAAa,SAAS,UAAU,KAAK,EAAE,SAAS,WAElD,MAAM,IAAI,MAAM,iCAAiC,WAAW;CAEhE;CAEF,OAAO;AACT"}
@@ -1,5 +1,5 @@
1
1
  //#region src/repositoryCommand.d.ts
2
- type RepositoryCommand = "git" | "hg" | "sl" | "svn" | "svnadmin" | "svnrdump";
2
+ type RepositoryCommand = "git" | "hg" | "jj" | "sl" | "svn" | "svnadmin" | "svnrdump";
3
3
  declare function repositoryExec(cwd: string, command: RepositoryCommand, args: readonly string[]): Promise<string>;
4
4
  declare function repositoryExecSync(cwd: string, command: RepositoryCommand, args: readonly string[]): string;
5
5
  declare const createExecForDirectory: (cwd: string) => ((command: RepositoryCommand, args: readonly string[]) => Promise<string>);
@@ -11,6 +11,11 @@ const environment = {
11
11
  GIT_AUTHOR_NAME: "alan",
12
12
  GIT_AUTHOR_EMAIL: "alan@example.com"
13
13
  },
14
+ jj: {
15
+ JJ_CONFIG: "/dev/null",
16
+ JJ_USER: "alan",
17
+ JJ_EMAIL: "alan@example.com"
18
+ },
14
19
  hg: {
15
20
  HGRCPATH: "/dev/null",
16
21
  HGUSER: "alan",
@@ -25,14 +30,44 @@ const environment = {
25
30
  svnadmin: {},
26
31
  svnrdump: {}
27
32
  };
33
+ /**
34
+ * Inherited environment variables to drop, per command. The other version
35
+ * control systems have no equivalent of GIT_DIR: they're told which repository
36
+ * to use with a flag, never with the environment.
37
+ */
38
+ const removedEnvironment = {
39
+ git: [
40
+ "GIT_DIR",
41
+ "GIT_WORK_TREE",
42
+ "GIT_COMMON_DIR",
43
+ "GIT_INDEX_FILE",
44
+ "GIT_INDEX_VERSION",
45
+ "GIT_OBJECT_DIRECTORY",
46
+ "GIT_ALTERNATE_OBJECT_DIRECTORIES",
47
+ "GIT_NAMESPACE",
48
+ "GIT_PREFIX",
49
+ "GIT_QUARANTINE_PATH"
50
+ ],
51
+ jj: [],
52
+ hg: [],
53
+ sl: [],
54
+ svn: [],
55
+ svnadmin: [],
56
+ svnrdump: []
57
+ };
58
+ function getEnvironment(command) {
59
+ const result = {
60
+ ...process.env,
61
+ ...environment[command]
62
+ };
63
+ for (const variable of removedEnvironment[command]) delete result[variable];
64
+ return result;
65
+ }
28
66
  async function repositoryExec(cwd, command, args) {
29
67
  return execFileAsync(command, args, {
30
68
  cwd,
31
69
  encoding: "utf8",
32
- env: {
33
- ...process.env,
34
- ...environment[command]
35
- }
70
+ env: getEnvironment(command)
36
71
  }).then(({ stdout, stderr }) => {
37
72
  return stderr ? Promise.reject(new Error(stderr.trim())) : stdout.trim();
38
73
  });
@@ -41,10 +76,7 @@ function repositoryExecSync(cwd, command, args) {
41
76
  return execFileSync(command, args, {
42
77
  cwd,
43
78
  encoding: "utf8",
44
- env: {
45
- ...process.env,
46
- ...environment[command]
47
- }
79
+ env: getEnvironment(command)
48
80
  }).trim();
49
81
  }
50
82
  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 = \"git\" | \"hg\" | \"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 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\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: {\n ...process.env,\n ...environment[command],\n },\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: {\n ...process.env,\n ...environment[command],\n },\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":";;;AAKA,MAAM,cAAc;CAClB,KAAK;EAEH,qBAAqB;EAErB,mBAAmB;EACnB,mBAAmB;EAEnB,oBAAoB;EACpB,qBAAqB;EACrB,iBAAiB;EACjB,kBAAkB;CACpB;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;AAEA,eAAsB,eACpB,KACA,SACA,MACiB;CAGjB,OAAO,cAAc,SAAS,MAAM;EAC7B;EACL,UAAU;EACV,KAAK;GACH,GAAG,QAAQ;GACX,GAAG,YAAY;EACjB;CACF,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;CAYR,OATe,aAAa,SAAS,MAAM;EACpC;EACL,UAAU;EACV,KAAK;GACH,GAAG,QAAQ;GACX,GAAG,YAAY;EACjB;CACF,CAAC,CAAC,CAAC,KAES;AACd;AAEA,MAAa,0BACX,QAEA,eAAe,KAAK,MAAM,GAAG"}
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;CASR,OANe,aAAa,SAAS,MAAM;EACpC;EACL,UAAU;EACV,KAAK,eAAe,OAAO;CAC7B,CAAC,CAAC,CAAC,KAES;AACd;AAEA,MAAa,0BACX,QAEA,eAAe,KAAK,MAAM,GAAG"}
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/types.d.ts
2
- declare const repositoryTypes: readonly ["git", "mercurial", "sapling", "subversion"];
2
+ declare const repositoryTypes: readonly ["git", "jujutsu", "mercurial", "sapling", "subversion"];
3
3
  type RepositoryType = (typeof repositoryTypes)[number];
4
4
  //#endregion
5
5
  export { RepositoryType, repositoryTypes };
package/dist/types.js CHANGED
@@ -1,6 +1,7 @@
1
1
  //#region src/types.ts
2
2
  const repositoryTypes = [
3
3
  "git",
4
+ "jujutsu",
4
5
  "mercurial",
5
6
  "sapling",
6
7
  "subversion"
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["export const repositoryTypes = [\n \"git\",\n \"mercurial\",\n \"sapling\",\n \"subversion\",\n] as const;\n\nexport type RepositoryType = (typeof repositoryTypes)[number];\n"],"mappings":";AAAA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;AACF"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["export const repositoryTypes = [\n \"git\",\n \"jujutsu\",\n \"mercurial\",\n \"sapling\",\n \"subversion\",\n] as const;\n\nexport type RepositoryType = (typeof repositoryTypes)[number];\n"],"mappings":";AAAA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;AACF"}
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@altano/repository-tools",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
4
4
  "description": "Misc tools for dealing with repositories of multiple version control systems (git, svn, etc)",
5
5
  "keywords": [
6
6
  "repository",
7
7
  "root",
8
8
  "git",
9
+ "jujutsu",
10
+ "jj",
9
11
  "mercurial",
10
12
  "sapling"
11
13
  ],
@@ -46,14 +48,14 @@
46
48
  "memize": "^2.1.1",
47
49
  "prettier": "3.9.6",
48
50
  "ts-assert-unreachable": "^0.0.9",
49
- "tsdown": "^0.22.13",
51
+ "tsdown": "^0.22.14",
50
52
  "typescript": "^6.0.3",
51
53
  "vite": "^8.1.5",
52
54
  "vitest": "^4.1.10",
53
- "@altano/build-config": "0.0.1",
54
55
  "@altano/disposable-directory": "0.0.3",
55
- "@altano/testing": "0.0.1",
56
- "@altano/tsconfig": "0.0.1"
56
+ "@altano/build-config": "0.0.1",
57
+ "@altano/tsconfig": "0.0.1",
58
+ "@altano/testing": "0.0.1"
57
59
  },
58
60
  "publishConfig": {
59
61
  "access": "public"