@gitkraken/core-gitlens 0.35.0 → 0.37.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/dist/git/models/branch.d.ts +9 -0
  3. package/dist/git/models/branch.js.map +1 -1
  4. package/dist/git/providers/branches.d.ts +11 -1
  5. package/dist/git/providers/revision.d.ts +6 -0
  6. package/dist/git/utils/branch.utils.d.ts +14 -0
  7. package/dist/git/utils/branch.utils.js +37 -1
  8. package/dist/git/utils/branch.utils.js.map +1 -1
  9. package/dist/git/utils/branchLanded.utils.d.ts +43 -0
  10. package/dist/git/utils/branchLanded.utils.js +56 -0
  11. package/dist/git/utils/branchLanded.utils.js.map +1 -0
  12. package/dist/git-cli/exec/git.js +2 -2
  13. package/dist/git-cli/exec/git.js.map +1 -1
  14. package/dist/git-cli/providers/branches.d.ts +6 -1
  15. package/dist/git-cli/providers/branches.js +58 -0
  16. package/dist/git-cli/providers/branches.js.map +1 -1
  17. package/dist/git-cli/providers/revision.d.ts +1 -0
  18. package/dist/git-cli/providers/revision.js +9 -0
  19. package/dist/git-cli/providers/revision.js.map +1 -1
  20. package/dist/plus/ai/models/model.js +58 -4
  21. package/dist/plus/ai/models/model.js.map +1 -1
  22. package/dist/plus/ai/providers/anthropicProvider.js +58 -223
  23. package/dist/plus/ai/providers/anthropicProvider.js.map +1 -1
  24. package/dist/plus/ai/providers/deepSeekProvider.js +32 -18
  25. package/dist/plus/ai/providers/deepSeekProvider.js.map +1 -1
  26. package/dist/plus/ai/providers/geminiProvider.js +25 -189
  27. package/dist/plus/ai/providers/geminiProvider.js.map +1 -1
  28. package/dist/plus/ai/providers/mistralProvider.js +31 -73
  29. package/dist/plus/ai/providers/mistralProvider.js.map +1 -1
  30. package/dist/plus/ai/providers/xaiProvider.js +9 -11
  31. package/dist/plus/ai/providers/xaiProvider.js.map +1 -1
  32. package/dist/plus/git-github/api/github.d.ts +14 -3
  33. package/dist/plus/git-github/api/github.js +47 -14
  34. package/dist/plus/git-github/api/github.js.map +1 -1
  35. package/dist/plus/integrations/integrationService.d.ts +5 -1
  36. package/dist/plus/integrations/integrationService.js +4 -2
  37. package/dist/plus/integrations/integrationService.js.map +1 -1
  38. package/dist/plus/integrations/manager.d.ts +24 -5
  39. package/dist/plus/integrations/models/integration.d.ts +12 -0
  40. package/dist/plus/integrations/models/integration.js +15 -1
  41. package/dist/plus/integrations/models/integration.js.map +1 -1
  42. package/dist/plus/integrations/models/issuesIntegration.d.ts +2 -1
  43. package/dist/plus/integrations/models/issuesIntegration.js +6 -3
  44. package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
  45. package/dist/plus/integrations/providers/azureDevOps.d.ts +21 -6
  46. package/dist/plus/integrations/providers/azureDevOps.js +24 -12
  47. package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
  48. package/dist/plus/integrations/providers/azureDevOpsServer.d.ts +49 -3
  49. package/dist/plus/integrations/providers/azureDevOpsServer.js +151 -23
  50. package/dist/plus/integrations/providers/azureDevOpsServer.js.map +1 -1
  51. package/dist/plus/integrations/providers/linear.d.ts +3 -2
  52. package/dist/plus/integrations/providers/linear.js +7 -5
  53. package/dist/plus/integrations/providers/linear.js.map +1 -1
  54. package/dist/plus/integrations/reads/autolinks.js.map +1 -1
  55. package/dist/plus/integrations/reads/searchPullRequests.d.ts +2 -0
  56. package/dist/plus/integrations/reads/searchPullRequests.js +18 -9
  57. package/dist/plus/integrations/reads/searchPullRequests.js.map +1 -1
  58. package/docs/integrations.md +27 -6
  59. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -6,6 +6,33 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.37.0] - 2026-11-10
10
+
11
+ ### Added
12
+
13
+ - Adds `getBranchReflogWork` to `utils/branch.utils.js`: from a local branch's reflog (newest first, as `refs.getReflogEntries` reads it), whether the branch has work authored on it (`'work'`), was created here and never had any (`'none'`), or can't be told (`'unknown'`: an empty or expired reflog, or a branch created from the same-named remote branch). Every entry counts as work except a move that adds none: the branch's creation, a reset or rename, a fast-forward merge or pull, a fetch, a clone, or a rebase that replayed nothing. It tells a branch whose work was fast-forward merged apart from a new one, which `getBranchMergedStatus` reports alike, as merged (git)
14
+ - Adds `getBranchLandedState` to `utils/branchLanded.utils.js`, with the `BranchLandedPullRequestCandidate` and `BranchLandedState` types: from a branch's tip sha and its pull requests, whether its work landed through a merged pull request. The head sha decides, never recency: an open pull request at the tip means the branch is live (`live`), a merged one at the tip means it landed, and otherwise the merged pull request with the fewest new commits decides between landed (none) and a successor (some). A pull request without a head sha never decides (git)
15
+ - Adds `cancellation` to `IntegrationManager.searchPullRequestsPage`: aborting it cancels the request in flight, a retry waiting to be sent and any page a page-number walk still has to read, and the read rejects with a `CancellationError` rather than resolving as a failed or empty page (plus/integrations)
16
+
17
+ ### Changed
18
+
19
+ - **Breaking (plus/git-github, plus/integrations)** — On GitHub/GHE the filtered pull request search (`searchPullRequestsPage`) holds at most 20 pull requests a page across all of its relationship × state facets in the full shape, and 100 in the `summary` shape, split evenly across the active facets (at least one each), and `itemsPerPage` can only lower a facet's share. The full-shape default was 30 per facet with an explicit maximum of 100, so a single-facet page now holds up to 20 rather than 30 (or 100), a 3-relationship search 6 per facet rather than 30, and an explicit `summary` size of 100 over two states 50 per facet. GitHub gives up on a page it can't build in about 11 seconds, answering 502/504 with an HTML gateway page, and the time grows with the pull requests the page selects: measured on `org:microsoft is:pr is:open`, 20 full rows took 5 to 7 seconds while 30 failed in some runs and 100 in every run. A page with more to read always carries a `cursor`; a smaller page is not the last one and carries no warning, and `page.itemsPerPage` reports what came back. Size a list from `hasMore`/`cursor` and `page.itemsPerPage`, never from the size you asked for ([#5978](https://github.com/gitkraken/vscode-gitlens/issues/5978))
20
+
21
+ ### Fixed
22
+
23
+ - Fixes the filtered pull request search on GitHub/GHE failing after about 35 seconds whenever GitHub's gateway timed out building a page, by sending the same expensive request three times. A page whose request gets a 502/504 is now asked for once more at half its size (unchanged once it is one row per facet), and a second gateway failure fails the read (warning + `fetchFailed`, as before) instead of a third identical request. A page that recovers is smaller but no facet skips or repeats a row, since every facet resumes from the last row it served, and the rest of the walk keeps the halved size so its later pages don't time out first; the reduced size travels in the cursor. Other transient failures (503, a network failure) retry unchanged as before ([#5978](https://github.com/gitkraken/vscode-gitlens/issues/5978)) (plus/git-github)
24
+
25
+ ## [0.36.0] - 2026-11-09
26
+
27
+ ### Added
28
+
29
+ - Adds `revision.getTrackedFilesRaw`, the whole index listing as the raw bytes `git ls-files -z` prints (an unmerged path once per stage), for a host that parses it elsewhere, such as in a worker, instead of having `getTrackedFiles` split and dedupe it into strings on the calling thread. Rejects when git fails, and with a `CancellationError` when aborted (git, git-cli)
30
+ - Adds `branches.getCurrentHead`, which reads what a worktree has checked out (`GitCurrentHead`: the branch, or the one a paused rebase is rebasing, read from the rebase's own `head-name`; with `sha: true`, the commit; and whether a rebase is paused) fresh on every call, from the worktree's own `HEAD` file, falling back to `git symbolic-ref` when that file can't say (a reftable repository, a symlinked `HEAD`, or a branch that is itself a symbolic ref). It never reads or fills core's current-branch caches, so it answers right after a checkout no watcher has reported yet, and never walks the index as a status read does (git, git-cli)
31
+
32
+ ### Fixed
33
+
34
+ - Fixes two identical git runs in flight at once sharing one process when one asked for text and the other for raw bytes or another encoding, which handed one of them output of the wrong type; a raw-bytes run is now never shared, so a caller that transfers its buffer to a worker can't empty another caller's (git-cli)
35
+
9
36
  ## [0.35.0] - 2026-11-08
10
37
 
11
38
  ### Changed
@@ -1193,7 +1220,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1193
1220
 
1194
1221
  - Initial release. Bundles `@gitlens/utils`, `@gitlens/git`, `@gitlens/git-cli`, `@gitlens/ai`, and `@gitlens/git-github` into a single core npm package with subpath exports.
1195
1222
 
1196
- [unreleased]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.35.0...HEAD
1223
+ [unreleased]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.37.0...HEAD
1224
+ [0.37.0]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.36.0...gitkraken:releases/core/v0.37.0
1225
+ [0.36.0]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.35.0...gitkraken:releases/core/v0.36.0
1197
1226
  [0.35.0]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.34.0...gitkraken:releases/core/v0.35.0
1198
1227
  [0.34.0]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.33.0...gitkraken:releases/core/v0.34.0
1199
1228
  [0.33.0]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.32.0...gitkraken:releases/core/v0.33.0
@@ -1,6 +1,15 @@
1
1
  import { Shape } from "../../utils/types.js";
2
2
  import { GitBranchReference } from "./reference.js";
3
3
  //#region ../git/src/models/branch.d.ts
4
+ /** What a worktree has checked out, read fresh (see `GitBranchesSubProvider.getCurrentHead`) */
5
+ export interface GitCurrentHead {
6
+ /** The branch HEAD is on (short name, e.g. `main`), or the branch a paused rebase is rebasing; `undefined` when HEAD is detached */
7
+ readonly branch: string | undefined;
8
+ /** The commit HEAD points at; `undefined` when the branch is unborn (no commit yet) or the read didn't ask for it (`sha: true`) */
9
+ readonly sha: string | undefined;
10
+ /** HEAD is detached because a rebase is paused, so `branch` names the branch being rebased, or is `undefined` when the rebase started on a detached HEAD */
11
+ readonly rebasing: boolean;
12
+ }
4
13
  export type BranchDisposition = 'starred' | 'archived';
5
14
  /** The `.git/gk/config` keys (`branch.<name>.<key>`) a branch's {@link BranchMetadata} is read from */
6
15
  export type BranchMetadataGkConfigKey = 'gk-last-accessed' | 'gk-last-modified' | 'gk-agent-last-activity' | 'gk-disposition';
@@ -1 +1 @@
1
- {"version":3,"file":"branch.js","names":[],"sources":["../../../../git/src/models/branch.ts"],"sourcesContent":["import { formatDate, fromNow } from '@gitlens/utils/date.js';\nimport { loggable } from '@gitlens/utils/decorators/log.js';\nimport { memoize } from '@gitlens/utils/decorators/memoize.js';\nimport { serializable } from '@gitlens/utils/decorators/serializable.js';\nimport { getBranchId, getRemoteNameFromBranchName, getRemoteNameSlashIndex } from '@gitlens/utils/gitRefs.js';\nimport type { Shape } from '@gitlens/utils/types.js';\nimport {\n\tformatDetachedHeadName,\n\tgetBranchTrackingWithoutRemote,\n\tisDetachedHead,\n\tparseRefName,\n} from '../utils/branch.utils.js';\nimport { getUpstreamStatus } from '../utils/status.utils.js';\nimport type { GitBranchReference } from './reference.js';\n\nexport type BranchDisposition = 'starred' | 'archived';\n\n/** The `.git/gk/config` keys (`branch.<name>.<key>`) a branch's {@link BranchMetadata} is read from */\nexport type BranchMetadataGkConfigKey =\n\t| 'gk-last-accessed'\n\t| 'gk-last-modified'\n\t| 'gk-agent-last-activity'\n\t| 'gk-disposition';\n\n/**\n * A branch's `.git/gk/config` metadata. Unlike other cached values, the cache updates these objects in place when a\n * key changes (see `Cache.patchBranchMetadata`), so every `GitBranch` holding one, old or new, reads the new value\n */\nexport interface BranchMetadata {\n\tlastAccessedAt?: string;\n\tlastModifiedAt?: string;\n\tagentLastActivityAt?: string;\n\tdisposition?: BranchDisposition;\n}\n\nexport type GitBranchShape = Shape<GitBranch>;\n\n/**\n * Each metadata object's last parsed stamps. Not `@memoize`d on the branch: the cache updates `BranchMetadata` in\n * place, so a parse is reused only while its stamp is unchanged — and shared by every branch holding the object.\n */\nconst stampDates = new WeakMap<BranchMetadata, Partial<Record<StampField, { stamp: string; date: Date }>>>();\ntype StampField = 'lastAccessedAt' | 'lastModifiedAt';\n\nfunction getStampDate(metadata: BranchMetadata, field: StampField): Date | undefined {\n\tconst stamp = metadata[field];\n\tif (!stamp) return undefined;\n\n\tlet parsed = stampDates.get(metadata);\n\tif (parsed == null) {\n\t\tparsed = {};\n\t\tstampDates.set(metadata, parsed);\n\t}\n\n\tlet entry = parsed[field];\n\tif (entry?.stamp !== stamp) {\n\t\tentry = { stamp: stamp, date: new Date(stamp) };\n\t\tparsed[field] = entry;\n\t}\n\treturn entry.date;\n}\n\n@loggable(i => i.id)\n@serializable\nexport class GitBranch implements GitBranchReference {\n\treadonly refType = 'branch';\n\treadonly detached: boolean;\n\treadonly id: string;\n\n\tprivate readonly _name: string;\n\tget name(): string {\n\t\treturn this._name;\n\t}\n\n\tprivate readonly _remote: boolean;\n\tget remote(): boolean {\n\t\treturn this._remote;\n\t}\n\n\tconstructor(\n\t\tpublic readonly repoPath: string,\n\t\tpublic readonly refName: string,\n\t\tpublic readonly current: boolean,\n\t\tpublic readonly date: Date | undefined,\n\t\t/**\n\t\t * GK config metadata (dates, disposition), shared with the cache and updated in place: comparing an old and a\n\t\t * new branch can't detect a changed stamp (no change event fires for one either)\n\t\t */\n\t\tpublic readonly metadata: BranchMetadata | undefined,\n\t\tpublic readonly sha?: string,\n\t\tpublic readonly upstream?: GitTrackingUpstream,\n\t\tpublic readonly worktree?: { path: string; isDefault: boolean } | false,\n\t\tdetached: boolean = false,\n\t\tpublic readonly rebasing: boolean = false,\n\t) {\n\t\t({ name: this._name, remote: this._remote } = parseRefName(refName));\n\n\t\tthis.detached = detached || (this.current ? isDetachedHead(this._name) : false);\n\t\tif (this.detached) {\n\t\t\tthis.id = getBranchId(repoPath, this._remote, this.sha!);\n\t\t\tthis._name = formatDetachedHeadName(this.sha!);\n\t\t} else {\n\t\t\tthis.id = getBranchId(repoPath, this._remote, this._name);\n\t\t}\n\n\t\tthis.upstream = upstream?.name ? upstream : undefined;\n\t}\n\n\tget archived(): boolean {\n\t\treturn this.metadata?.disposition === 'archived';\n\t}\n\n\t@memoize()\n\tget basename(): string {\n\t\tconst name = this.nameWithoutRemote;\n\t\tconst index = name.lastIndexOf('/');\n\t\treturn index !== -1 ? name.substring(index + 1) : name;\n\t}\n\n\tget disposition(): BranchDisposition | undefined {\n\t\treturn this.metadata?.disposition;\n\t}\n\n\t/** @returns The most recent date among lastModifiedDate, lastAccessedDate, and branch.date */\n\tget effectiveDate(): Date | undefined {\n\t\tlet maxTime: number | undefined;\n\n\t\tconst accessed = this.lastAccessedDate?.getTime();\n\t\tif (accessed != null && (maxTime == null || accessed > maxTime)) {\n\t\t\tmaxTime = accessed;\n\t\t}\n\n\t\tconst modified = this.lastModifiedDate?.getTime();\n\t\tif (modified != null && (maxTime == null || modified > maxTime)) {\n\t\t\tmaxTime = modified;\n\t\t}\n\n\t\tconst date = this.date?.getTime();\n\t\tif (date != null && (maxTime == null || date > maxTime)) {\n\t\t\tmaxTime = date;\n\t\t}\n\n\t\treturn maxTime != null ? new Date(maxTime) : undefined;\n\t}\n\n\tget lastAccessedDate(): Date | undefined {\n\t\treturn this.metadata != null ? getStampDate(this.metadata, 'lastAccessedAt') : undefined;\n\t}\n\n\t/** When a checkout's working tree or index last changed while on this branch (`gk-last-modified`), not only commits */\n\tget lastModifiedDate(): Date | undefined {\n\t\treturn this.metadata != null ? getStampDate(this.metadata, 'lastModifiedAt') : undefined;\n\t}\n\n\t@memoize()\n\tget nameWithoutRemote(): string {\n\t\treturn this.remote ? this.name.substring(getRemoteNameSlashIndex(this.name) + 1) : this.name;\n\t}\n\n\tget ref(): string {\n\t\treturn this.detached ? this.sha! : this._name;\n\t}\n\n\t@memoize()\n\tget remoteName(): string | undefined {\n\t\tif (this.remote) return getRemoteNameFromBranchName(this.name);\n\t\tif (this.upstream?.local) return undefined;\n\t\tif (this.upstream != null) return this.upstream.remote ?? getRemoteNameFromBranchName(this.upstream.name);\n\n\t\treturn undefined;\n\t}\n\n\tget starred(): boolean {\n\t\treturn this.metadata?.disposition === 'starred';\n\t}\n\n\tget status(): GitBranchStatus {\n\t\tif (this.remote) return 'remote';\n\t\tif (this.upstream == null) return this.detached ? 'detached' : 'local';\n\n\t\tif (this.upstream.missing) return 'missingUpstream';\n\t\tif (this.upstream.state.ahead && this.upstream.state.behind) return 'diverged';\n\t\tif (this.upstream.state.ahead) return 'ahead';\n\t\tif (this.upstream.state.behind) return 'behind';\n\t\treturn 'upToDate';\n\t}\n\n\t@memoize()\n\tget trackingWithoutRemote(): string | undefined {\n\t\treturn getBranchTrackingWithoutRemote(this);\n\t}\n\n\t/** Creates a copy of this branch with a different repoPath and optionally a different current flag — ONLY used for worktree-aware caching */\n\twithRepoPath(repoPath: string, current?: boolean): GitBranch {\n\t\tconst newCurrent = current ?? this.current;\n\t\tif (repoPath === this.repoPath && newCurrent === this.current) return this;\n\t\treturn new GitBranch(\n\t\t\trepoPath,\n\t\t\tthis.refName,\n\t\t\tnewCurrent,\n\t\t\tthis.date,\n\t\t\tthis.metadata,\n\t\t\tthis.sha,\n\t\t\tthis.upstream,\n\t\t\tthis.worktree,\n\t\t\tthis.detached,\n\t\t\tthis.rebasing,\n\t\t);\n\t}\n\n\tstatic is(branch: unknown): branch is GitBranch {\n\t\treturn branch instanceof GitBranch;\n\t}\n\n\tstatic formatDate(branch: GitBranchShape, format?: string | null): string {\n\t\treturn branch.date != null ? formatDate(branch.date, format ?? 'MMMM Do, YYYY h:mma') : '';\n\t}\n\n\tstatic formatDateFromNow(branch: GitBranchShape): string {\n\t\treturn branch.date != null ? fromNow(branch.date) : '';\n\t}\n\n\tstatic formatDateWithStyle(\n\t\tbranch: GitBranchShape,\n\t\tformatting: { dateStyle: string; dateFormat: string | null },\n\t): string {\n\t\treturn formatting.dateStyle === 'absolute'\n\t\t\t? GitBranch.formatDate(branch, formatting.dateFormat)\n\t\t\t: GitBranch.formatDateFromNow(branch);\n\t}\n\n\tstatic getTrackingStatus(\n\t\tbranch: GitBranchShape,\n\t\toptions?: {\n\t\t\tcount?: boolean;\n\t\t\tempty?: string;\n\t\t\texpand?: boolean;\n\t\t\ticons?: boolean;\n\t\t\tprefix?: string;\n\t\t\tseparator?: string;\n\t\t\tsuffix?: string;\n\t\t},\n\t): string {\n\t\treturn getUpstreamStatus(branch.upstream, options);\n\t}\n}\n\nexport interface GitTrackingState {\n\treadonly ahead: number;\n\treadonly behind: number;\n}\n\nexport interface GitTrackingUpstream {\n\treadonly name: string;\n\t/**\n\t * The remote the upstream is on (`branch.<name>.remote`) as git reports it, so a remote whose own name contains a\n\t * `/` stays whole. `undefined` when git is too old to report it (before 2.23 here) or the upstream is a local branch\n\t */\n\treadonly remote?: string;\n\t/**\n\t * The branch's name on its {@link remote} (`branch.<name>.merge` without `refs/heads/`), so a custom fetch refspec\n\t * can't misname it. `undefined` when git is too old to report it or the upstream is a local branch\n\t */\n\treadonly remoteBranch?: string;\n\t/** The upstream is a branch in this repository (`branch.<name>.remote = .`), so it has no remote */\n\treadonly local?: boolean;\n\treadonly missing: boolean;\n\treadonly state: GitTrackingState;\n}\n\nexport type GitBranchStatus =\n\t| 'local'\n\t| 'detached'\n\t| 'ahead'\n\t| 'behind'\n\t| 'diverged'\n\t| 'upToDate'\n\t| 'missingUpstream'\n\t| 'remote';\n"],"mappings":";;;;;;;;;;;;;;AAyCA,MAAM,6BAAa,IAAI,QAAoF;AAG3G,SAAS,aAAa,UAA0B,OAAqC;CACpF,MAAM,QAAQ,SAAS;CACvB,IAAI,CAAC,OAAO,OAAO,KAAA;CAEnB,IAAI,SAAS,WAAW,IAAI,QAAQ;CACpC,IAAI,UAAU,MAAM;EACnB,SAAS,CAAC;EACV,WAAW,IAAI,UAAU,MAAM;CAChC;CAEA,IAAI,QAAQ,OAAO;CACnB,IAAI,OAAO,UAAU,OAAO;EAC3B,QAAQ;GAAS;GAAO,MAAM,IAAI,KAAK,KAAK;EAAE;EAC9C,OAAO,SAAS;CACjB;CACA,OAAO,MAAM;AACd;AAIO,IAAM,YAAA,aAAN,MAAM,UAAwC;CAgBnC;CACA;CACA;CACA;CAKA;CACA;CACA;CACA;CAEA;CA5BjB,UAAmB;CACnB;CACA;CAEA;CACA,IAAI,OAAe;EAClB,OAAO,KAAK;CACb;CAEA;CACA,IAAI,SAAkB;EACrB,OAAO,KAAK;CACb;CAEA,YACC,UACA,SACA,SACA,MAKA,UACA,KACA,UACA,UACA,WAAoB,OACpB,WAAoC,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ACzE,OAAO,OAAO,QAAQ,OAAO,WAAW,OAAO,MAAM,UAAU,qBAAqB,IAAI;CACzF;CAEA,OAAO,kBAAkB,QAAgC;EACxD,OAAO,OAAO,QAAQ,OAAO,QAAQ,OAAO,IAAI,IAAI;CACrD;CAEA,OAAO,oBACN,QACA,YACS;EACT,OAAO,WAAW,cAAc,aAAA,WACnB,WAAW,QAAQ,WAAW,UAAU,IAAA,WACxC,kBAAkB,MAAM;CACtC;CAEA,OAAO,kBACN,QACA,SASS;EACT,OAAO,kBAAkB,OAAO,UAAU,OAAO;CAClD;AACD;AArIE,WAAA,CAAA,QAAQ,CAAA,GAAA,UAAA,WAAA,YAAA,IAAA;AA0CR,WAAA,CAAA,QAAQ,CAAA,GAAA,UAAA,WAAA,qBAAA,IAAA;AASR,WAAA,CAAA,QAAQ,CAAA,GAAA,UAAA,WAAA,cAAA,IAAA;AAwBR,WAAA,CAAA,QAAQ,CAAA,GAAA,UAAA,WAAA,yBAAA,IAAA;AA7HT,YAAA,aAAA,WAAA,CAAA,UAAS,MAAK,EAAE,EAAE,GAClB,YAAA,GAAA,SAAA"}
1
+ {"version":3,"file":"branch.js","names":[],"sources":["../../../../git/src/models/branch.ts"],"sourcesContent":["import { formatDate, fromNow } from '@gitlens/utils/date.js';\nimport { loggable } from '@gitlens/utils/decorators/log.js';\nimport { memoize } from '@gitlens/utils/decorators/memoize.js';\nimport { serializable } from '@gitlens/utils/decorators/serializable.js';\nimport { getBranchId, getRemoteNameFromBranchName, getRemoteNameSlashIndex } from '@gitlens/utils/gitRefs.js';\nimport type { Shape } from '@gitlens/utils/types.js';\nimport {\n\tformatDetachedHeadName,\n\tgetBranchTrackingWithoutRemote,\n\tisDetachedHead,\n\tparseRefName,\n} from '../utils/branch.utils.js';\nimport { getUpstreamStatus } from '../utils/status.utils.js';\nimport type { GitBranchReference } from './reference.js';\n\n/** What a worktree has checked out, read fresh (see `GitBranchesSubProvider.getCurrentHead`) */\nexport interface GitCurrentHead {\n\t/** The branch HEAD is on (short name, e.g. `main`), or the branch a paused rebase is rebasing; `undefined` when HEAD is detached */\n\treadonly branch: string | undefined;\n\t/** The commit HEAD points at; `undefined` when the branch is unborn (no commit yet) or the read didn't ask for it (`sha: true`) */\n\treadonly sha: string | undefined;\n\t/** HEAD is detached because a rebase is paused, so `branch` names the branch being rebased, or is `undefined` when the rebase started on a detached HEAD */\n\treadonly rebasing: boolean;\n}\n\nexport type BranchDisposition = 'starred' | 'archived';\n\n/** The `.git/gk/config` keys (`branch.<name>.<key>`) a branch's {@link BranchMetadata} is read from */\nexport type BranchMetadataGkConfigKey =\n\t| 'gk-last-accessed'\n\t| 'gk-last-modified'\n\t| 'gk-agent-last-activity'\n\t| 'gk-disposition';\n\n/**\n * A branch's `.git/gk/config` metadata. Unlike other cached values, the cache updates these objects in place when a\n * key changes (see `Cache.patchBranchMetadata`), so every `GitBranch` holding one, old or new, reads the new value\n */\nexport interface BranchMetadata {\n\tlastAccessedAt?: string;\n\tlastModifiedAt?: string;\n\tagentLastActivityAt?: string;\n\tdisposition?: BranchDisposition;\n}\n\nexport type GitBranchShape = Shape<GitBranch>;\n\n/**\n * Each metadata object's last parsed stamps. Not `@memoize`d on the branch: the cache updates `BranchMetadata` in\n * place, so a parse is reused only while its stamp is unchanged — and shared by every branch holding the object.\n */\nconst stampDates = new WeakMap<BranchMetadata, Partial<Record<StampField, { stamp: string; date: Date }>>>();\ntype StampField = 'lastAccessedAt' | 'lastModifiedAt';\n\nfunction getStampDate(metadata: BranchMetadata, field: StampField): Date | undefined {\n\tconst stamp = metadata[field];\n\tif (!stamp) return undefined;\n\n\tlet parsed = stampDates.get(metadata);\n\tif (parsed == null) {\n\t\tparsed = {};\n\t\tstampDates.set(metadata, parsed);\n\t}\n\n\tlet entry = parsed[field];\n\tif (entry?.stamp !== stamp) {\n\t\tentry = { stamp: stamp, date: new Date(stamp) };\n\t\tparsed[field] = entry;\n\t}\n\treturn entry.date;\n}\n\n@loggable(i => i.id)\n@serializable\nexport class GitBranch implements GitBranchReference {\n\treadonly refType = 'branch';\n\treadonly detached: boolean;\n\treadonly id: string;\n\n\tprivate readonly _name: string;\n\tget name(): string {\n\t\treturn this._name;\n\t}\n\n\tprivate readonly _remote: boolean;\n\tget remote(): boolean {\n\t\treturn this._remote;\n\t}\n\n\tconstructor(\n\t\tpublic readonly repoPath: string,\n\t\tpublic readonly refName: string,\n\t\tpublic readonly current: boolean,\n\t\tpublic readonly date: Date | undefined,\n\t\t/**\n\t\t * GK config metadata (dates, disposition), shared with the cache and updated in place: comparing an old and a\n\t\t * new branch can't detect a changed stamp (no change event fires for one either)\n\t\t */\n\t\tpublic readonly metadata: BranchMetadata | undefined,\n\t\tpublic readonly sha?: string,\n\t\tpublic readonly upstream?: GitTrackingUpstream,\n\t\tpublic readonly worktree?: { path: string; isDefault: boolean } | false,\n\t\tdetached: boolean = false,\n\t\tpublic readonly rebasing: boolean = false,\n\t) {\n\t\t({ name: this._name, remote: this._remote } = parseRefName(refName));\n\n\t\tthis.detached = detached || (this.current ? isDetachedHead(this._name) : false);\n\t\tif (this.detached) {\n\t\t\tthis.id = getBranchId(repoPath, this._remote, this.sha!);\n\t\t\tthis._name = formatDetachedHeadName(this.sha!);\n\t\t} else {\n\t\t\tthis.id = getBranchId(repoPath, this._remote, this._name);\n\t\t}\n\n\t\tthis.upstream = upstream?.name ? upstream : undefined;\n\t}\n\n\tget archived(): boolean {\n\t\treturn this.metadata?.disposition === 'archived';\n\t}\n\n\t@memoize()\n\tget basename(): string {\n\t\tconst name = this.nameWithoutRemote;\n\t\tconst index = name.lastIndexOf('/');\n\t\treturn index !== -1 ? name.substring(index + 1) : name;\n\t}\n\n\tget disposition(): BranchDisposition | undefined {\n\t\treturn this.metadata?.disposition;\n\t}\n\n\t/** @returns The most recent date among lastModifiedDate, lastAccessedDate, and branch.date */\n\tget effectiveDate(): Date | undefined {\n\t\tlet maxTime: number | undefined;\n\n\t\tconst accessed = this.lastAccessedDate?.getTime();\n\t\tif (accessed != null && (maxTime == null || accessed > maxTime)) {\n\t\t\tmaxTime = accessed;\n\t\t}\n\n\t\tconst modified = this.lastModifiedDate?.getTime();\n\t\tif (modified != null && (maxTime == null || modified > maxTime)) {\n\t\t\tmaxTime = modified;\n\t\t}\n\n\t\tconst date = this.date?.getTime();\n\t\tif (date != null && (maxTime == null || date > maxTime)) {\n\t\t\tmaxTime = date;\n\t\t}\n\n\t\treturn maxTime != null ? new Date(maxTime) : undefined;\n\t}\n\n\tget lastAccessedDate(): Date | undefined {\n\t\treturn this.metadata != null ? getStampDate(this.metadata, 'lastAccessedAt') : undefined;\n\t}\n\n\t/** When a checkout's working tree or index last changed while on this branch (`gk-last-modified`), not only commits */\n\tget lastModifiedDate(): Date | undefined {\n\t\treturn this.metadata != null ? getStampDate(this.metadata, 'lastModifiedAt') : undefined;\n\t}\n\n\t@memoize()\n\tget nameWithoutRemote(): string {\n\t\treturn this.remote ? this.name.substring(getRemoteNameSlashIndex(this.name) + 1) : this.name;\n\t}\n\n\tget ref(): string {\n\t\treturn this.detached ? this.sha! : this._name;\n\t}\n\n\t@memoize()\n\tget remoteName(): string | undefined {\n\t\tif (this.remote) return getRemoteNameFromBranchName(this.name);\n\t\tif (this.upstream?.local) return undefined;\n\t\tif (this.upstream != null) return this.upstream.remote ?? getRemoteNameFromBranchName(this.upstream.name);\n\n\t\treturn undefined;\n\t}\n\n\tget starred(): boolean {\n\t\treturn this.metadata?.disposition === 'starred';\n\t}\n\n\tget status(): GitBranchStatus {\n\t\tif (this.remote) return 'remote';\n\t\tif (this.upstream == null) return this.detached ? 'detached' : 'local';\n\n\t\tif (this.upstream.missing) return 'missingUpstream';\n\t\tif (this.upstream.state.ahead && this.upstream.state.behind) return 'diverged';\n\t\tif (this.upstream.state.ahead) return 'ahead';\n\t\tif (this.upstream.state.behind) return 'behind';\n\t\treturn 'upToDate';\n\t}\n\n\t@memoize()\n\tget trackingWithoutRemote(): string | undefined {\n\t\treturn getBranchTrackingWithoutRemote(this);\n\t}\n\n\t/** Creates a copy of this branch with a different repoPath and optionally a different current flag — ONLY used for worktree-aware caching */\n\twithRepoPath(repoPath: string, current?: boolean): GitBranch {\n\t\tconst newCurrent = current ?? this.current;\n\t\tif (repoPath === this.repoPath && newCurrent === this.current) return this;\n\t\treturn new GitBranch(\n\t\t\trepoPath,\n\t\t\tthis.refName,\n\t\t\tnewCurrent,\n\t\t\tthis.date,\n\t\t\tthis.metadata,\n\t\t\tthis.sha,\n\t\t\tthis.upstream,\n\t\t\tthis.worktree,\n\t\t\tthis.detached,\n\t\t\tthis.rebasing,\n\t\t);\n\t}\n\n\tstatic is(branch: unknown): branch is GitBranch {\n\t\treturn branch instanceof GitBranch;\n\t}\n\n\tstatic formatDate(branch: GitBranchShape, format?: string | null): string {\n\t\treturn branch.date != null ? formatDate(branch.date, format ?? 'MMMM Do, YYYY h:mma') : '';\n\t}\n\n\tstatic formatDateFromNow(branch: GitBranchShape): string {\n\t\treturn branch.date != null ? fromNow(branch.date) : '';\n\t}\n\n\tstatic formatDateWithStyle(\n\t\tbranch: GitBranchShape,\n\t\tformatting: { dateStyle: string; dateFormat: string | null },\n\t): string {\n\t\treturn formatting.dateStyle === 'absolute'\n\t\t\t? GitBranch.formatDate(branch, formatting.dateFormat)\n\t\t\t: GitBranch.formatDateFromNow(branch);\n\t}\n\n\tstatic getTrackingStatus(\n\t\tbranch: GitBranchShape,\n\t\toptions?: {\n\t\t\tcount?: boolean;\n\t\t\tempty?: string;\n\t\t\texpand?: boolean;\n\t\t\ticons?: boolean;\n\t\t\tprefix?: string;\n\t\t\tseparator?: string;\n\t\t\tsuffix?: string;\n\t\t},\n\t): string {\n\t\treturn getUpstreamStatus(branch.upstream, options);\n\t}\n}\n\nexport interface GitTrackingState {\n\treadonly ahead: number;\n\treadonly behind: number;\n}\n\nexport interface GitTrackingUpstream {\n\treadonly name: string;\n\t/**\n\t * The remote the upstream is on (`branch.<name>.remote`) as git reports it, so a remote whose own name contains a\n\t * `/` stays whole. `undefined` when git is too old to report it (before 2.23 here) or the upstream is a local branch\n\t */\n\treadonly remote?: string;\n\t/**\n\t * The branch's name on its {@link remote} (`branch.<name>.merge` without `refs/heads/`), so a custom fetch refspec\n\t * can't misname it. `undefined` when git is too old to report it or the upstream is a local branch\n\t */\n\treadonly remoteBranch?: string;\n\t/** The upstream is a branch in this repository (`branch.<name>.remote = .`), so it has no remote */\n\treadonly local?: boolean;\n\treadonly missing: boolean;\n\treadonly state: GitTrackingState;\n}\n\nexport type GitBranchStatus =\n\t| 'local'\n\t| 'detached'\n\t| 'ahead'\n\t| 'behind'\n\t| 'diverged'\n\t| 'upToDate'\n\t| 'missingUpstream'\n\t| 'remote';\n"],"mappings":";;;;;;;;;;;;;;AAmDA,MAAM,6BAAa,IAAI,QAAoF;AAG3G,SAAS,aAAa,UAA0B,OAAqC;CACpF,MAAM,QAAQ,SAAS;CACvB,IAAI,CAAC,OAAO,OAAO,KAAA;CAEnB,IAAI,SAAS,WAAW,IAAI,QAAQ;CACpC,IAAI,UAAU,MAAM;EACnB,SAAS,CAAC;EACV,WAAW,IAAI,UAAU,MAAM;CAChC;CAEA,IAAI,QAAQ,OAAO;CACnB,IAAI,OAAO,UAAU,OAAO;EAC3B,QAAQ;GAAS;GAAO,MAAM,IAAI,KAAK,KAAK;EAAE;EAC9C,OAAO,SAAS;CACjB;CACA,OAAO,MAAM;AACd;AAIO,IAAM,YAAA,aAAN,MAAM,UAAwC;CAgBnC;CACA;CACA;CACA;CAKA;CACA;CACA;CACA;CAEA;CA5BjB,UAAmB;CACnB;CACA;CAEA;CACA,IAAI,OAAe;EAClB,OAAO,KAAK;CACb;CAEA;CACA,IAAI,SAAkB;EACrB,OAAO,KAAK;CACb;CAEA,YACC,UACA,SACA,SACA,MAKA,UACA,KACA,UACA,UACA,WAAoB,OACpB,WAAoC,OACnC;EAde,KAAA,WAAA;EACA,KAAA,UAAA;EACA,KAAA,UAAA;EACA,KAAA,OAAA;EAKA,KAAA,WAAA;EACA,KAAA,MAAA;EACA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O,OAAO,QAAQ,OAAO,QAAQ,OAAO,IAAI,IAAI;CACrD;CAEA,OAAO,oBACN,QACA,YACS;EACT,OAAO,WAAW,cAAc,aAAA,WACnB,WAAW,QAAQ,WAAW,UAAU,IAAA,WACxC,kBAAkB,MAAM;CACtC;CAEA,OAAO,kBACN,QACA,SASS;EACT,OAAO,kBAAkB,OAAO,UAAU,OAAO;CAClD;AACD;AArIE,WAAA,CAAA,QAAQ,CAAA,GAAA,UAAA,WAAA,YAAA,IAAA;AA0CR,WAAA,CAAA,QAAQ,CAAA,GAAA,UAAA,WAAA,qBAAA,IAAA;AASR,WAAA,CAAA,QAAQ,CAAA,GAAA,UAAA,WAAA,cAAA,IAAA;AAwBR,WAAA,CAAA,QAAQ,CAAA,GAAA,UAAA,WAAA,yBAAA,IAAA;AA7HT,YAAA,aAAA,WAAA,CAAA,UAAS,MAAK,EAAE,EAAE,GAClB,YAAA,GAAA,SAAA"}
@@ -1,7 +1,7 @@
1
1
  import { PagedResult, PagingOptions } from "../../utils/paging.js";
2
2
  import { GitBranchReference } from "../models/reference.js";
3
3
  import { GitCommitStats } from "../models/commit.js";
4
- import { BranchDisposition, GitBranch } from "../models/branch.js";
4
+ import { BranchDisposition, GitBranch, GitCurrentHead } from "../models/branch.js";
5
5
  import { GitContributor } from "../models/contributor.js";
6
6
  import { ConflictDetectionResult } from "../models/mergeConflicts.js";
7
7
  import { GitCommandPriority } from "../run.types.js";
@@ -190,6 +190,16 @@ export interface GitBranchesSubProvider {
190
190
  getBranchMergedStatus?(repoPath: string, branch: GitBranchReference, into: GitBranchReference, cancellation?: AbortSignal): Promise<GitBranchMergedStatus>;
191
191
  /** @internal not intended to be used outside of the sub-providers */
192
192
  getCurrentBranchReference?(repoPath: string, cancellation?: AbortSignal): Promise<GitBranchReference | undefined>;
193
+ /**
194
+ * Reads what `repoPath` has checked out fresh on every call: never from or into core's current-branch caches,
195
+ * without waiting on cache validation, and without walking the index as a status does, so it answers right after a
196
+ * checkout no watcher reported yet. A detached HEAD with a paused rebase names the rebased branch, as `getStatus` does,
197
+ * and no branch when that rebase started on a detached HEAD. `sha` also reads the commit HEAD points at. Rejects when
198
+ * `repoPath` isn't a repository or git fails, and with a `CancellationError` when `cancellation` aborts.
199
+ */
200
+ getCurrentHead?(repoPath: string, options?: {
201
+ sha?: boolean;
202
+ }, cancellation?: AbortSignal): Promise<GitCurrentHead>;
193
203
  getLocalBranchByUpstream?(repoPath: string, remoteBranchName: string, cancellation?: AbortSignal): Promise<GitBranch | undefined>;
194
204
  /**
195
205
  * Where `branch` (a local branch's short or full name; the branch checked out at `repoPath` when omitted) pushes to,
@@ -34,6 +34,12 @@ export interface GitRevisionSubProvider {
34
34
  getTrackedFiles(repoPath: string, options?: {
35
35
  paths?: readonly string[];
36
36
  }, cancellation?: AbortSignal): Promise<string[]>;
37
+ /**
38
+ * The whole index's paths exactly as `git ls-files -z` prints them: each NUL-terminated, repo-relative, in index
39
+ * order. An unmerged path appears once per stage, unlike {@link getTrackedFiles}, which dedupes.
40
+ * Rejects when git fails (e.g. not a repository), and with a `CancellationError` when `cancellation` aborts.
41
+ */
42
+ getTrackedFilesRaw?(repoPath: string, cancellation?: AbortSignal): Promise<Uint8Array>;
37
43
  getTreeEntryForRevision(repoPath: string, path: string, rev: string): Promise<GitTreeEntry | undefined>;
38
44
  /**
39
45
  * Lists every entry (files and folders) of the tree at `rev`, recursively.
@@ -1,6 +1,7 @@
1
1
  import { PageableResult } from "../../utils/paging.js";
2
2
  import { GitBranchReference, GitReference } from "../models/reference.js";
3
3
  import { BranchMetadata, BranchMetadataGkConfigKey, GitBranch, GitTrackingUpstream } from "../models/branch.js";
4
+ import { GitReflogEntry } from "../models/reflog.js";
4
5
  //#region ../git/src/utils/branch.utils.d.ts
5
6
  export declare function formatDetachedHeadName(sha: string): string;
6
7
  export declare function getBranchNameAndRemote(ref: GitBranchReference): [name: string, remote: string | undefined];
@@ -41,5 +42,18 @@ export declare function parseBranchMetadataGkConfigKey(key: string): {
41
42
  } | undefined;
42
43
  /** Sets the field `key` is read into to `value`, or removes it for `undefined`, exactly as a fresh read of the key would */
43
44
  export declare function setBranchMetadataValue(metadata: BranchMetadata, key: BranchMetadataGkConfigKey, value: string | undefined): void;
45
+ /**
46
+ * Classifies whether a local branch's own reflog shows work authored on it. A branch that is 0 commits ahead
47
+ * of its merge target is either brand new (nothing merged) or had its work fast-forward merged, and only the
48
+ * reflog tells them apart. Exclusion-based: any entry other than a known no-work move (creation, reset, rename,
49
+ * fast-forward, fetch, clone, or a rebase that replayed nothing) counts as work.
50
+ *
51
+ * - `work`: the branch has its own work, so it was genuinely merged
52
+ * - `none`: the branch was created here and never had work, so it's just fresh
53
+ * - `unknown`: can't tell (empty or expired reflog, or created from the same-named remote branch)
54
+ *
55
+ * @param entries the branch's reflog, newest first
56
+ */
57
+ export declare function getBranchReflogWork(entries: readonly GitReflogEntry[], branchName: string): 'work' | 'none' | 'unknown';
44
58
  //#endregion
45
59
  //# sourceMappingURL=branch.utils.d.ts.map
@@ -174,7 +174,43 @@ function setBranchMetadataValue(metadata, key, value) {
174
174
  else delete metadata.disposition;
175
175
  }
176
176
  }
177
+ const mergeFastForwardRegex = /^merge .+: Fast-forward$/;
178
+ const pullFastForwardRegex = /^pull\b.*: Fast-forward$/;
179
+ const rebaseFinishRegex = /^(?:rebase|pull)\b.* \(finish\): .* onto ([0-9a-f]+)$/;
180
+ const branchCreatedRegex = /^branch: Created from (.+)$/;
181
+ /**
182
+ * Classifies whether a local branch's own reflog shows work authored on it. A branch that is 0 commits ahead
183
+ * of its merge target is either brand new (nothing merged) or had its work fast-forward merged, and only the
184
+ * reflog tells them apart. Exclusion-based: any entry other than a known no-work move (creation, reset, rename,
185
+ * fast-forward, fetch, clone, or a rebase that replayed nothing) counts as work.
186
+ *
187
+ * - `work`: the branch has its own work, so it was genuinely merged
188
+ * - `none`: the branch was created here and never had work, so it's just fresh
189
+ * - `unknown`: can't tell (empty or expired reflog, or created from the same-named remote branch)
190
+ *
191
+ * @param entries the branch's reflog, newest first
192
+ */
193
+ function getBranchReflogWork(entries, branchName) {
194
+ let createdFrom;
195
+ for (const entry of entries) {
196
+ const { message } = entry;
197
+ const created = branchCreatedRegex.exec(message);
198
+ if (created != null) {
199
+ createdFrom = created[1];
200
+ continue;
201
+ }
202
+ if (message.startsWith("branch: Reset to ") || message.startsWith("Branch: renamed ") || message.startsWith("reset: moving to ") || mergeFastForwardRegex.test(message) || pullFastForwardRegex.test(message) || message.startsWith("fetch") || message.startsWith("clone: ")) continue;
203
+ const finished = rebaseFinishRegex.exec(message);
204
+ if (finished != null && finished[1] === entry.sha) continue;
205
+ return "work";
206
+ }
207
+ if (createdFrom == null) return "unknown";
208
+ const source = createdFrom.startsWith("refs/remotes/") ? createdFrom.substring(13) : createdFrom;
209
+ const slash = source.indexOf("/");
210
+ if (slash > 0 && source.substring(slash + 1) === branchName) return "unknown";
211
+ return "none";
212
+ }
177
213
  //#endregion
178
- export { formatDetachedHeadName, getBranchNameAndRemote, getBranchTrackingWithoutRemote, getLocalBranchByUpstream, getLocalBranchUpstreamNames, isDetachedHead, isOfBranchRefType, isRemoteBranch, isRemoteHEAD, parseBranchMetadataGkConfigKey, parseRefName, parseUpstream, setBranchMetadataValue, splitRemoteBranchName };
214
+ export { formatDetachedHeadName, getBranchNameAndRemote, getBranchReflogWork, getBranchTrackingWithoutRemote, getLocalBranchByUpstream, getLocalBranchUpstreamNames, isDetachedHead, isOfBranchRefType, isRemoteBranch, isRemoteHEAD, parseBranchMetadataGkConfigKey, parseRefName, parseUpstream, setBranchMetadataValue, splitRemoteBranchName };
179
215
 
180
216
  //# sourceMappingURL=branch.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"branch.utils.js","names":[],"sources":["../../../../git/src/utils/branch.utils.ts"],"sourcesContent":["import { getRemoteNameSlashIndex } from '@gitlens/utils/gitRefs.js';\nimport type { PageableResult } from '@gitlens/utils/paging.js';\nimport type { BranchMetadata, BranchMetadataGkConfigKey, GitBranch, GitTrackingUpstream } from '../models/branch.js';\nimport type { GitBranchReference, GitReference } from '../models/reference.js';\nimport { shortenRevision } from './revision.utils.js';\n\n/**\n * The names git uses where a branch name would go when HEAD isn't on a branch — `(HEAD detached\n * at|from <rev>)`, `(no branch)`, `(no branch, rebasing <name>)`, `(no branch, bisect started on\n * <name>)`, and `git status --porcelain=v2`'s `branch.head` token `(detached)` — plus bare `HEAD`\n * and our own {@link formatDetachedHeadName} output (`(<rev>...)`).\n *\n * Deliberately NOT \"anything parenthesized\": parentheses are legal in ref names, so `(release)`,\n * `v1.0(rc)` and `feat/(wip)` are all real branches a user can be on. Matching those made\n * `GitBranch` rewrite a genuine branch's `name` to the synthesized `(sha…)` label and re-key its\n * `id` by SHA, which corrupts its identity for every downstream consumer.\n */\nconst detachedHEADRegex = /^(?:HEAD|\\(detached\\)|\\(HEAD detached (?:at|from) .+\\)|\\(no branch.*\\)|\\(.+\\.\\.\\.\\))$/;\n\nexport function formatDetachedHeadName(sha: string): string {\n\treturn `(${shortenRevision(sha)}...)`;\n}\n\nexport function getBranchNameAndRemote(ref: GitBranchReference): [name: string, remote: string | undefined] {\n\tif (ref.remote) {\n\t\tconst index = getRemoteNameSlashIndex(ref.name);\n\t\tif (index === -1) return [ref.name, undefined];\n\n\t\treturn [ref.name.substring(index + 1), ref.name.substring(0, index)];\n\t}\n\n\tif (ref.upstream?.local) return [ref.name, undefined];\n\tif (ref.upstream?.remote) return [ref.name, ref.upstream.remote];\n\n\tif (ref.upstream?.name != null) {\n\t\tconst index = getRemoteNameSlashIndex(ref.upstream.name);\n\t\tif (index === -1) return [ref.name, undefined];\n\n\t\treturn [ref.name, ref.upstream.name.substring(0, index)];\n\t}\n\n\treturn [ref.name, undefined];\n}\n\n/**\n * The upstream's branch name on its remote. The name git reports (`branch.<name>.merge`) wins over stripping the local\n * remote-tracking name, which a custom fetch refspec makes differ (`origin` fetching into `refs/remotes/mirror/*`).\n *\n * A remote-tracking branch tracks nothing. The Graph's remote refs carry the remote's own name in `upstream`, which\n * read as a tracking name would fetch a branch named after the remote (`git fetch upstream upstream`)\n */\nexport function getBranchTrackingWithoutRemote(ref: GitBranchReference): string | undefined {\n\tif (ref.remote || ref.upstream == null) return undefined;\n\n\tconst { name, remote, remoteBranch, local } = ref.upstream;\n\tif (local) return name;\n\tif (remoteBranch) return remoteBranch;\n\tif (remote && name.startsWith(`${remote}/`)) return name.substring(remote.length + 1);\n\n\treturn name.substring(getRemoteNameSlashIndex(name) + 1);\n}\n\n/**\n * Splits `name` at the longest of `remoteNames` that prefixes it, so a remote whose own name contains a `/` resolves\n * whole. A leading `remotes/` is stripped only when no remote matches the name as given\n */\nexport function splitRemoteBranchName(\n\tname: string,\n\tremoteNames: Iterable<string>,\n): [remote: string, branch: string] | undefined {\n\tconst names = Array.isArray(remoteNames) ? remoteNames : [...remoteNames];\n\n\tconst split = splitAtLongestRemote(name, names);\n\tif (split != null || !name.startsWith('remotes/')) return split;\n\n\treturn splitAtLongestRemote(name.substring(8), names);\n}\n\nfunction splitAtLongestRemote(\n\tname: string,\n\tremoteNames: Iterable<string>,\n): [remote: string, branch: string] | undefined {\n\tlet match: string | undefined;\n\tfor (const remote of remoteNames) {\n\t\tif (\n\t\t\tname.length > remote.length + 1 &&\n\t\t\tname.charCodeAt(remote.length) === 47 /* '/' */ &&\n\t\t\tname.startsWith(remote) &&\n\t\t\t(match == null || remote.length > match.length)\n\t\t) {\n\t\t\tmatch = remote;\n\t\t}\n\t}\n\n\treturn match != null ? [match, name.substring(match.length + 1)] : undefined;\n}\n\nexport function isDetachedHead(name: string): boolean {\n\t// If there is whitespace in the name assume this is not a valid branch name\n\t// Deals with detached HEAD states\n\tname = name.trim();\n\treturn name.length ? detachedHEADRegex.test(name) : true;\n}\n\nexport function isOfBranchRefType(branch: GitReference | undefined): branch is GitBranchReference {\n\treturn branch?.refType === 'branch';\n}\n\nconst localBranchesPrefixRegex = /^(refs\\/)?heads\\//i;\nconst remoteBranchesPrefixRegex = /^(refs\\/)?remotes\\//i;\nconst remoteHEADRegex = /^(refs\\/)?remotes\\/(.*\\/)HEAD$/i;\n\nexport function isRemoteBranch(refName: string): boolean {\n\treturn remoteBranchesPrefixRegex.test(refName);\n}\n\nexport function isRemoteHEAD(refName: string): boolean {\n\treturn remoteHEADRegex.test(refName);\n}\n\nexport function parseRefName(refName: string): { name: string; remote: boolean } {\n\tconst remote = isRemoteBranch(refName);\n\n\tlet name;\n\tif (remote) {\n\t\t// Strip off refs/remotes/\n\t\tname = refName.replace(remoteBranchesPrefixRegex, '');\n\t} else {\n\t\t// Strip off refs/heads/\n\t\tname = refName.replace(localBranchesPrefixRegex, '');\n\t}\n\n\treturn { name: name, remote: remote };\n}\n\nexport async function getLocalBranchByUpstream(\n\tremoteBranchName: string,\n\tbranches: PageableResult<GitBranch> | ReadonlyMap<unknown, GitBranch>,\n): Promise<GitBranch | undefined> {\n\tlet qualifiedRemoteBranchName;\n\tif (remoteBranchName.startsWith('remotes/')) {\n\t\tqualifiedRemoteBranchName = remoteBranchName;\n\t\tremoteBranchName = remoteBranchName.substring(8);\n\t} else {\n\t\tqualifiedRemoteBranchName = `remotes/${remoteBranchName}`;\n\t}\n\n\tfunction matches(branch: GitBranch): boolean {\n\t\treturn (\n\t\t\t!branch.remote &&\n\t\t\tbranch.upstream?.name != null &&\n\t\t\t(branch.upstream.name === remoteBranchName || branch.upstream.name === qualifiedRemoteBranchName!)\n\t\t);\n\t}\n\n\tconst values = branches.values();\n\tif (Symbol.asyncIterator in values) {\n\t\tfor await (const branch of values) {\n\t\t\tif (matches(branch)) return branch;\n\t\t}\n\t} else {\n\t\tfor (const branch of values) {\n\t\t\tif (matches(branch)) return branch;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nexport async function getLocalBranchUpstreamNames(branches: PageableResult<GitBranch>): Promise<Set<string>> {\n\tconst remoteBranches = new Set<string>();\n\n\tfor await (const branch of branches.values()) {\n\t\tif (!branch.remote && branch.upstream?.name != null) {\n\t\t\tremoteBranches.add(branch.upstream.name);\n\t\t}\n\t}\n\n\treturn remoteBranches;\n}\n\nconst trackingStateRegex = /(?:\\[(?:ahead ([0-9]+))?[,\\s]*(?:behind ([0-9]+))?]|\\[(gone)])/;\n\n/**\n * @param remote - `%(upstream:remotename)`; `.` is a local upstream, and empty means git reported none. A reported\n * remote always wins, even when a custom fetch refspec puts its branches under `refs/heads/`; only when none was\n * reported (git < 2.23) is an upstream under `refs/heads/` taken as local\n * @param remoteRef - `%(upstream:remoteref)`; the upstream's ref on `remote`, read as its branch name\n */\nexport function parseUpstream(\n\tupstream: string,\n\ttracking: string,\n\tremote?: string,\n\tremoteRef?: string,\n): GitTrackingUpstream | undefined {\n\tif (!upstream) return undefined;\n\n\tconst { name } = parseRefName(upstream);\n\tconst local = remote ? remote === '.' : upstream.startsWith('refs/heads/');\n\tconst localProp = local ? { local: true } : undefined;\n\tconst remoteProp =\n\t\tremote && remote !== '.'\n\t\t\t? { remote: remote, ...(remoteRef ? { remoteBranch: remoteRef.replace(/^refs\\/heads\\//, '') } : undefined) }\n\t\t\t: undefined;\n\n\tconst match = trackingStateRegex.exec(tracking);\n\tif (match == null) {\n\t\treturn { name: name, missing: false, state: { ahead: 0, behind: 0 }, ...remoteProp, ...localProp };\n\t}\n\n\tconst ahead = match[1] == null ? 0 : Number(match[1]);\n\tconst behind = match[2] == null ? 0 : Number(match[2]);\n\n\treturn {\n\t\tname: name,\n\t\tmissing: match[3] != null,\n\t\tstate: { ahead: isNaN(ahead) ? 0 : ahead, behind: isNaN(behind) ? 0 : behind },\n\t\t...remoteProp,\n\t\t...localProp,\n\t};\n}\n\nconst branchMetadataGkConfigKeyRegex =\n\t/^branch\\.(.+)\\.(gk-(?:last-accessed|last-modified|agent-last-activity|disposition))$/;\n\n/** Splits a `branch.<name>.<key>` gk config key that a branch's {@link BranchMetadata} is read from, or `undefined` for any other key */\nexport function parseBranchMetadataGkConfigKey(\n\tkey: string,\n): { branch: string; key: BranchMetadataGkConfigKey } | undefined {\n\tconst match = branchMetadataGkConfigKeyRegex.exec(key);\n\tif (match == null) return undefined;\n\n\treturn { branch: match[1], key: match[2] as BranchMetadataGkConfigKey };\n}\n\n/** Sets the field `key` is read into to `value`, or removes it for `undefined`, exactly as a fresh read of the key would */\nexport function setBranchMetadataValue(\n\tmetadata: BranchMetadata,\n\tkey: BranchMetadataGkConfigKey,\n\tvalue: string | undefined,\n): void {\n\tswitch (key) {\n\t\tcase 'gk-last-accessed':\n\t\t\tif (value != null) {\n\t\t\t\tmetadata.lastAccessedAt = value;\n\t\t\t} else {\n\t\t\t\tdelete metadata.lastAccessedAt;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'gk-last-modified':\n\t\t\tif (value != null) {\n\t\t\t\tmetadata.lastModifiedAt = value;\n\t\t\t} else {\n\t\t\t\tdelete metadata.lastModifiedAt;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'gk-agent-last-activity':\n\t\t\tif (value != null) {\n\t\t\t\tmetadata.agentLastActivityAt = value;\n\t\t\t} else {\n\t\t\t\tdelete metadata.agentLastActivityAt;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'gk-disposition':\n\t\t\tif (value === 'starred' || value === 'archived') {\n\t\t\t\tmetadata.disposition = value;\n\t\t\t} else {\n\t\t\t\tdelete metadata.disposition;\n\t\t\t}\n\t\t\tbreak;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBA,MAAM,oBAAoB;AAE1B,SAAgB,uBAAuB,KAAqB;CAC3D,OAAO,IAAI,gBAAgB,GAAG,EAAE;AACjC;AAEA,SAAgB,uBAAuB,KAAqE;CAC3G,IAAI,IAAI,QAAQ;EACf,MAAM,QAAQ,wBAAwB,IAAI,IAAI;EAC9C,IAAI,UAAU,IAAI,OAAO,CAAC,IAAI,MAAM,KAAA,CAAS;EAE7C,OAAO,CAAC,IAAI,KAAK,UAAU,QAAQ,CAAC,GAAG,IAAI,KAAK,UAAU,GAAG,KAAK,CAAC;CACpE;CAEA,IAAI,IAAI,UA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AEjB;EACD,KAAK;GACJ,IAAI,SAAS,MACZ,SAAS,iBAAiB;QAE1B,OAAO,SAAS;GAEjB;EACD,KAAK;GACJ,IAAI,SAAS,MACZ,SAAS,sBAAsB;QAE/B,OAAO,SAAS;GAEjB;EACD,KAAK,kBACJ,IAAI,UAAU,aAAa,UAAU,YACpC,SAAS,cAAc;OAEvB,OAAO,SAAS;CAGnB;AACD"}
1
+ {"version":3,"file":"branch.utils.js","names":[],"sources":["../../../../git/src/utils/branch.utils.ts"],"sourcesContent":["import { getRemoteNameSlashIndex } from '@gitlens/utils/gitRefs.js';\nimport type { PageableResult } from '@gitlens/utils/paging.js';\nimport type { BranchMetadata, BranchMetadataGkConfigKey, GitBranch, GitTrackingUpstream } from '../models/branch.js';\nimport type { GitBranchReference, GitReference } from '../models/reference.js';\nimport type { GitReflogEntry } from '../models/reflog.js';\nimport { shortenRevision } from './revision.utils.js';\n\n/**\n * The names git uses where a branch name would go when HEAD isn't on a branch — `(HEAD detached\n * at|from <rev>)`, `(no branch)`, `(no branch, rebasing <name>)`, `(no branch, bisect started on\n * <name>)`, and `git status --porcelain=v2`'s `branch.head` token `(detached)` — plus bare `HEAD`\n * and our own {@link formatDetachedHeadName} output (`(<rev>...)`).\n *\n * Deliberately NOT \"anything parenthesized\": parentheses are legal in ref names, so `(release)`,\n * `v1.0(rc)` and `feat/(wip)` are all real branches a user can be on. Matching those made\n * `GitBranch` rewrite a genuine branch's `name` to the synthesized `(sha…)` label and re-key its\n * `id` by SHA, which corrupts its identity for every downstream consumer.\n */\nconst detachedHEADRegex = /^(?:HEAD|\\(detached\\)|\\(HEAD detached (?:at|from) .+\\)|\\(no branch.*\\)|\\(.+\\.\\.\\.\\))$/;\n\nexport function formatDetachedHeadName(sha: string): string {\n\treturn `(${shortenRevision(sha)}...)`;\n}\n\nexport function getBranchNameAndRemote(ref: GitBranchReference): [name: string, remote: string | undefined] {\n\tif (ref.remote) {\n\t\tconst index = getRemoteNameSlashIndex(ref.name);\n\t\tif (index === -1) return [ref.name, undefined];\n\n\t\treturn [ref.name.substring(index + 1), ref.name.substring(0, index)];\n\t}\n\n\tif (ref.upstream?.local) return [ref.name, undefined];\n\tif (ref.upstream?.remote) return [ref.name, ref.upstream.remote];\n\n\tif (ref.upstream?.name != null) {\n\t\tconst index = getRemoteNameSlashIndex(ref.upstream.name);\n\t\tif (index === -1) return [ref.name, undefined];\n\n\t\treturn [ref.name, ref.upstream.name.substring(0, index)];\n\t}\n\n\treturn [ref.name, undefined];\n}\n\n/**\n * The upstream's branch name on its remote. The name git reports (`branch.<name>.merge`) wins over stripping the local\n * remote-tracking name, which a custom fetch refspec makes differ (`origin` fetching into `refs/remotes/mirror/*`).\n *\n * A remote-tracking branch tracks nothing. The Graph's remote refs carry the remote's own name in `upstream`, which\n * read as a tracking name would fetch a branch named after the remote (`git fetch upstream upstream`)\n */\nexport function getBranchTrackingWithoutRemote(ref: GitBranchReference): string | undefined {\n\tif (ref.remote || ref.upstream == null) return undefined;\n\n\tconst { name, remote, remoteBranch, local } = ref.upstream;\n\tif (local) return name;\n\tif (remoteBranch) return remoteBranch;\n\tif (remote && name.startsWith(`${remote}/`)) return name.substring(remote.length + 1);\n\n\treturn name.substring(getRemoteNameSlashIndex(name) + 1);\n}\n\n/**\n * Splits `name` at the longest of `remoteNames` that prefixes it, so a remote whose own name contains a `/` resolves\n * whole. A leading `remotes/` is stripped only when no remote matches the name as given\n */\nexport function splitRemoteBranchName(\n\tname: string,\n\tremoteNames: Iterable<string>,\n): [remote: string, branch: string] | undefined {\n\tconst names = Array.isArray(remoteNames) ? remoteNames : [...remoteNames];\n\n\tconst split = splitAtLongestRemote(name, names);\n\tif (split != null || !name.startsWith('remotes/')) return split;\n\n\treturn splitAtLongestRemote(name.substring(8), names);\n}\n\nfunction splitAtLongestRemote(\n\tname: string,\n\tremoteNames: Iterable<string>,\n): [remote: string, branch: string] | undefined {\n\tlet match: string | undefined;\n\tfor (const remote of remoteNames) {\n\t\tif (\n\t\t\tname.length > remote.length + 1 &&\n\t\t\tname.charCodeAt(remote.length) === 47 /* '/' */ &&\n\t\t\tname.startsWith(remote) &&\n\t\t\t(match == null || remote.length > match.length)\n\t\t) {\n\t\t\tmatch = remote;\n\t\t}\n\t}\n\n\treturn match != null ? [match, name.substring(match.length + 1)] : undefined;\n}\n\nexport function isDetachedHead(name: string): boolean {\n\t// If there is whitespace in the name assume this is not a valid branch name\n\t// Deals with detached HEAD states\n\tname = name.trim();\n\treturn name.length ? detachedHEADRegex.test(name) : true;\n}\n\nexport function isOfBranchRefType(branch: GitReference | undefined): branch is GitBranchReference {\n\treturn branch?.refType === 'branch';\n}\n\nconst localBranchesPrefixRegex = /^(refs\\/)?heads\\//i;\nconst remoteBranchesPrefixRegex = /^(refs\\/)?remotes\\//i;\nconst remoteHEADRegex = /^(refs\\/)?remotes\\/(.*\\/)HEAD$/i;\n\nexport function isRemoteBranch(refName: string): boolean {\n\treturn remoteBranchesPrefixRegex.test(refName);\n}\n\nexport function isRemoteHEAD(refName: string): boolean {\n\treturn remoteHEADRegex.test(refName);\n}\n\nexport function parseRefName(refName: string): { name: string; remote: boolean } {\n\tconst remote = isRemoteBranch(refName);\n\n\tlet name;\n\tif (remote) {\n\t\t// Strip off refs/remotes/\n\t\tname = refName.replace(remoteBranchesPrefixRegex, '');\n\t} else {\n\t\t// Strip off refs/heads/\n\t\tname = refName.replace(localBranchesPrefixRegex, '');\n\t}\n\n\treturn { name: name, remote: remote };\n}\n\nexport async function getLocalBranchByUpstream(\n\tremoteBranchName: string,\n\tbranches: PageableResult<GitBranch> | ReadonlyMap<unknown, GitBranch>,\n): Promise<GitBranch | undefined> {\n\tlet qualifiedRemoteBranchName;\n\tif (remoteBranchName.startsWith('remotes/')) {\n\t\tqualifiedRemoteBranchName = remoteBranchName;\n\t\tremoteBranchName = remoteBranchName.substring(8);\n\t} else {\n\t\tqualifiedRemoteBranchName = `remotes/${remoteBranchName}`;\n\t}\n\n\tfunction matches(branch: GitBranch): boolean {\n\t\treturn (\n\t\t\t!branch.remote &&\n\t\t\tbranch.upstream?.name != null &&\n\t\t\t(branch.upstream.name === remoteBranchName || branch.upstream.name === qualifiedRemoteBranchName!)\n\t\t);\n\t}\n\n\tconst values = branches.values();\n\tif (Symbol.asyncIterator in values) {\n\t\tfor await (const branch of values) {\n\t\t\tif (matches(branch)) return branch;\n\t\t}\n\t} else {\n\t\tfor (const branch of values) {\n\t\t\tif (matches(branch)) return branch;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nexport async function getLocalBranchUpstreamNames(branches: PageableResult<GitBranch>): Promise<Set<string>> {\n\tconst remoteBranches = new Set<string>();\n\n\tfor await (const branch of branches.values()) {\n\t\tif (!branch.remote && branch.upstream?.name != null) {\n\t\t\tremoteBranches.add(branch.upstream.name);\n\t\t}\n\t}\n\n\treturn remoteBranches;\n}\n\nconst trackingStateRegex = /(?:\\[(?:ahead ([0-9]+))?[,\\s]*(?:behind ([0-9]+))?]|\\[(gone)])/;\n\n/**\n * @param remote - `%(upstream:remotename)`; `.` is a local upstream, and empty means git reported none. A reported\n * remote always wins, even when a custom fetch refspec puts its branches under `refs/heads/`; only when none was\n * reported (git < 2.23) is an upstream under `refs/heads/` taken as local\n * @param remoteRef - `%(upstream:remoteref)`; the upstream's ref on `remote`, read as its branch name\n */\nexport function parseUpstream(\n\tupstream: string,\n\ttracking: string,\n\tremote?: string,\n\tremoteRef?: string,\n): GitTrackingUpstream | undefined {\n\tif (!upstream) return undefined;\n\n\tconst { name } = parseRefName(upstream);\n\tconst local = remote ? remote === '.' : upstream.startsWith('refs/heads/');\n\tconst localProp = local ? { local: true } : undefined;\n\tconst remoteProp =\n\t\tremote && remote !== '.'\n\t\t\t? { remote: remote, ...(remoteRef ? { remoteBranch: remoteRef.replace(/^refs\\/heads\\//, '') } : undefined) }\n\t\t\t: undefined;\n\n\tconst match = trackingStateRegex.exec(tracking);\n\tif (match == null) {\n\t\treturn { name: name, missing: false, state: { ahead: 0, behind: 0 }, ...remoteProp, ...localProp };\n\t}\n\n\tconst ahead = match[1] == null ? 0 : Number(match[1]);\n\tconst behind = match[2] == null ? 0 : Number(match[2]);\n\n\treturn {\n\t\tname: name,\n\t\tmissing: match[3] != null,\n\t\tstate: { ahead: isNaN(ahead) ? 0 : ahead, behind: isNaN(behind) ? 0 : behind },\n\t\t...remoteProp,\n\t\t...localProp,\n\t};\n}\n\nconst branchMetadataGkConfigKeyRegex =\n\t/^branch\\.(.+)\\.(gk-(?:last-accessed|last-modified|agent-last-activity|disposition))$/;\n\n/** Splits a `branch.<name>.<key>` gk config key that a branch's {@link BranchMetadata} is read from, or `undefined` for any other key */\nexport function parseBranchMetadataGkConfigKey(\n\tkey: string,\n): { branch: string; key: BranchMetadataGkConfigKey } | undefined {\n\tconst match = branchMetadataGkConfigKeyRegex.exec(key);\n\tif (match == null) return undefined;\n\n\treturn { branch: match[1], key: match[2] as BranchMetadataGkConfigKey };\n}\n\n/** Sets the field `key` is read into to `value`, or removes it for `undefined`, exactly as a fresh read of the key would */\nexport function setBranchMetadataValue(\n\tmetadata: BranchMetadata,\n\tkey: BranchMetadataGkConfigKey,\n\tvalue: string | undefined,\n): void {\n\tswitch (key) {\n\t\tcase 'gk-last-accessed':\n\t\t\tif (value != null) {\n\t\t\t\tmetadata.lastAccessedAt = value;\n\t\t\t} else {\n\t\t\t\tdelete metadata.lastAccessedAt;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'gk-last-modified':\n\t\t\tif (value != null) {\n\t\t\t\tmetadata.lastModifiedAt = value;\n\t\t\t} else {\n\t\t\t\tdelete metadata.lastModifiedAt;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'gk-agent-last-activity':\n\t\t\tif (value != null) {\n\t\t\t\tmetadata.agentLastActivityAt = value;\n\t\t\t} else {\n\t\t\t\tdelete metadata.agentLastActivityAt;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'gk-disposition':\n\t\t\tif (value === 'starred' || value === 'archived') {\n\t\t\t\tmetadata.disposition = value;\n\t\t\t} else {\n\t\t\t\tdelete metadata.disposition;\n\t\t\t}\n\t\t\tbreak;\n\t}\n}\n\nconst mergeFastForwardRegex = /^merge .+: Fast-forward$/;\nconst pullFastForwardRegex = /^pull\\b.*: Fast-forward$/;\nconst rebaseFinishRegex = /^(?:rebase|pull)\\b.* \\(finish\\): .* onto ([0-9a-f]+)$/;\nconst branchCreatedRegex = /^branch: Created from (.+)$/;\n\n/**\n * Classifies whether a local branch's own reflog shows work authored on it. A branch that is 0 commits ahead\n * of its merge target is either brand new (nothing merged) or had its work fast-forward merged, and only the\n * reflog tells them apart. Exclusion-based: any entry other than a known no-work move (creation, reset, rename,\n * fast-forward, fetch, clone, or a rebase that replayed nothing) counts as work.\n *\n * - `work`: the branch has its own work, so it was genuinely merged\n * - `none`: the branch was created here and never had work, so it's just fresh\n * - `unknown`: can't tell (empty or expired reflog, or created from the same-named remote branch)\n *\n * @param entries the branch's reflog, newest first\n */\nexport function getBranchReflogWork(\n\tentries: readonly GitReflogEntry[],\n\tbranchName: string,\n): 'work' | 'none' | 'unknown' {\n\tlet createdFrom: string | undefined;\n\n\tfor (const entry of entries) {\n\t\tconst { message } = entry;\n\n\t\tconst created = branchCreatedRegex.exec(message);\n\t\tif (created != null) {\n\t\t\tcreatedFrom = created[1];\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (\n\t\t\tmessage.startsWith('branch: Reset to ') ||\n\t\t\tmessage.startsWith('Branch: renamed ') ||\n\t\t\tmessage.startsWith('reset: moving to ') ||\n\t\t\tmergeFastForwardRegex.test(message) ||\n\t\t\tpullFastForwardRegex.test(message) ||\n\t\t\tmessage.startsWith('fetch') ||\n\t\t\tmessage.startsWith('clone: ')\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// A rebase that finishes onto the entry's own sha replayed nothing\n\t\tconst finished = rebaseFinishRegex.exec(message);\n\t\tif (finished != null && finished[1] === entry.sha) continue;\n\n\t\treturn 'work';\n\t}\n\n\tif (createdFrom == null) return 'unknown';\n\n\t// Strip an optional `refs/remotes/`, then see if what's left is `<remote>/<branchName>` (remote has no `/`)\n\tconst source = createdFrom.startsWith('refs/remotes/')\n\t\t? createdFrom.substring('refs/remotes/'.length)\n\t\t: createdFrom;\n\tconst slash = source.indexOf('/');\n\tif (slash > 0 && source.substring(slash + 1) === branchName) return 'unknown';\n\n\treturn 'none';\n}\n"],"mappings":";;;;;;;;;;;;;;AAkBA,MAAM,oBAAoB;AAE1B,SAAgB,uBAAuB,KAAqB;CAC3D,OAAO,IAAI,gBAAgB,GAAG,EAAE;AACjC;AAEA,SAAgB,uBAAuB,KAAqE;CAC3G,IAAI,IAAI,QAAQ;EACf,MAAM,QAAQ,wBAAwB,IAAI,IAAI;EAC9C,IAAI,UAAU,IAAI,OAAO,CAAC,IAAI,MAAM,KAAA,CAAS;EAE7C,OAAO,CAAC,IAAI,KAAK,UAAU,QAAQ,CAAC,GAAG,IAAI,KAAK,UAAU,GAAG,KAAK,CAAC;CACpE;CAEA,IAAI,IAAI,UAAU,OAAO,OAAO,CAAC,IAAI,MAAM,KAAA,CAAS;CACpD,IAAI,IAAI,UAAU,QAAQ,OAAO,CAAC,IAAI,MAAM,IAAI,SAAS,MAAM;CAE/D,IAAI,IAAI,UAAU,QAAQ,MAAM;EAC/B,MAAM,QAAQ,wBAAwB,IAAI,SAAS,IAAI;EACvD,IAAI,UAAU,IAAI,OAAO,CAAC,IAAI,MAAM,KAAA,CAAS;EAE7C,OAAO,CAAC,IAAI,MAAM,IAAI,SAAS,KAAK,UAAU,GAAG,KAAK,CAAC;CACxD;CAEA,OAAO,CAAC,IAAI,MAAM,KAAA,CAAS;AAC5B;;;;;;;;AASA,SAAgB,+BAA+B,KAA6C;CAC3F,IAAI,IAAI,UAAU,IAAI,YAAY,MAAM,OAAO,KAAA;CAE/C,MAAM,EAAE,MAAM,QAAQ,cAAc,UAAU,IAAI;CAClD,IAAI,OAAO,OAAO;CAClB,IAAI,cAAc,OAAO;CACzB,IAAI,UAAU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AAkB,KACrC,QAAQ,WAAW,mBAAmB,KACtC,sBAAsB,KAAK,OAAO,KAClC,qBAAqB,KAAK,OAAO,KACjC,QAAQ,WAAW,OAAO,KAC1B,QAAQ,WAAW,SAAS,GAE5B;EAID,MAAM,WAAW,kBAAkB,KAAK,OAAO;EAC/C,IAAI,YAAY,QAAQ,SAAS,OAAO,MAAM,KAAK;EAEnD,OAAO;CACR;CAEA,IAAI,eAAe,MAAM,OAAO;CAGhC,MAAM,SAAS,YAAY,WAAW,eAAe,IAClD,YAAY,UAAU,EAAsB,IAC5C;CACH,MAAM,QAAQ,OAAO,QAAQ,GAAG;CAChC,IAAI,QAAQ,KAAK,OAAO,UAAU,QAAQ,CAAC,MAAM,YAAY,OAAO;CAEpE,OAAO;AACR"}
@@ -0,0 +1,43 @@
1
+ import { PullRequestShape } from "../models/pullRequest.js";
2
+ //#region ../git/src/utils/branchLanded.utils.d.ts
3
+ export interface BranchLandedPullRequestCandidate {
4
+ readonly pullRequest: Pick<PullRequestShape, 'id' | 'url' | 'title' | 'state' | 'refs'>;
5
+ /**
6
+ * Commits on the branch that are in neither this pull request's head nor the merge target, when known. Only read
7
+ * for a merged pull request whose head isn't the tip; leaving it `undefined` leaves that pull request undecided.
8
+ */
9
+ readonly newCommits?: number;
10
+ }
11
+ export interface BranchLandedState {
12
+ /** An open pull request's head is the tip, so the branch is live and nothing landed, whatever git evidence says */
13
+ live?: true;
14
+ landed?: {
15
+ via: 'pr';
16
+ confidence: 'highest';
17
+ /** `id` is the pull request's display number where its url names one */
18
+ pullRequest: {
19
+ id: string;
20
+ url: string;
21
+ title?: string;
22
+ };
23
+ };
24
+ /** The pull request merged, but the branch has commits it didn't carry — so the branch itself hasn't landed */
25
+ successor?: {
26
+ pullRequest: {
27
+ id: string;
28
+ url: string;
29
+ };
30
+ newCommits: number;
31
+ };
32
+ }
33
+ /**
34
+ * What a branch's pull requests say about whether its work landed. The head sha decides, never recency:
35
+ * - an open pull request whose head is the tip is live (`live`), so nothing landed
36
+ * - a merged pull request whose head is the tip landed
37
+ * - else the merged pull request with the fewest new commits (the first on a tie): none → landed, some → successor
38
+ *
39
+ * A pull request without a head sha (some non-GitHub hosts) never decides, so git evidence can.
40
+ */
41
+ export declare function getBranchLandedState(tipSha: string | undefined, candidates: readonly BranchLandedPullRequestCandidate[]): BranchLandedState;
42
+ //#endregion
43
+ //# sourceMappingURL=branchLanded.utils.d.ts.map
@@ -0,0 +1,56 @@
1
+ import { getPullRequestNumberFromUrl } from "./pullRequest.utils.js";
2
+ //#region ../git/src/utils/branchLanded.utils.ts
3
+ /**
4
+ * What a branch's pull requests say about whether its work landed. The head sha decides, never recency:
5
+ * - an open pull request whose head is the tip is live (`live`), so nothing landed
6
+ * - a merged pull request whose head is the tip landed
7
+ * - else the merged pull request with the fewest new commits (the first on a tie): none → landed, some → successor
8
+ *
9
+ * A pull request without a head sha (some non-GitHub hosts) never decides, so git evidence can.
10
+ */
11
+ function getBranchLandedState(tipSha, candidates) {
12
+ if (!tipSha) return {};
13
+ let atTip;
14
+ let best;
15
+ for (const candidate of candidates) {
16
+ const { state, refs } = candidate.pullRequest;
17
+ const headSha = refs?.head?.sha;
18
+ if (!headSha) continue;
19
+ if (headSha === tipSha) {
20
+ if (state === "opened") return { live: true };
21
+ if (state === "merged") atTip ??= candidate;
22
+ continue;
23
+ }
24
+ if (state !== "merged" || candidate.newCommits == null) continue;
25
+ if (best?.newCommits == null || candidate.newCommits < best.newCommits) best = candidate;
26
+ }
27
+ if (atTip != null) return { landed: toLanded(atTip.pullRequest) };
28
+ if (best?.newCommits == null) return {};
29
+ if (best.newCommits === 0) return { landed: toLanded(best.pullRequest) };
30
+ const { id, url } = toLandedPullRequest(best.pullRequest);
31
+ return { successor: {
32
+ pullRequest: {
33
+ id,
34
+ url
35
+ },
36
+ newCommits: best.newCommits
37
+ } };
38
+ }
39
+ function toLanded(pr) {
40
+ return {
41
+ via: "pr",
42
+ confidence: "highest",
43
+ pullRequest: toLandedPullRequest(pr)
44
+ };
45
+ }
46
+ function toLandedPullRequest(pr) {
47
+ return {
48
+ id: getPullRequestNumberFromUrl(pr.url) ?? pr.id,
49
+ url: pr.url,
50
+ title: pr.title
51
+ };
52
+ }
53
+ //#endregion
54
+ export { getBranchLandedState };
55
+
56
+ //# sourceMappingURL=branchLanded.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"branchLanded.utils.js","names":[],"sources":["../../../../git/src/utils/branchLanded.utils.ts"],"sourcesContent":["import type { PullRequestShape } from '../models/pullRequest.js';\nimport { getPullRequestNumberFromUrl } from './pullRequest.utils.js';\n\nexport interface BranchLandedPullRequestCandidate {\n\treadonly pullRequest: Pick<PullRequestShape, 'id' | 'url' | 'title' | 'state' | 'refs'>;\n\t/**\n\t * Commits on the branch that are in neither this pull request's head nor the merge target, when known. Only read\n\t * for a merged pull request whose head isn't the tip; leaving it `undefined` leaves that pull request undecided.\n\t */\n\treadonly newCommits?: number;\n}\n\nexport interface BranchLandedState {\n\t/** An open pull request's head is the tip, so the branch is live and nothing landed, whatever git evidence says */\n\tlive?: true;\n\tlanded?: {\n\t\tvia: 'pr';\n\t\tconfidence: 'highest';\n\t\t/** `id` is the pull request's display number where its url names one */\n\t\tpullRequest: { id: string; url: string; title?: string };\n\t};\n\t/** The pull request merged, but the branch has commits it didn't carry — so the branch itself hasn't landed */\n\tsuccessor?: { pullRequest: { id: string; url: string }; newCommits: number };\n}\n\n/**\n * What a branch's pull requests say about whether its work landed. The head sha decides, never recency:\n * - an open pull request whose head is the tip is live (`live`), so nothing landed\n * - a merged pull request whose head is the tip landed\n * - else the merged pull request with the fewest new commits (the first on a tie): none → landed, some → successor\n *\n * A pull request without a head sha (some non-GitHub hosts) never decides, so git evidence can.\n */\nexport function getBranchLandedState(\n\ttipSha: string | undefined,\n\tcandidates: readonly BranchLandedPullRequestCandidate[],\n): BranchLandedState {\n\tif (!tipSha) return {};\n\n\tlet atTip: BranchLandedPullRequestCandidate | undefined;\n\tlet best: BranchLandedPullRequestCandidate | undefined;\n\tfor (const candidate of candidates) {\n\t\tconst { state, refs } = candidate.pullRequest;\n\t\tconst headSha = refs?.head?.sha;\n\t\tif (!headSha) continue;\n\n\t\tif (headSha === tipSha) {\n\t\t\tif (state === 'opened') return { live: true };\n\n\t\t\tif (state === 'merged') {\n\t\t\t\tatTip ??= candidate;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (state !== 'merged' || candidate.newCommits == null) continue;\n\n\t\tif (best?.newCommits == null || candidate.newCommits < best.newCommits) {\n\t\t\tbest = candidate;\n\t\t}\n\t}\n\n\tif (atTip != null) return { landed: toLanded(atTip.pullRequest) };\n\tif (best?.newCommits == null) return {};\n\tif (best.newCommits === 0) return { landed: toLanded(best.pullRequest) };\n\n\tconst { id, url } = toLandedPullRequest(best.pullRequest);\n\treturn {\n\t\tsuccessor: {\n\t\t\tpullRequest: { id: id, url: url },\n\t\t\tnewCommits: best.newCommits,\n\t\t},\n\t};\n}\n\nfunction toLanded(pr: BranchLandedPullRequestCandidate['pullRequest']): NonNullable<BranchLandedState['landed']> {\n\treturn {\n\t\tvia: 'pr',\n\t\tconfidence: 'highest',\n\t\tpullRequest: toLandedPullRequest(pr),\n\t};\n}\n\nfunction toLandedPullRequest(pr: BranchLandedPullRequestCandidate['pullRequest']): {\n\tid: string;\n\turl: string;\n\ttitle?: string;\n} {\n\treturn {\n\t\tid: getPullRequestNumberFromUrl(pr.url) ?? pr.id,\n\t\turl: pr.url,\n\t\ttitle: pr.title,\n\t};\n}\n"],"mappings":";;;;;;;;;;AAiCA,SAAgB,qBACf,QACA,YACoB;CACpB,IAAI,CAAC,QAAQ,OAAO,CAAC;CAErB,IAAI;CACJ,IAAI;CACJ,KAAK,MAAM,aAAa,YAAY;EACnC,MAAM,EAAE,OAAO,SAAS,UAAU;EAClC,MAAM,UAAU,MAAM,MAAM;EAC5B,IAAI,CAAC,SAAS;EAEd,IAAI,YAAY,QAAQ;GACvB,IAAI,UAAU,UAAU,OAAO,EAAE,MAAM,KAAK;GAE5C,IAAI,UAAU,UACb,UAAU;GAEX;EACD;EAEA,IAAI,UAAU,YAAY,UAAU,cAAc,MAAM;EAExD,IAAI,MAAM,cAAc,QAAQ,UAAU,aAAa,KAAK,YAC3D,OAAO;CAET;CAEA,IAAI,SAAS,MAAM,OAAO,EAAE,QAAQ,SAAS,MAAM,WAAW,EAAE;CAChE,IAAI,MAAM,cAAc,MAAM,OAAO,CAAC;CACtC,IAAI,KAAK,eAAe,GAAG,OAAO,EAAE,QAAQ,SAAS,KAAK,WAAW,EAAE;CAEvE,MAAM,EAAE,IAAI,QAAQ,oBAAoB,KAAK,WAAW;CACxD,OAAO,EACN,WAAW;EACV,aAAa;GAAM;GAAS;EAAI;EAChC,YAAY,KAAK;CAClB,EACD;AACD;AAEA,SAAS,SAAS,IAA+F;CAChH,OAAO;EACN,KAAK;EACL,YAAY;EACZ,aAAa,oBAAoB,EAAE;CACpC;AACD;AAEA,SAAS,oBAAoB,IAI3B;CACD,OAAO;EACN,IAAI,4BAA4B,GAAG,GAAG,KAAK,GAAG;EAC9C,KAAK,GAAG;EACR,OAAO,GAAG;CACX;AACD"}
@@ -867,8 +867,8 @@ var Git = class {
867
867
  quiet: errorHandling === "ignore",
868
868
  spawn: this.options.spawn
869
869
  };
870
- const unshared = options?.stdin != null || options?.env != null && Object.keys(options.env).length > 0 || beforeIndexLockRetry != null;
871
- const cacheKey = `${correlationKey !== void 0 ? `${correlationKey}:` : ""}${unshared ? `${unsharedRunCounter.next()}:` : ""}${cancellation != null ? `${getAbortSignalId(cancellation)}:` : ""}${gitCommand}`;
870
+ const unshared = options?.stdin != null || options?.env != null && Object.keys(options.env).length > 0 || beforeIndexLockRetry != null || encoding === "buffer";
871
+ const cacheKey = `${correlationKey !== void 0 ? `${correlationKey}:` : ""}${unshared ? `${unsharedRunCounter.next()}:` : ""}${encoding != null && encoding !== "utf8" ? `${encoding}:` : ""}${cancellation != null ? `${getAbortSignalId(cancellation)}:` : ""}${gitCommand}`;
872
872
  let execStart;
873
873
  let hookFailure;
874
874
  let waiting;