@statewalker/vcs-commands 0.1.1 → 0.3.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 (85) hide show
  1. package/dist/commands/commit-command.d.ts.map +1 -1
  2. package/dist/commands/init-command.d.ts.map +1 -1
  3. package/dist/commands/push-command.d.ts.map +1 -1
  4. package/dist/core-commands/checkout.command.impl.d.ts +1 -1
  5. package/dist/core-commands/checkout.command.impl.d.ts.map +1 -1
  6. package/dist/git-command.d.ts.map +1 -1
  7. package/package.json +19 -14
  8. package/src/commands/add-command.ts +494 -0
  9. package/src/commands/blame-command.ts +1241 -0
  10. package/src/commands/branch-command.ts +487 -0
  11. package/src/commands/checkout-command.ts +681 -0
  12. package/src/commands/cherry-pick-command.ts +544 -0
  13. package/src/commands/clean-command.ts +218 -0
  14. package/src/commands/clone-command.ts +532 -0
  15. package/src/commands/commit-command.ts +529 -0
  16. package/src/commands/describe-command.ts +454 -0
  17. package/src/commands/diff-command.ts +257 -0
  18. package/src/commands/fetch-command.ts +615 -0
  19. package/src/commands/gc-command.ts +155 -0
  20. package/src/commands/index.ts +31 -0
  21. package/src/commands/init-command.ts +365 -0
  22. package/src/commands/log-command.ts +549 -0
  23. package/src/commands/ls-remote-command.ts +237 -0
  24. package/src/commands/merge-command.ts +750 -0
  25. package/src/commands/pack-refs-command.ts +101 -0
  26. package/src/commands/pull-command.ts +258 -0
  27. package/src/commands/push-command.ts +682 -0
  28. package/src/commands/rebase-command.ts +665 -0
  29. package/src/commands/reflog-command.ts +68 -0
  30. package/src/commands/remote-command.ts +385 -0
  31. package/src/commands/reset-command.ts +292 -0
  32. package/src/commands/revert-command.ts +552 -0
  33. package/src/commands/rm-command.ts +178 -0
  34. package/src/commands/stash-apply-command.ts +402 -0
  35. package/src/commands/stash-create-command.ts +339 -0
  36. package/src/commands/stash-drop-command.ts +115 -0
  37. package/src/commands/stash-list-command.ts +116 -0
  38. package/src/commands/status-command.ts +173 -0
  39. package/src/commands/tag-command.ts +378 -0
  40. package/src/commands/tree-restore.ts +126 -0
  41. package/src/core-commands/add.command.impl.ts +274 -0
  42. package/src/core-commands/add.command.ts +81 -0
  43. package/src/core-commands/checkout.command.impl.ts +586 -0
  44. package/src/core-commands/checkout.command.ts +125 -0
  45. package/src/core-commands/index.ts +13 -0
  46. package/src/errors/add-errors.ts +20 -0
  47. package/src/errors/checkout-errors.ts +42 -0
  48. package/src/errors/command-errors.ts +68 -0
  49. package/src/errors/commit-errors.ts +40 -0
  50. package/src/errors/git-api-error.ts +11 -0
  51. package/src/errors/index.ts +12 -0
  52. package/src/errors/merge-errors.ts +94 -0
  53. package/src/errors/rebase-errors.ts +34 -0
  54. package/src/errors/ref-errors.ts +100 -0
  55. package/src/errors/remote-errors.ts +27 -0
  56. package/src/errors/stash-errors.ts +42 -0
  57. package/src/errors/tag-errors.ts +16 -0
  58. package/src/errors/transport-errors.ts +68 -0
  59. package/src/git-command.ts +421 -0
  60. package/src/git.ts +910 -0
  61. package/src/index.ts +18 -0
  62. package/src/pack-import/index.ts +8 -0
  63. package/src/pack-import/pack-import.ts +24 -0
  64. package/src/remote-config/index.ts +12 -0
  65. package/src/remote-config/remote-config-store.ts +285 -0
  66. package/src/rename/index.ts +5 -0
  67. package/src/rename/similarity-index.ts +185 -0
  68. package/src/results/cherry-pick-result.ts +35 -0
  69. package/src/results/clone-result.ts +25 -0
  70. package/src/results/diff-entry.ts +162 -0
  71. package/src/results/diff-formatter.ts +416 -0
  72. package/src/results/fetch-result.ts +91 -0
  73. package/src/results/index.ts +13 -0
  74. package/src/results/init-result.ts +29 -0
  75. package/src/results/merge-result.ts +135 -0
  76. package/src/results/pull-result.ts +27 -0
  77. package/src/results/push-result.ts +86 -0
  78. package/src/results/rebase-result.ts +140 -0
  79. package/src/results/revert-result.ts +35 -0
  80. package/src/results/stash-result.ts +60 -0
  81. package/src/results/status-result.ts +65 -0
  82. package/src/transport-command.ts +125 -0
  83. package/src/tree-merge/index.ts +8 -0
  84. package/src/tree-merge/tree-merge.ts +249 -0
  85. package/src/types.ts +70 -0
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ // Main entry point
2
+
3
+ // Fluent API commands
4
+ export * from "./commands/index.js";
5
+
6
+ // Note: Core command implementations (Add, Checkout interfaces and their impl classes)
7
+ // are available via direct import from "./core-commands/" to avoid naming conflicts
8
+ // with the fluent API. Example: import { AddCommand } from "@statewalker/vcs-commands/core-commands";
9
+ // Errors
10
+ export * from "./errors/index.js";
11
+ export { Git } from "./git.js";
12
+ // Base classes
13
+ export { GitCommand } from "./git-command.js";
14
+ // Results
15
+ export * from "./results/index.js";
16
+ export { TransportCommand } from "./transport-command.js";
17
+ // Types
18
+ export * from "./types.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Pack-import plumbing shared by the commands that receive packs
3
+ * (`clone`, `fetch`).
4
+ *
5
+ * Internal: not re-exported from `src/index.ts`.
6
+ */
7
+
8
+ export { importPackIntoHistory } from "./pack-import.js";
@@ -0,0 +1,24 @@
1
+ import type { History, HistoryWithOperations } from "@statewalker/vcs-core";
2
+ // Import from the package root only: vcs-core ships a single runtime file
3
+ // (dist/index.js); its subpaths resolve for types but not at runtime.
4
+ import { DefaultSerializationApi } from "@statewalker/vcs-core";
5
+
6
+ /**
7
+ * Unpack pack data into a history's object stores.
8
+ *
9
+ * Uses the history's own {@link SerializationApi} when it exposes one
10
+ * (a `HistoryWithOperations`), otherwise builds a default one over its
11
+ * object stores — `WorkingCopy.history` is typed as a plain `History`,
12
+ * so `serialization` is not statically available.
13
+ */
14
+ export async function importPackIntoHistory(history: History, packData: Uint8Array): Promise<void> {
15
+ const serialization =
16
+ (history as Partial<HistoryWithOperations>).serialization ??
17
+ new DefaultSerializationApi({ history });
18
+
19
+ const packStream = (async function* () {
20
+ yield packData;
21
+ })();
22
+
23
+ await serialization.importPack(packStream);
24
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Remote configuration plumbing shared by the remote-facing commands.
3
+ *
4
+ * Internal: not re-exported from `src/index.ts`.
5
+ */
6
+
7
+ export {
8
+ defaultFetchRefspec,
9
+ listRemoteNames,
10
+ type RemoteConfig,
11
+ RemoteConfigStore,
12
+ } from "./remote-config-store.js";
@@ -0,0 +1,285 @@
1
+ /**
2
+ * Reading and writing the `[remote "<name>"]` sections of a working copy's
3
+ * configuration.
4
+ *
5
+ * Internal to the package: the remote/fetch/push/ls-remote commands share it,
6
+ * the public API does not expose it. Only {@link RemoteConfig} is public, and
7
+ * it is re-exported from `commands/remote-command.ts`.
8
+ */
9
+
10
+ import type { WorkingCopy, WorkingCopyConfig } from "@statewalker/vcs-working-tree";
11
+
12
+ import { InvalidArgumentError } from "../errors/index.js";
13
+
14
+ /**
15
+ * Remote configuration entry.
16
+ *
17
+ * Based on JGit's RemoteConfig.
18
+ */
19
+ export interface RemoteConfig {
20
+ /** Remote name */
21
+ name: string;
22
+ /** Fetch URLs */
23
+ urls: string[];
24
+ /** Push URLs (defaults to fetch URLs if not set) */
25
+ pushUrls: string[];
26
+ /** Fetch refspecs */
27
+ fetchRefspecs: string[];
28
+ /** Push refspecs */
29
+ pushRefspecs: string[];
30
+ }
31
+
32
+ /** The default fetch refspec `git remote add` writes for a remote. */
33
+ export function defaultFetchRefspec(name: string): string {
34
+ return `+refs/heads/*:refs/remotes/${name}/*`;
35
+ }
36
+
37
+ /* ------------------------------------------------------- config plumbing */
38
+
39
+ /**
40
+ * The git-config surface {@link RemoteConfigStore} needs.
41
+ *
42
+ * `WorkingCopy.config` is typed as a bare index-signature bag, so a working
43
+ * copy may hand us either a real git config object (`GitWorkingCopyConfig` in
44
+ * `@statewalker/vcs-store-files`, which reads and writes `.git/config`) or a
45
+ * plain object. This is the shape of the former; {@link PlainObjectConfig}
46
+ * gives the latter the same shape, so the commands never branch.
47
+ */
48
+ interface GitConfigLike {
49
+ get(key: string): unknown;
50
+ getAll(key: string): unknown[];
51
+ set(key: string, value: unknown): void;
52
+ add(key: string, value: unknown): void;
53
+ unset(key: string): void;
54
+ unsetSection(section: string): void;
55
+ subsections(section: string): string[];
56
+ /** Optional: a config with no backing file has nothing to save. */
57
+ save?(): Promise<void>;
58
+ }
59
+
60
+ const GIT_CONFIG_METHODS = [
61
+ "get",
62
+ "getAll",
63
+ "set",
64
+ "add",
65
+ "unset",
66
+ "unsetSection",
67
+ "subsections",
68
+ ] as const;
69
+
70
+ function isGitConfigLike(
71
+ config: WorkingCopyConfig | undefined,
72
+ ): config is WorkingCopyConfig & GitConfigLike {
73
+ if (!config) return false;
74
+ return GIT_CONFIG_METHODS.every((method) => typeof config[method] === "function");
75
+ }
76
+
77
+ /**
78
+ * Split `remote.<subsection>.<name>` into its subsection.
79
+ *
80
+ * Follows git's key grammar (and `GitWorkingCopyConfig`'s): the first part is
81
+ * the section, the last is the variable name and everything in between is the
82
+ * subsection, which keeps its case and may itself contain dots.
83
+ *
84
+ * @returns undefined when the key is not a `remote` subsection key
85
+ */
86
+ function remoteSubsectionOf(key: string): string | undefined {
87
+ const parts = key.split(".");
88
+ if (parts.length < 3 || parts[0].toLowerCase() !== "remote") return undefined;
89
+ return parts.slice(1, -1).join(".");
90
+ }
91
+
92
+ /**
93
+ * {@link GitConfigLike} over a plain `{[key: string]: unknown}` bag.
94
+ *
95
+ * Keys are stored in canonical dotted form (`remote.origin.url`) — the same
96
+ * form `GitWorkingCopyConfig` mirrors as own properties — so the two
97
+ * representations read alike. A repeated key holds an array.
98
+ *
99
+ * There is no `save()`: this config lives and dies with the working copy
100
+ * instance, which is exactly what a working copy without a config file has.
101
+ */
102
+ class PlainObjectConfig implements GitConfigLike {
103
+ constructor(private readonly bag: Record<string, unknown>) {}
104
+
105
+ get(key: string): unknown {
106
+ const values = this.getAll(key);
107
+ return values.length > 0 ? values[values.length - 1] : undefined;
108
+ }
109
+
110
+ getAll(key: string): unknown[] {
111
+ const value = this.bag[key];
112
+ if (value === undefined) return [];
113
+ return Array.isArray(value) ? [...value] : [value];
114
+ }
115
+
116
+ set(key: string, value: unknown): void {
117
+ this.bag[key] = value;
118
+ }
119
+
120
+ add(key: string, value: unknown): void {
121
+ const existing = this.getAll(key);
122
+ this.bag[key] = existing.length > 0 ? [...existing, value] : value;
123
+ }
124
+
125
+ unset(key: string): void {
126
+ delete this.bag[key];
127
+ }
128
+
129
+ unsetSection(section: string): void {
130
+ const parts = section.split(".");
131
+ if (parts.length < 2 || parts[0].toLowerCase() !== "remote") return;
132
+ const subsection = parts.slice(1).join(".");
133
+ for (const key of Object.keys(this.bag)) {
134
+ if (remoteSubsectionOf(key) === subsection) delete this.bag[key];
135
+ }
136
+ }
137
+
138
+ subsections(section: string): string[] {
139
+ if (section.toLowerCase() !== "remote") return [];
140
+ const found = new Set<string>();
141
+ for (const key of Object.keys(this.bag)) {
142
+ if (this.getAll(key).length === 0) continue;
143
+ const subsection = remoteSubsectionOf(key);
144
+ if (subsection !== undefined) found.add(subsection);
145
+ }
146
+ return [...found];
147
+ }
148
+ }
149
+
150
+ /**
151
+ * The `[remote "<name>"]` sections of a working copy's configuration.
152
+ *
153
+ * Reading a remote is a **union** of two sources, and stays that way: the
154
+ * config sections, plus every name that appears under `refs/remotes/`. A
155
+ * remote that was fetched into tracking refs without ever being configured is
156
+ * a real remote to `git remote`, and so it is here — it simply has no URL.
157
+ */
158
+ export class RemoteConfigStore {
159
+ private constructor(private readonly config: GitConfigLike) {}
160
+
161
+ /**
162
+ * Wrap a working copy's configuration.
163
+ *
164
+ * A config that implements the git-config methods is used directly, so
165
+ * changes reach its backing file; anything else is driven as a plain bag.
166
+ */
167
+ static from(workingCopy: WorkingCopy): RemoteConfigStore {
168
+ const config = workingCopy.config;
169
+ if (isGitConfigLike(config)) return new RemoteConfigStore(config);
170
+ return new RemoteConfigStore(new PlainObjectConfig((config ?? {}) as Record<string, unknown>));
171
+ }
172
+
173
+ /** Remote names that have a config section. */
174
+ configuredNames(): string[] {
175
+ return this.config.subsections("remote");
176
+ }
177
+
178
+ /** Whether the remote has a config section. */
179
+ isConfigured(name: string): boolean {
180
+ return this.configuredNames().includes(name);
181
+ }
182
+
183
+ /**
184
+ * Read a remote, filling in the default fetch refspec when none is
185
+ * configured, exactly as `git remote` reports one.
186
+ */
187
+ read(name: string): RemoteConfig {
188
+ const fetchRefspecs = this.strings(name, "fetch");
189
+ return {
190
+ name,
191
+ urls: this.strings(name, "url"),
192
+ pushUrls: this.strings(name, "pushurl"),
193
+ fetchRefspecs: fetchRefspecs.length > 0 ? fetchRefspecs : [defaultFetchRefspec(name)],
194
+ pushRefspecs: this.strings(name, "push"),
195
+ };
196
+ }
197
+
198
+ /** Write every field of a remote, replacing whatever was there. */
199
+ write(remote: RemoteConfig): void {
200
+ this.setAll(remote.name, "url", remote.urls);
201
+ this.setAll(remote.name, "fetch", remote.fetchRefspecs);
202
+ this.setAll(remote.name, "pushurl", remote.pushUrls);
203
+ this.setAll(remote.name, "push", remote.pushRefspecs);
204
+ }
205
+
206
+ /** Drop the whole `[remote "<name>"]` section. */
207
+ remove(name: string): void {
208
+ this.config.unsetSection(`remote.${name}`);
209
+ }
210
+
211
+ /**
212
+ * Point a remote at a URL.
213
+ *
214
+ * @param push Write `pushurl` instead of `url`
215
+ * @param oldUrl Replace only this URL, as `git remote set-url <name> <new> <old>` does
216
+ * @throws InvalidArgumentError if `oldUrl` is not among the configured URLs
217
+ */
218
+ setUrl(name: string, url: string, options: { push?: boolean; oldUrl?: string } = {}): void {
219
+ const variable = options.push ? "pushurl" : "url";
220
+ if (options.oldUrl === undefined) {
221
+ this.setAll(name, variable, [url]);
222
+ return;
223
+ }
224
+ const existing = this.strings(name, variable);
225
+ if (!existing.includes(options.oldUrl)) {
226
+ throw new InvalidArgumentError("oldUri", `No such URL found: ${options.oldUrl}`);
227
+ }
228
+ this.setAll(
229
+ name,
230
+ variable,
231
+ existing.map((value) => (value === options.oldUrl ? url : value)),
232
+ );
233
+ }
234
+
235
+ /**
236
+ * The URL to talk to a remote over, or undefined when it has none.
237
+ *
238
+ * @param push Prefer `pushurl`, falling back to `url`, as git does
239
+ */
240
+ urlFor(name: string, options: { push?: boolean } = {}): string | undefined {
241
+ if (options.push) {
242
+ const pushUrl = this.strings(name, "pushurl")[0];
243
+ if (pushUrl !== undefined) return pushUrl;
244
+ }
245
+ return this.strings(name, "url")[0];
246
+ }
247
+
248
+ /** Flush to the backing file, if the config has one. */
249
+ async save(): Promise<void> {
250
+ await this.config.save?.();
251
+ }
252
+
253
+ private strings(name: string, variable: string): string[] {
254
+ return this.config
255
+ .getAll(`remote.${name}.${variable}`)
256
+ .filter((value) => value !== undefined && value !== null)
257
+ .map((value) => String(value));
258
+ }
259
+
260
+ private setAll(name: string, variable: string, values: string[]): void {
261
+ const key = `remote.${name}.${variable}`;
262
+ if (values.length === 0) {
263
+ this.config.unset(key);
264
+ return;
265
+ }
266
+ this.config.set(key, values[0]);
267
+ for (const value of values.slice(1)) this.config.add(key, value);
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Every remote name known to the repository: config sections ∪ the names
273
+ * appearing under `refs/remotes/`.
274
+ */
275
+ export async function listRemoteNames(
276
+ store: RemoteConfigStore,
277
+ refs: { list(prefix: string): AsyncIterable<{ name: string }> },
278
+ ): Promise<string[]> {
279
+ const names = new Set<string>(store.configuredNames());
280
+ for await (const ref of refs.list("refs/remotes/")) {
281
+ const parts = ref.name.split("/");
282
+ if (parts.length >= 3) names.add(parts[2]);
283
+ }
284
+ return [...names];
285
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Rename detection utilities for Git commands.
3
+ */
4
+
5
+ export { DEFAULT_RENAME_SCORE, MAX_SCORE, SimilarityIndex } from "./similarity-index.js";
@@ -0,0 +1,185 @@
1
+ /**
2
+ * SimilarityIndex - computes content similarity between files
3
+ *
4
+ * Based on JGit's SimilarityIndex.java
5
+ *
6
+ * Hashes lines/blocks of content to create a fingerprint that can be
7
+ * efficiently compared with other files. Used for rename detection.
8
+ */
9
+
10
+ import { RawText } from "@statewalker/vcs-utils";
11
+
12
+ /**
13
+ * Maximum score (100% match)
14
+ */
15
+ export const MAX_SCORE = 100;
16
+
17
+ /**
18
+ * Default rename threshold (50% similarity)
19
+ */
20
+ export const DEFAULT_RENAME_SCORE = 50;
21
+
22
+ /**
23
+ * Entry in the hash table: key and count stored separately to avoid
24
+ * JavaScript floating-point precision issues.
25
+ */
26
+ interface HashEntry {
27
+ key: number;
28
+ count: number;
29
+ }
30
+
31
+ /**
32
+ * Index structure for computing content similarity.
33
+ *
34
+ * Hash-based approach: each line/block is hashed and counts are maintained.
35
+ * Similarity is computed by finding common hashes between two files.
36
+ */
37
+ export class SimilarityIndex {
38
+ /** Total bytes hashed */
39
+ private hashedCnt = 0;
40
+
41
+ /** Hash table entries, sorted by key for efficient comparison */
42
+ private entries: HashEntry[] = [];
43
+
44
+ /** Lookup map during hashing (key -> index in entries) */
45
+ private hashMap = new Map<number, number>();
46
+
47
+ /**
48
+ * Create a SimilarityIndex from content bytes.
49
+ */
50
+ static create(content: Uint8Array): SimilarityIndex {
51
+ const idx = new SimilarityIndex();
52
+ idx.hash(content);
53
+ idx.sort();
54
+ return idx;
55
+ }
56
+
57
+ /**
58
+ * Check if content is binary (contains NUL bytes in first 8000 bytes)
59
+ */
60
+ static isBinary(content: Uint8Array): boolean {
61
+ return RawText.isBinary(content);
62
+ }
63
+
64
+ /**
65
+ * Hash the content.
66
+ */
67
+ hash(content: Uint8Array): void {
68
+ const text = !SimilarityIndex.isBinary(content);
69
+ this.hashedCnt = 0;
70
+ this.entries = [];
71
+ this.hashMap.clear();
72
+
73
+ let ptr = 0;
74
+ const end = content.length;
75
+
76
+ while (ptr < end) {
77
+ let hash = 5381;
78
+ let blockHashedCnt = 0;
79
+ const start = ptr;
80
+
81
+ // Hash one line, or one block (64 bytes), whichever occurs first
82
+ while (ptr < end && ptr - start < 64) {
83
+ const c = content[ptr++];
84
+
85
+ // Ignore CR in CRLF sequence if text
86
+ if (text && c === 0x0d && ptr < end && content[ptr] === 0x0a) {
87
+ continue;
88
+ }
89
+
90
+ blockHashedCnt++;
91
+
92
+ if (c === 0x0a) {
93
+ // LF - end of line
94
+ break;
95
+ }
96
+
97
+ // djb2 hash: hash = hash * 33 + c
98
+ hash = ((hash << 5) + hash + c) >>> 0;
99
+ }
100
+
101
+ this.hashedCnt += blockHashedCnt;
102
+ this.add(hash, blockHashedCnt);
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Sort entries by key for efficient comparison.
108
+ */
109
+ sort(): void {
110
+ this.entries.sort((a, b) => a.key - b.key);
111
+ // Clear the map after sorting as we don't need it anymore
112
+ this.hashMap.clear();
113
+ }
114
+
115
+ /**
116
+ * Compute similarity score between this index and another.
117
+ *
118
+ * @param other The other index to compare with
119
+ * @param maxScore Maximum score (default 100)
120
+ * @returns Similarity score from 0 to maxScore
121
+ */
122
+ score(other: SimilarityIndex, maxScore: number = MAX_SCORE): number {
123
+ const max = Math.max(this.hashedCnt, other.hashedCnt);
124
+ if (max === 0) {
125
+ return maxScore; // Both empty = 100% match
126
+ }
127
+ return Math.floor((this.common(other) * maxScore) / max);
128
+ }
129
+
130
+ /**
131
+ * Count common bytes between this index and another.
132
+ * Both indices must be sorted.
133
+ */
134
+ private common(other: SimilarityIndex): number {
135
+ const srcEntries = this.entries;
136
+ const dstEntries = other.entries;
137
+
138
+ if (srcEntries.length === 0 || dstEntries.length === 0) {
139
+ return 0;
140
+ }
141
+
142
+ let srcIdx = 0;
143
+ let dstIdx = 0;
144
+ let commonBytes = 0;
145
+
146
+ while (srcIdx < srcEntries.length && dstIdx < dstEntries.length) {
147
+ const srcEntry = srcEntries[srcIdx];
148
+ const dstEntry = dstEntries[dstIdx];
149
+
150
+ if (srcEntry.key === dstEntry.key) {
151
+ // Same key - add minimum count to common
152
+ commonBytes += Math.min(srcEntry.count, dstEntry.count);
153
+ srcIdx++;
154
+ dstIdx++;
155
+ } else if (srcEntry.key < dstEntry.key) {
156
+ // Advance source
157
+ srcIdx++;
158
+ } else {
159
+ // Advance destination
160
+ dstIdx++;
161
+ }
162
+ }
163
+
164
+ return commonBytes;
165
+ }
166
+
167
+ /**
168
+ * Add a hash with count to the table.
169
+ */
170
+ private add(key: number, cnt: number): void {
171
+ // Mix bits and ensure not negative (same as JGit)
172
+ key = ((key * 0x9e370001) >>> 1) >>> 0;
173
+
174
+ const existingIdx = this.hashMap.get(key);
175
+ if (existingIdx !== undefined) {
176
+ // Increment count for existing key
177
+ this.entries[existingIdx].count += cnt;
178
+ } else {
179
+ // Add new entry
180
+ const idx = this.entries.length;
181
+ this.entries.push({ key, count: cnt });
182
+ this.hashMap.set(key, idx);
183
+ }
184
+ }
185
+ }
@@ -0,0 +1,35 @@
1
+ import type { ObjectId } from "@statewalker/vcs-core";
2
+
3
+ import type { MergeFailureReason } from "../errors/merge-errors.js";
4
+
5
+ /**
6
+ * Status of a cherry-pick operation.
7
+ *
8
+ * Based on JGit's CherryPickResult.CherryPickStatus.
9
+ */
10
+ export enum CherryPickStatus {
11
+ /** Cherry-pick completed successfully */
12
+ OK = "ok",
13
+ /** Cherry-pick failed due to conflicts */
14
+ CONFLICTING = "conflicting",
15
+ /** Cherry-pick failed (preconditions not met) */
16
+ FAILED = "failed",
17
+ }
18
+
19
+ /**
20
+ * Result of a cherry-pick operation.
21
+ *
22
+ * Based on JGit's CherryPickResult.
23
+ */
24
+ export interface CherryPickResult {
25
+ /** Status of the cherry-pick operation */
26
+ readonly status: CherryPickStatus;
27
+ /** New HEAD commit after cherry-pick (if successful) */
28
+ readonly newHead?: ObjectId;
29
+ /** Cherry-picked commits (for OK status) */
30
+ readonly cherryPickedRefs: ObjectId[];
31
+ /** Paths with conflicts (for CONFLICTING status) */
32
+ readonly conflicts?: string[];
33
+ /** Paths that failed (for FAILED status) */
34
+ readonly failingPaths?: Map<string, MergeFailureReason>;
35
+ }
@@ -0,0 +1,25 @@
1
+ import type { ObjectId } from "@statewalker/vcs-core";
2
+
3
+ import type { FetchResult } from "./fetch-result.js";
4
+
5
+ /**
6
+ * Result of a clone operation.
7
+ *
8
+ * Based on JGit's CloneCommand result (returns Git instance).
9
+ */
10
+ export interface CloneResult {
11
+ /** The fetch result containing refs and pack data */
12
+ fetchResult: FetchResult;
13
+ /**
14
+ * Default branch that was checked out, as a bare branch name (`main`), so
15
+ * it can be handed straight to a branch or checkout command. The advertised
16
+ * form is on {@link FetchResult.defaultBranch}.
17
+ */
18
+ defaultBranch: string;
19
+ /** Remote name used (typically "origin") */
20
+ remoteName: string;
21
+ /** Whether this was a bare clone */
22
+ bare: boolean;
23
+ /** Head commit after clone */
24
+ headCommit?: ObjectId;
25
+ }