type-git 0.8.1 → 0.8.3

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.
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkUHZWPYTFcjs = require('./chunk-UHZWPYTF.cjs');
8
+ var _chunkSNC324NLcjs = require('./chunk-SNC324NL.cjs');
9
9
 
10
10
  // src/adapters/node/exec.ts
11
11
  var _child_process = require('child_process');
@@ -134,7 +134,7 @@ var NodeExecAdapter = class {
134
134
  exitSignal = sig;
135
135
  }
136
136
  resolve({
137
- stdout: binary ? _chunkUHZWPYTFcjs.joinBytes.call(void 0, stdoutChunks) : stdout,
137
+ stdout: binary ? _chunkSNC324NLcjs.joinBytes.call(void 0, stdoutChunks) : stdout,
138
138
  stderr,
139
139
  exitCode: _nullishCoalesce(code, () => ( -1)),
140
140
  signal: exitSignal,
@@ -273,7 +273,7 @@ var NodeFsAdapter = (_class = class {constructor() { _class.prototype.__init.cal
273
273
  sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms))
274
274
  };
275
275
  try {
276
- await _chunkUHZWPYTFcjs.runTailPolling.call(void 0, { adapter, signal, pollInterval, onLine });
276
+ await _chunkSNC324NLcjs.runTailPolling.call(void 0, { adapter, signal, pollInterval, onLine });
277
277
  } finally {
278
278
  if (state.file) {
279
279
  await state.file.close();
@@ -341,7 +341,7 @@ var NodeFsAdapter = (_class = class {constructor() { _class.prototype.__init.cal
341
341
  },
342
342
  sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms))
343
343
  };
344
- const polling = _chunkUHZWPYTFcjs.createTailPolling.call(void 0, { adapter, signal, pollInterval });
344
+ const polling = _chunkSNC324NLcjs.createTailPolling.call(void 0, { adapter, signal, pollInterval });
345
345
  const closeFileHandle = async () => {
346
346
  if (state.file) {
347
347
  await state.file.close().catch(() => {
@@ -379,18 +379,18 @@ function splitOptions(options) {
379
379
  adapters: createNodeAdapters(windowsHide === void 0 ? void 0 : { windowsHide })
380
380
  };
381
381
  }
382
- var TypeGit = class _TypeGit extends _chunkUHZWPYTFcjs.GitClient {
382
+ var TypeGit = class _TypeGit extends _chunkSNC324NLcjs.GitClient {
383
383
  /**
384
384
  * Create a client after checking the installed Git version. Node adapter options such as
385
385
  * `windowsHide` are passed to the execution adapter.
386
386
  */
387
387
  static async create(options) {
388
- return new _TypeGit(await _chunkUHZWPYTFcjs.createGit.call(void 0, splitOptions(options)));
388
+ return new _TypeGit(await _chunkSNC324NLcjs.createGit.call(void 0, splitOptions(options)));
389
389
  }
390
390
  /** Wrap an existing Git instance, or create one from options without the version check. */
391
391
  constructor(optionsOrGit) {
392
392
  super(
393
- optionsOrGit && "open" in optionsOrGit ? optionsOrGit : _chunkUHZWPYTFcjs.createGitSync.call(void 0, splitOptions(optionsOrGit))
393
+ optionsOrGit && "open" in optionsOrGit ? optionsOrGit : _chunkSNC324NLcjs.createGitSync.call(void 0, splitOptions(optionsOrGit))
394
394
  );
395
395
  }
396
396
  };
@@ -5,7 +5,7 @@ import {
5
5
  createTailPolling,
6
6
  joinBytes,
7
7
  runTailPolling
8
- } from "./chunk-ADC26634.js";
8
+ } from "./chunk-HCQGGKTC.js";
9
9
 
10
10
  // src/adapters/node/exec.ts
11
11
  import { spawn } from "child_process";
@@ -3932,7 +3932,8 @@ var COMMAND_CONSTRAINTS = {
3932
3932
  reason: "Commit --all cannot use a pathspec file.",
3933
3933
  source: git("builtin/commit.c")
3934
3934
  },
3935
- // repo.commit emits no path operands and skips an empty pathspecFromFile or fixup.
3935
+ // repo.commit emits no path operands and refuses an empty fixup. It forwards an empty
3936
+ // pathspecFromFile, which Git 2.43 cannot open and newer Git ignores, so it supplies no paths.
3936
3937
  {
3937
3938
  id: "commit.include-paths",
3938
3939
  kind: "requires",
@@ -4132,7 +4133,8 @@ var COMMAND_CONSTRAINTS = {
4132
4133
  {
4133
4134
  id: "pull.branch-remote",
4134
4135
  kind: "requires",
4135
- when: { key: "branch", test: "nonempty" },
4136
+ // repo.pull emits an empty branch too (Git takes it as the remote's HEAD).
4137
+ when: active("branch"),
4136
4138
  required: [{ key: "remote", test: "nonempty" }],
4137
4139
  origin: "git",
4138
4140
  reason: "Git reads the first positional word as the repository, so a branch needs an explicit remote.",
@@ -4298,7 +4300,7 @@ var COMMAND_CONSTRAINTS = {
4298
4300
  when: { key: "startPoint", test: "nonempty" },
4299
4301
  choices: [active("create"), active("forceCreate")],
4300
4302
  origin: "git",
4301
- reason: "A start point is a second operand, which Git accepts only with -c or -C; --orphan takes no start point. An empty startPoint is not emitted.",
4303
+ reason: "A start point is a second operand, which Git accepts only with -c or -C; --orphan takes no start point. An empty startPoint is refused at runtime, as Git rejects it.",
4302
4304
  source: git("builtin/checkout.c")
4303
4305
  }
4304
4306
  ],
@@ -4936,7 +4938,8 @@ var INPUT_CONSTRAINTS = {
4936
4938
  kind: "forbid",
4937
4939
  when: [
4938
4940
  { key: "fixup", test: "startsWith", value: "amend:" },
4939
- { key: "message", test: "nonempty" }
4941
+ // repo.commit forwards an empty message as -m '', which Git refuses here too.
4942
+ { key: "message", test: "active" }
4940
4943
  ],
4941
4944
  origin: "git",
4942
4945
  reason: "An amend: fixup takes its message from the amended commit, not from a message.",
@@ -4947,7 +4950,8 @@ var INPUT_CONSTRAINTS = {
4947
4950
  kind: "forbid",
4948
4951
  when: [
4949
4952
  { key: "fixup", test: "startsWith", value: "reword:" },
4950
- { key: "message", test: "nonempty" }
4953
+ // repo.commit forwards an empty message as -m '', which Git refuses here too.
4954
+ { key: "message", test: "active" }
4951
4955
  ],
4952
4956
  origin: "git",
4953
4957
  reason: "A reword: fixup takes its message from the amended commit, not from a message.",
@@ -4958,7 +4962,8 @@ var INPUT_CONSTRAINTS = {
4958
4962
  kind: "scalar",
4959
4963
  key: "author",
4960
4964
  parser: "commit-author",
4961
- // repo.commit skips an empty author; dry runs return before determine_author_info.
4965
+ // An empty author is forwarded and Git matches it against existing authors, so the ident
4966
+ // parser skips it; dry runs return before determine_author_info.
4962
4967
  guard: [
4963
4968
  { key: "author", test: "nonempty" },
4964
4969
  { key: "dryRun", test: "inactive" }
@@ -4972,7 +4977,7 @@ var INPUT_CONSTRAINTS = {
4972
4977
  kind: "scalar",
4973
4978
  key: "date",
4974
4979
  parser: "commit-date",
4975
- // repo.commit skips an empty date and converts a Date, which still needs a valid time.
4980
+ // repo.commit refuses an empty date and converts a Date, which still needs a valid time.
4976
4981
  guard: [
4977
4982
  { key: "date", test: "present" },
4978
4983
  { key: "date", test: "notEquals", value: "" },
@@ -4988,7 +4993,8 @@ var INPUT_CONSTRAINTS = {
4988
4993
  id: "restore.paths",
4989
4994
  kind: "requiresAny",
4990
4995
  when: { key: "paths", test: "lengthEquals", value: 0 },
4991
- // An empty pathspecFromFile is not emitted, so it does not count.
4996
+ // An empty pathspecFromFile is forwarded but supplies no paths (Git 2.43 cannot open it and
4997
+ // newer Git ignores it), so it does not count.
4992
4998
  choices: [{ key: "pathspecFromFile", test: "nonempty" }],
4993
4999
  origin: "git",
4994
5000
  reason: "Restore without patch mode needs paths or a pathspec file.",
@@ -5010,7 +5016,8 @@ var INPUT_CONSTRAINTS = {
5010
5016
  key: "paths",
5011
5017
  min: 0,
5012
5018
  max: 0,
5013
- // The convenience APIs emit --pathspec-from-file only for a non-empty value.
5019
+ // An empty pathspecFromFile is forwarded but names no file (Git 2.43 cannot open it and newer
5020
+ // Git ignores it), so it does not count.
5014
5021
  when: { key: "pathspecFromFile", test: "nonempty" },
5015
5022
  origin: "git",
5016
5023
  reason: "Pathspec files cannot be combined with command-line pathspecs.",
@@ -5305,6 +5312,52 @@ function validateInput(name, input, command = name) {
5305
5312
  var FATAL_ERROR_PATTERN = /fatal:\s*(.+)/i;
5306
5313
  var ERROR_PATTERN = /error:\s*(.+)/i;
5307
5314
  var LINE_SEPARATOR_PATTERN = /\r|\n/;
5315
+ var WINDOWS_ROOTED_PATH_PATTERN = /^(?:[\\/]|[A-Za-z]:[\\/])/;
5316
+ function isRootedPath(path, platform = _process2.default.platform) {
5317
+ return platform === "win32" ? WINDOWS_ROOTED_PATH_PATTERN.test(path) : path.startsWith("/");
5318
+ }
5319
+ function spawnCwd(context, companion) {
5320
+ const directory = context.type === "worktree" ? context.workdir : context.type === "bare" ? context.gitDir : void 0;
5321
+ if (directory === void 0) {
5322
+ return void 0;
5323
+ }
5324
+ return companion || isRootedPath(directory) ? directory : void 0;
5325
+ }
5326
+ var WINDOWS_SEPARATOR_PATTERN = /[\\/]/;
5327
+ var WINDOWS_DRIVE_PATTERN = /^[A-Za-z]:/;
5328
+ function anchorToCaller(path) {
5329
+ const windows = _process2.default.platform === "win32";
5330
+ if (path === "") {
5331
+ return _process2.default.cwd();
5332
+ }
5333
+ if (isRootedPath(path) || windows && WINDOWS_DRIVE_PATTERN.test(path)) {
5334
+ return path;
5335
+ }
5336
+ return `${_process2.default.cwd()}${windows ? "\\" : "/"}${path}`;
5337
+ }
5338
+ var WINDOWS_QUOTED_PATTERN = /^".*"$/;
5339
+ function pathKeyOf(env) {
5340
+ return _process2.default.platform === "win32" ? _nullishCoalesce(Object.keys(env).find((key) => key.toLowerCase() === "path"), () => ( "PATH")) : "PATH";
5341
+ }
5342
+ function anchorSearchPath(env) {
5343
+ const windows = _process2.default.platform === "win32";
5344
+ const delimiter = windows ? ";" : ":";
5345
+ const keys = windows ? Object.keys(env).filter((key) => key.toLowerCase() === "path") : ["PATH"];
5346
+ for (const key of keys) {
5347
+ const value = env[key];
5348
+ if (value === void 0) {
5349
+ continue;
5350
+ }
5351
+ env[key] = value.split(delimiter).map(
5352
+ (entry) => windows && WINDOWS_QUOTED_PATTERN.test(entry) ? entry : anchorToCaller(entry)
5353
+ ).join(delimiter);
5354
+ }
5355
+ }
5356
+ function callerRelativeProgram(program, cwd) {
5357
+ const windows = _process2.default.platform === "win32";
5358
+ const hasSeparator = windows ? WINDOWS_SEPARATOR_PATTERN.test(program) : program.includes("/");
5359
+ return cwd === void 0 || !hasSeparator ? program : anchorToCaller(program);
5360
+ }
5308
5361
  var GIT_TRACE_PATTERN = /^\d{2}:\d{2}:\d{2}\.\d+\s+(?:trace:|[A-Za-z0-9_.-]+\.c:)/;
5309
5362
  var TRACE_ENV_PATTERN = /^(?:GIT_TRACE\w*|GIT_CURL_VERBOSE)$/i;
5310
5363
  function stripTraceEnv(env) {
@@ -5490,7 +5543,7 @@ var CliRunner = class _CliRunner {
5490
5543
  * Build command argv based on execution context
5491
5544
  */
5492
5545
  buildArgv(context, args) {
5493
- const argv = [this.gitBinary];
5546
+ const argv = [callerRelativeProgram(this.gitBinary, spawnCwd(context, false))];
5494
5547
  for (const parameter of this.configParameters()) {
5495
5548
  argv.push("-c", parameter);
5496
5549
  }
@@ -5539,7 +5592,7 @@ var CliRunner = class _CliRunner {
5539
5592
  if (allPathPrefixes.length > 0) {
5540
5593
  const isWindows = _process2.default.platform === "win32";
5541
5594
  const separator = isWindows ? ";" : ":";
5542
- const pathKey = isWindows ? _nullishCoalesce(Object.keys(env).find((key) => key.toLowerCase() === "path"), () => ( "PATH")) : "PATH";
5595
+ const pathKey = pathKeyOf(env);
5543
5596
  const currentPath = _nullishCoalesce(env[pathKey], () => ( ""));
5544
5597
  env[pathKey] = [...allPathPrefixes, currentPath].join(separator);
5545
5598
  }
@@ -5815,6 +5868,10 @@ var CliRunner = class _CliRunner {
5815
5868
  if (envOverride) {
5816
5869
  applyEnvOverride(env, envOverride);
5817
5870
  }
5871
+ const cwd = spawnCwd(context, executable !== void 0);
5872
+ if (cwd !== void 0) {
5873
+ anchorSearchPath(env);
5874
+ }
5818
5875
  if (internal) {
5819
5876
  stripTraceEnv(env);
5820
5877
  }
@@ -5857,7 +5914,7 @@ var CliRunner = class _CliRunner {
5857
5914
  // The env above is already fully resolved (including any inherited variables),
5858
5915
  // so the adapter must not merge the parent environment on top of it.
5859
5916
  inheritEnv: false,
5860
- cwd: context.type === "worktree" ? context.workdir : executable && context.type === "bare" ? context.gitDir : void 0,
5917
+ cwd,
5861
5918
  signal
5862
5919
  },
5863
5920
  needsStderrStreaming ? {