sync-worktrees 3.5.0 → 3.6.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/dist/index.js CHANGED
@@ -25,7 +25,8 @@ var GIT_CONSTANTS = {
25
25
  REMOTES: "refs/remotes/origin",
26
26
  REMOTES_ORIGIN: "refs/remotes/origin/*"
27
27
  },
28
- FETCH_CONFIG: "+refs/heads/*:refs/remotes/origin/*"
28
+ FETCH_CONFIG: "+refs/heads/*:refs/remotes/origin/*",
29
+ PROGRESS_BUCKET_PERCENT: 25
29
30
  };
30
31
  var GIT_OPERATIONS = {
31
32
  MERGE_HEAD: "MERGE_HEAD",
@@ -3098,13 +3099,33 @@ var GitService = class {
3098
3099
  const key = `${path6.resolve(dirPath)}::${useLfsSkip ? "1" : "0"}`;
3099
3100
  let git = this.gitInstances.get(key);
3100
3101
  if (!git) {
3101
- const block = this.getFetchTimeoutMs();
3102
- const base = block > 0 ? simpleGit4(dirPath, { timeout: { block } }) : simpleGit4(dirPath);
3102
+ const base = simpleGit4(dirPath, this.buildSimpleGitOptions(this.getFetchTimeoutMs()));
3103
3103
  git = useLfsSkip ? base.env({ [ENV_CONSTANTS.GIT_LFS_SKIP_SMUDGE]: "1" }) : base;
3104
3104
  this.gitInstances.set(key, git);
3105
3105
  }
3106
3106
  return git;
3107
3107
  }
3108
+ buildSimpleGitOptions(blockMs) {
3109
+ const options = { progress: this.makeProgressHandler() };
3110
+ if (blockMs > 0) options.timeout = { block: blockMs };
3111
+ return options;
3112
+ }
3113
+ makeProgressHandler() {
3114
+ const lastBucket = /* @__PURE__ */ new Map();
3115
+ return (event) => {
3116
+ if (event.method !== "fetch" && event.method !== "clone" && event.method !== "pull") return;
3117
+ const key = `${event.method}:${event.stage}`;
3118
+ const bucket = Math.floor(event.progress / GIT_CONSTANTS.PROGRESS_BUCKET_PERCENT);
3119
+ let last = lastBucket.get(key) ?? -1;
3120
+ if (bucket < last) {
3121
+ last = -1;
3122
+ }
3123
+ if (bucket <= last && event.progress < 100) return;
3124
+ lastBucket.set(key, bucket);
3125
+ const total = event.total > 0 ? `${event.processed}/${event.total}` : `${event.processed}`;
3126
+ this.logger.info(` \u21B3 ${event.method} ${event.stage}: ${event.progress}% (${total})`);
3127
+ };
3128
+ }
3108
3129
  updateLogger(logger) {
3109
3130
  this.logger = logger;
3110
3131
  this.sparseCheckoutService.updateLogger(logger);
@@ -3116,10 +3137,9 @@ var GitService = class {
3116
3137
  } catch {
3117
3138
  this.logger.info(`Cloning from "${repoUrl}" as bare repository into "${this.bareRepoPath}"...`);
3118
3139
  await fs4.mkdir(path6.dirname(this.bareRepoPath), { recursive: true });
3119
- const cloneBlock = this.getCloneTimeoutMs();
3120
- const cloneBase = cloneBlock > 0 ? simpleGit4({ timeout: { block: cloneBlock } }) : simpleGit4();
3140
+ const cloneBase = simpleGit4(this.buildSimpleGitOptions(this.getCloneTimeoutMs()));
3121
3141
  const cloneGit = this.isLfsSkipEnabled() ? cloneBase.env({ [ENV_CONSTANTS.GIT_LFS_SKIP_SMUDGE]: "1" }) : cloneBase;
3122
- await cloneGit.clone(repoUrl, this.bareRepoPath, ["--bare"]);
3142
+ await cloneGit.clone(repoUrl, this.bareRepoPath, ["--bare", "--progress"]);
3123
3143
  this.logger.info("\u2705 Clone successful.");
3124
3144
  }
3125
3145
  const bareGit = this.getCachedGit(this.bareRepoPath);
@@ -3133,7 +3153,7 @@ var GitService = class {
3133
3153
  await bareGit.addConfig("remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*");
3134
3154
  }
3135
3155
  this.logger.info("Fetching remote branches...");
3136
- await bareGit.fetch(["--all"]);
3156
+ await bareGit.fetch(["--all", "--progress"]);
3137
3157
  this.defaultBranch = await this.detectDefaultBranch(bareGit);
3138
3158
  this.mainWorktreePath = path6.join(this.config.worktreeDir, this.defaultBranch);
3139
3159
  let needsMainWorktree = true;
@@ -3211,12 +3231,12 @@ var GitService = class {
3211
3231
  this.assertInitialized();
3212
3232
  this.logger.info("Fetching latest data from remote...");
3213
3233
  const git = this.getCachedGit(this.mainWorktreePath, this.isLfsSkipEnabled());
3214
- await git.fetch(["--all", "--prune"]);
3234
+ await git.fetch(["--all", "--prune", "--progress"]);
3215
3235
  }
3216
3236
  async fetchBranch(branchName) {
3217
3237
  this.assertInitialized();
3218
3238
  const git = this.getCachedGit(this.mainWorktreePath, this.isLfsSkipEnabled());
3219
- await git.fetch(["origin", branchName, "--prune"]);
3239
+ await git.fetch(["origin", branchName, "--prune", "--progress"]);
3220
3240
  }
3221
3241
  assertInitialized() {
3222
3242
  if (!this.git) {