@gitkraken/core-gitlens 0.15.0 → 0.15.1

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 (49) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/dist/git/models/branch.d.ts +7 -0
  3. package/dist/git/models/branch.js +1 -0
  4. package/dist/git/models/branch.js.map +1 -1
  5. package/dist/git/models/graph.d.ts +2 -0
  6. package/dist/git/models/graph.js.map +1 -1
  7. package/dist/git/models/reference.d.ts +4 -0
  8. package/dist/git/providers/provider.d.ts +3 -1
  9. package/dist/git/providers/revision.d.ts +2 -1
  10. package/dist/git/run.types.d.ts +3 -2
  11. package/dist/git/utils/branch.utils.d.ts +15 -3
  12. package/dist/git/utils/branch.utils.js +34 -8
  13. package/dist/git/utils/branch.utils.js.map +1 -1
  14. package/dist/git/utils/reference.utils.d.ts +2 -0
  15. package/dist/git/utils/reference.utils.js.map +1 -1
  16. package/dist/git/watching/worktreeSummary.d.ts +7 -4
  17. package/dist/git/watching/worktreeSummary.js +22 -3
  18. package/dist/git/watching/worktreeSummary.js.map +1 -1
  19. package/dist/git-cli/cliGitProvider.d.ts +6 -0
  20. package/dist/git-cli/cliGitProvider.js +48 -2
  21. package/dist/git-cli/cliGitProvider.js.map +1 -1
  22. package/dist/git-cli/exec/git.d.ts +1 -0
  23. package/dist/git-cli/exec/git.js +8 -10
  24. package/dist/git-cli/exec/git.js.map +1 -1
  25. package/dist/git-cli/exec/indexLock.d.ts +9 -1
  26. package/dist/git-cli/exec/indexLock.js +19 -5
  27. package/dist/git-cli/exec/indexLock.js.map +1 -1
  28. package/dist/git-cli/parsers/logParser.d.ts +4 -0
  29. package/dist/git-cli/parsers/logParser.js +12 -2
  30. package/dist/git-cli/parsers/logParser.js.map +1 -1
  31. package/dist/git-cli/parsers/refParser.js +4 -2
  32. package/dist/git-cli/parsers/refParser.js.map +1 -1
  33. package/dist/git-cli/providers/branchRemote.d.ts +13 -1
  34. package/dist/git-cli/providers/branchRemote.js +41 -12
  35. package/dist/git-cli/providers/branchRemote.js.map +1 -1
  36. package/dist/git-cli/providers/branches.js +55 -21
  37. package/dist/git-cli/providers/branches.js.map +1 -1
  38. package/dist/git-cli/providers/graph.js +53 -32
  39. package/dist/git-cli/providers/graph.js.map +1 -1
  40. package/dist/git-cli/providers/operations.js +22 -4
  41. package/dist/git-cli/providers/operations.js.map +1 -1
  42. package/dist/git-cli/providers/revision.d.ts +8 -1
  43. package/dist/git-cli/providers/revision.js +22 -8
  44. package/dist/git-cli/providers/revision.js.map +1 -1
  45. package/dist/git-cli/providers/stash.js +3 -3
  46. package/dist/git-cli/providers/stash.js.map +1 -1
  47. package/dist/git-cli/providers/worktrees.js +3 -3
  48. package/dist/git-cli/providers/worktrees.js.map +1 -1
  49. package/package.json +1 -1
@@ -8,7 +8,7 @@ import { debug, trace } from "../../utils/decorators/log.js";
8
8
  import { getBranchId } from "../../utils/gitRefs.js";
9
9
  import { normalizePath } from "../../utils/path.js";
10
10
  import { createRevisionRange, shortenRevision } from "../../git/utils/revision.utils.js";
11
- import { formatDetachedHeadName, getLocalBranchByUpstream, isDetachedHead, isRemoteHEAD, parseBranchMetadataGkConfigKey, parseRefName, parseUpstream, setBranchMetadataValue } from "../../git/utils/branch.utils.js";
11
+ import { formatDetachedHeadName, getLocalBranchByUpstream, isDetachedHead, isRemoteHEAD, parseBranchMetadataGkConfigKey, parseRefName, parseUpstream, setBranchMetadataValue, splitRemoteBranchName } from "../../git/utils/branch.utils.js";
12
12
  import { createReference } from "../../git/utils/reference.utils.js";
13
13
  import __decorate from "../../_virtual/@oxc-project+runtime/helpers/esm/decorate.js";
14
14
  import { BranchError, GitWarnings } from "../../git/errors.js";
@@ -153,11 +153,26 @@ var BranchesGitSubProvider = class {
153
153
  level: "debug"
154
154
  } }));
155
155
  const branches = [];
156
+ let remoteNames;
157
+ const resolveUpstreamRemote = async (upstream) => {
158
+ if (!upstream.startsWith("refs/remotes/")) return void 0;
159
+ const { name } = parseRefName(upstream);
160
+ if (!name.includes("/", name.indexOf("/") + 1)) return void 0;
161
+ remoteNames ??= this.provider.remotes.getRemotes(commonPath, void 0, signal).then((remotes) => {
162
+ if (!remotes.length) cacheable?.invalidate();
163
+ return remotes.map((r) => r.name);
164
+ }, (ex) => {
165
+ if (isCancellationError(ex)) throw ex;
166
+ cacheable?.invalidate();
167
+ return [];
168
+ });
169
+ return splitRemoteBranchName(name, await remoteNames)?.[0];
170
+ };
156
171
  for (const record of records) {
157
172
  const fullName = record.name;
158
173
  if (!fullName.startsWith("refs/heads/") && !fullName.startsWith("refs/remotes/")) continue;
159
174
  if (isRemoteHEAD(fullName)) continue;
160
- const upstream = parseUpstream(record.upstream, record.upstreamTracking, record.upstreamRemote);
175
+ const upstream = parseUpstream(record.upstream, record.upstreamTracking, record.upstreamRemote ?? (!worktreePathSupported ? await resolveUpstreamRemote(record.upstream) : void 0), record.upstreamRemoteRef);
161
176
  const metadata = metadataMap.get(parseRefName(fullName).name);
162
177
  const worktreePath = record.worktreePath ? normalizePath(record.worktreePath) : void 0;
163
178
  branches.push(new GitBranch(commonPath, fullName, false, record.committerDate ? new Date(record.committerDate) : void 0, metadata, record.objectname, upstream, worktreePathSupported ? worktreePath ? {
@@ -176,7 +191,9 @@ var BranchesGitSubProvider = class {
176
191
  upstream: branch.upstream?.name ? {
177
192
  name: branch.upstream.name,
178
193
  missing: branch.upstream.missing,
179
- remote: branch.upstream.remote
194
+ remote: branch.upstream.remote,
195
+ remoteBranch: branch.upstream.remoteBranch,
196
+ local: branch.upstream.local
180
197
  } : void 0,
181
198
  sha: branch.sha
182
199
  });
@@ -289,11 +306,13 @@ var BranchesGitSubProvider = class {
289
306
  const branch = await this.getBranch(repoPath, ref, void 0, cancellation);
290
307
  if (branch == null) return void 0;
291
308
  const { remote: remoteName } = await resolveBranchRemote(this.provider, repoPath, branch, cancellation);
292
- const prTarget = `${remoteName}/${pr.refs.base.branch}`;
293
- const { missing } = await this.provider.refs.getSymbolicReferenceNameOrMissing(repoPath, prTarget, priorityOpts, cancellation);
294
- if (!missing) {
295
- mergeTarget = prTarget;
296
- if (pr.stack == null) this.storeMergeTargetBranchName(repoPath, ref, prTarget, { skipInvalidation: ["branchOverviews"] });
309
+ if (remoteName != null) {
310
+ const prTarget = `${remoteName}/${pr.refs.base.branch}`;
311
+ const { missing } = await this.provider.refs.getSymbolicReferenceNameOrMissing(repoPath, prTarget, priorityOpts, cancellation);
312
+ if (!missing) {
313
+ mergeTarget = prTarget;
314
+ if (pr.stack == null) this.storeMergeTargetBranchName(repoPath, ref, prTarget, { skipInvalidation: ["branchOverviews"] });
315
+ }
297
316
  }
298
317
  }
299
318
  }
@@ -356,26 +375,26 @@ var BranchesGitSubProvider = class {
356
375
  cwd: repoPath,
357
376
  cancellation: signal,
358
377
  errors: "throw"
359
- }, "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@", "@{u}", "--");
360
- data = [result.stdout, void 0];
378
+ }, "rev-parse", "--symbolic-full-name", "@", "@{u}", "--");
379
+ data = parseSymbolicFullNames(result.stdout);
361
380
  } catch (ex) {
362
381
  if (isCancellationError(ex)) throw ex;
363
382
  const msg = ex?.toString() ?? "";
364
383
  if (GitErrors.badRevision.test(msg) || GitWarnings.noUpstream.test(msg)) {
365
- if (ex.stdout != null && ex.stdout.length !== 0) data = [ex.stdout, void 0];
384
+ if (ex.stdout != null && ex.stdout.length !== 0) data = parseSymbolicFullNames(ex.stdout);
366
385
  else {
367
386
  try {
368
387
  result = await this.git.run({
369
388
  cwd: repoPath,
370
389
  cancellation: signal
371
390
  }, "symbolic-ref", "--short", "HEAD");
372
- if (result.stdout) data = [result.stdout.trim(), void 0];
391
+ if (result.stdout) data = { name: result.stdout.trim() };
373
392
  } catch {
374
393
  if (isCancellationError(ex)) throw ex;
375
394
  }
376
395
  if (data == null) {
377
396
  const symbolicRef = await this.getDefaultBranchName(repoPath, "origin", void 0, signal);
378
- if (symbolicRef != null) data = [symbolicRef.startsWith("origin/") ? symbolicRef.substring(7) : symbolicRef, void 0];
397
+ if (symbolicRef != null) data = { name: symbolicRef.startsWith("origin/") ? symbolicRef.substring(7) : symbolicRef };
379
398
  }
380
399
  if (data == null) {
381
400
  const defaultBranch = await this.provider.config.getConfig(repoPath, "init.defaultBranch") ?? "main";
@@ -383,7 +402,12 @@ var BranchesGitSubProvider = class {
383
402
  const remote = configMap.get(`branch.${defaultBranch}.remote`);
384
403
  const merge = configMap.get(`branch.${defaultBranch}.merge`);
385
404
  const remoteBranch = merge?.startsWith("refs/heads/") ? merge.substring(11) : void 0;
386
- data = [`${defaultBranch}${remote && remoteBranch ? `\n${remote}/${remoteBranch}` : ""}`, void 0];
405
+ data = { name: defaultBranch };
406
+ if (remote && remoteBranch) {
407
+ data.upstream = remote === "." ? `refs/heads/${remoteBranch}` : `refs/remotes/${remote}/${remoteBranch}`;
408
+ data.remote = remote;
409
+ data.remoteRef = merge;
410
+ }
387
411
  }
388
412
  }
389
413
  } else if (GitWarnings.headNotABranch.test(msg)) {
@@ -395,21 +419,23 @@ var BranchesGitSubProvider = class {
395
419
  }, "log", "-n1", "--format=%H", commitOrdering ? `--${commitOrdering}-order` : void 0, "--");
396
420
  if (result.completion.status === "cancelled" || signal?.aborted) throw new CancellationError();
397
421
  const sha = result.stdout.trim();
398
- if (sha) data = [`(HEAD detached at ${shortenRevision(sha)})`, sha];
422
+ if (sha) data = {
423
+ name: `(HEAD detached at ${shortenRevision(sha)})`,
424
+ sha
425
+ };
399
426
  } else _logger.warn(`[${repoPath}] Unable to get current branch: ${ex}`);
400
427
  }
401
428
  if (data == null) return void 0;
402
- const [name, upstream] = data[0].split("\n");
429
+ const { name } = data;
430
+ let { remote, remoteRef } = data;
431
+ if (data.upstream?.startsWith("refs/heads/") && remote == null) [remote, remoteRef] = await Promise.all([this.provider.config.getConfig(repoPath, `branch.${name}.remote`), this.provider.config.getConfig(repoPath, `branch.${name}.merge`)]);
403
432
  return createReference(name, repoPath, {
404
433
  refType: "branch",
405
434
  name,
406
435
  id: getBranchId(repoPath, false, name),
407
436
  remote: false,
408
- upstream: upstream ? {
409
- name: upstream,
410
- missing: false
411
- } : void 0,
412
- sha: data[1]
437
+ upstream: data.upstream ? parseUpstream(data.upstream, "", remote, remoteRef) : void 0,
438
+ sha: data.sha
413
439
  });
414
440
  }, { cancellation });
415
441
  }
@@ -1836,6 +1862,14 @@ __decorate([debug()], BranchesGitSubProvider.prototype, "setUpstreamBranch", nul
1836
1862
  __decorate([debug()], BranchesGitSubProvider.prototype, "storeBaseBranchName", null);
1837
1863
  __decorate([debug()], BranchesGitSubProvider.prototype, "storeMergeTargetBranchName", null);
1838
1864
  __decorate([debug()], BranchesGitSubProvider.prototype, "storeUserMergeTargetBranchName", null);
1865
+ /** Reads `rev-parse --symbolic-full-name @ @{u}` output: the current branch, then its upstream when it has one */
1866
+ function parseSymbolicFullNames(stdout) {
1867
+ const [head, upstream] = stdout.trim().split("\n");
1868
+ return {
1869
+ name: parseRefName(head).name,
1870
+ upstream: upstream || void 0
1871
+ };
1872
+ }
1839
1873
  /** Each ref list {@link findRefTip} searched, by full name: one base read looks up many names in the same cached list */
1840
1874
  const refRecordsByName = /* @__PURE__ */ new WeakMap();
1841
1875
  /**