@kungfu-tech/buildchain 3.0.5-alpha.0 → 3.0.5-alpha.2

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.
@@ -46,6 +46,14 @@ function normalizeFallback(value = "github") {
46
46
  return fallback;
47
47
  }
48
48
 
49
+ function normalizeHistoryMode(value = "shallow") {
50
+ const mode = String(value || "shallow").trim().toLowerCase() || "shallow";
51
+ if (!["shallow", "full"].includes(mode)) {
52
+ throw new Error(`checkout-history-mode must be shallow or full; got ${value}`);
53
+ }
54
+ return mode;
55
+ }
56
+
49
57
  function splitRepository(repository) {
50
58
  const match = String(repository || "").trim().match(/^([^/\s]+)\/([^/\s]+)$/);
51
59
  if (!match) {
@@ -237,19 +245,25 @@ export function fetchSourceCommit({
237
245
  sourceTreeSha = "",
238
246
  timeoutMs,
239
247
  env = {},
248
+ historyMode = readEnv("BUILDCHAIN_CHECKOUT_HISTORY_MODE", "shallow"),
240
249
  allowFullFetchRetry = false,
241
250
  runGit = git,
242
251
  containsCommit = hasCommit,
243
252
  }) {
253
+ const normalizedHistoryMode = normalizeHistoryMode(historyMode);
244
254
  const fetchEnv = isolatedGitFetchEnv(env, targetPath);
245
255
  const fetch = (refspec) => {
246
256
  const options = { cwd: targetPath, timeoutMs, env: fetchEnv };
257
+ const fetchArgs = ["fetch", "--no-tags"];
258
+ if (normalizedHistoryMode === "shallow") fetchArgs.push("--depth=1");
259
+ fetchArgs.push(remoteName, refspec);
247
260
  try {
248
- runGit(["fetch", "--no-tags", "--depth=1", remoteName, refspec], options);
249
- return "shallow";
261
+ runGit(fetchArgs, options);
262
+ return normalizedHistoryMode;
250
263
  } catch (error) {
251
264
  if (
252
- !allowFullFetchRetry
265
+ normalizedHistoryMode !== "shallow"
266
+ || !allowFullFetchRetry
253
267
  || !/dumb http transport does not support shallow capabilities/i.test(
254
268
  String(error?.message || error || ""),
255
269
  )