@eve-horizon/cli 0.2.40 → 0.2.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +52 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -67380,32 +67380,46 @@ async function resolveGitRef(context2, projectId, ref, repoDir) {
67380
67380
  return ref;
67381
67381
  }
67382
67382
  const resolvedRepoDir = repoDir ?? getGitRoot();
67383
- if (!resolvedRepoDir) {
67384
- throw new Error(
67385
- `Failed to resolve git ref '${ref}': not in a git repository.
67386
- Run the command from the project repository, pass --repo-dir <path>, or use a 40-character SHA.`
67387
- );
67388
- }
67383
+ let useLocal = !!resolvedRepoDir;
67384
+ let projectRepoUrl;
67389
67385
  if (projectId) {
67390
67386
  const project = await requestJson(context2, `/projects/${projectId}`);
67387
+ projectRepoUrl = project.repo_url;
67391
67388
  const expected = normalizeRepoIdentity(project.repo_url);
67392
- const actual = normalizeRepoIdentity(getGitOriginUrl(resolvedRepoDir));
67393
- const repoDirIdentity = normalizeRepoIdentity(resolvedRepoDir);
67389
+ const actual = resolvedRepoDir ? normalizeRepoIdentity(getGitOriginUrl(resolvedRepoDir)) : null;
67390
+ const repoDirIdentity = resolvedRepoDir ? normalizeRepoIdentity(resolvedRepoDir) : null;
67394
67391
  if (expected && actual && expected !== actual) {
67395
- throw new Error(
67396
- `Failed to resolve git ref '${ref}': current repo does not match project repo.
67397
- Project repo: ${project.repo_url}
67398
- Current repo: ${getGitOriginUrl(resolvedRepoDir)}
67399
- Run the command from the project repository, pass --repo-dir <path>, or use a 40-character SHA.`
67400
- );
67392
+ useLocal = false;
67401
67393
  }
67402
67394
  if (expected && !actual && (!repoDirIdentity || repoDirIdentity !== expected)) {
67403
- throw new Error(
67404
- `Failed to resolve git ref '${ref}': current repo has no origin remote to validate against project repo.
67405
- Project repo: ${project.repo_url}
67406
- Run the command from the project repository, pass --repo-dir <path>, or use a 40-character SHA.`
67407
- );
67395
+ useLocal = false;
67396
+ }
67397
+ }
67398
+ if (useLocal && resolvedRepoDir) {
67399
+ try {
67400
+ return (0, import_node_child_process5.execSync)(`git rev-parse ${ref}`, {
67401
+ cwd: resolvedRepoDir,
67402
+ encoding: "utf-8",
67403
+ stdio: ["pipe", "pipe", "pipe"]
67404
+ }).trim();
67405
+ } catch {
67406
+ }
67407
+ }
67408
+ if (projectRepoUrl) {
67409
+ const sha = resolveRefRemote(projectRepoUrl, ref);
67410
+ if (sha) {
67411
+ return sha;
67408
67412
  }
67413
+ throw new Error(
67414
+ `Failed to resolve git ref '${ref}' against remote '${projectRepoUrl}'.
67415
+ Make sure the ref (branch or tag) exists in the remote repository, or use a 40-character SHA.`
67416
+ );
67417
+ }
67418
+ if (!resolvedRepoDir) {
67419
+ throw new Error(
67420
+ `Failed to resolve git ref '${ref}': not in a git repository.
67421
+ Run the command from the project repository, pass --repo-dir <path>, or use a 40-character SHA.`
67422
+ );
67409
67423
  }
67410
67424
  try {
67411
67425
  return (0, import_node_child_process5.execSync)(`git rev-parse ${ref}`, {
@@ -67470,6 +67484,25 @@ function resolveGitBranch(repoDir, ref) {
67470
67484
  return null;
67471
67485
  }
67472
67486
  }
67487
+ function resolveRefRemote(repoUrl, ref) {
67488
+ try {
67489
+ const output = (0, import_node_child_process5.execSync)(`git ls-remote ${repoUrl} ${ref}`, {
67490
+ encoding: "utf-8",
67491
+ stdio: ["pipe", "pipe", "pipe"],
67492
+ timeout: 15e3
67493
+ }).trim();
67494
+ for (const line of output.split("\n")) {
67495
+ const [sha, refName] = line.split(" ");
67496
+ if (!sha || !refName) continue;
67497
+ if (refName === `refs/heads/${ref}` || refName === `refs/tags/${ref}` || refName === ref) {
67498
+ return sha;
67499
+ }
67500
+ }
67501
+ return null;
67502
+ } catch {
67503
+ return null;
67504
+ }
67505
+ }
67473
67506
  function getGitOriginUrl(repoDir) {
67474
67507
  try {
67475
67508
  const url = (0, import_node_child_process5.execSync)("git config --get remote.origin.url", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eve-horizon/cli",
3
- "version": "0.2.40",
3
+ "version": "0.2.41",
4
4
  "description": "Eve Horizon CLI",
5
5
  "license": "MIT",
6
6
  "repository": {