@statewalker/vcs-commands 0.1.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +180 -466
  2. package/dist/commands/commit-command.d.ts.map +1 -1
  3. package/dist/commands/init-command.d.ts.map +1 -1
  4. package/dist/commands/push-command.d.ts.map +1 -1
  5. package/dist/core-commands/checkout.command.impl.d.ts +1 -1
  6. package/dist/core-commands/checkout.command.impl.d.ts.map +1 -1
  7. package/dist/git-command.d.ts.map +1 -1
  8. package/package.json +25 -16
  9. package/src/commands/add-command.ts +494 -0
  10. package/src/commands/blame-command.ts +1241 -0
  11. package/src/commands/branch-command.ts +487 -0
  12. package/src/commands/checkout-command.ts +681 -0
  13. package/src/commands/cherry-pick-command.ts +544 -0
  14. package/src/commands/clean-command.ts +218 -0
  15. package/src/commands/clone-command.ts +532 -0
  16. package/src/commands/commit-command.ts +529 -0
  17. package/src/commands/describe-command.ts +454 -0
  18. package/src/commands/diff-command.ts +257 -0
  19. package/src/commands/fetch-command.ts +615 -0
  20. package/src/commands/gc-command.ts +155 -0
  21. package/src/commands/index.ts +31 -0
  22. package/src/commands/init-command.ts +365 -0
  23. package/src/commands/log-command.ts +549 -0
  24. package/src/commands/ls-remote-command.ts +237 -0
  25. package/src/commands/merge-command.ts +750 -0
  26. package/src/commands/pack-refs-command.ts +101 -0
  27. package/src/commands/pull-command.ts +258 -0
  28. package/src/commands/push-command.ts +682 -0
  29. package/src/commands/rebase-command.ts +665 -0
  30. package/src/commands/reflog-command.ts +68 -0
  31. package/src/commands/remote-command.ts +385 -0
  32. package/src/commands/reset-command.ts +292 -0
  33. package/src/commands/revert-command.ts +552 -0
  34. package/src/commands/rm-command.ts +178 -0
  35. package/src/commands/stash-apply-command.ts +402 -0
  36. package/src/commands/stash-create-command.ts +339 -0
  37. package/src/commands/stash-drop-command.ts +115 -0
  38. package/src/commands/stash-list-command.ts +116 -0
  39. package/src/commands/status-command.ts +173 -0
  40. package/src/commands/tag-command.ts +378 -0
  41. package/src/commands/tree-restore.ts +126 -0
  42. package/src/core-commands/add.command.impl.ts +274 -0
  43. package/src/core-commands/add.command.ts +81 -0
  44. package/src/core-commands/checkout.command.impl.ts +586 -0
  45. package/src/core-commands/checkout.command.ts +125 -0
  46. package/src/core-commands/index.ts +13 -0
  47. package/src/errors/add-errors.ts +20 -0
  48. package/src/errors/checkout-errors.ts +42 -0
  49. package/src/errors/command-errors.ts +68 -0
  50. package/src/errors/commit-errors.ts +40 -0
  51. package/src/errors/git-api-error.ts +11 -0
  52. package/src/errors/index.ts +12 -0
  53. package/src/errors/merge-errors.ts +94 -0
  54. package/src/errors/rebase-errors.ts +34 -0
  55. package/src/errors/ref-errors.ts +100 -0
  56. package/src/errors/remote-errors.ts +27 -0
  57. package/src/errors/stash-errors.ts +42 -0
  58. package/src/errors/tag-errors.ts +16 -0
  59. package/src/errors/transport-errors.ts +68 -0
  60. package/src/git-command.ts +421 -0
  61. package/src/git.ts +910 -0
  62. package/src/index.ts +18 -0
  63. package/src/pack-import/index.ts +8 -0
  64. package/src/pack-import/pack-import.ts +24 -0
  65. package/src/remote-config/index.ts +12 -0
  66. package/src/remote-config/remote-config-store.ts +285 -0
  67. package/src/rename/index.ts +5 -0
  68. package/src/rename/similarity-index.ts +185 -0
  69. package/src/results/cherry-pick-result.ts +35 -0
  70. package/src/results/clone-result.ts +25 -0
  71. package/src/results/diff-entry.ts +162 -0
  72. package/src/results/diff-formatter.ts +416 -0
  73. package/src/results/fetch-result.ts +91 -0
  74. package/src/results/index.ts +13 -0
  75. package/src/results/init-result.ts +29 -0
  76. package/src/results/merge-result.ts +135 -0
  77. package/src/results/pull-result.ts +27 -0
  78. package/src/results/push-result.ts +86 -0
  79. package/src/results/rebase-result.ts +140 -0
  80. package/src/results/revert-result.ts +35 -0
  81. package/src/results/stash-result.ts +60 -0
  82. package/src/results/status-result.ts +65 -0
  83. package/src/transport-command.ts +125 -0
  84. package/src/tree-merge/index.ts +8 -0
  85. package/src/tree-merge/tree-merge.ts +249 -0
  86. package/src/types.ts +70 -0
@@ -0,0 +1,135 @@
1
+ import type { ObjectId } from "@statewalker/vcs-core";
2
+
3
+ import type { MergeFailureReason } from "../errors/merge-errors.js";
4
+
5
+ /**
6
+ * Status of a merge operation.
7
+ *
8
+ * Based on JGit's MergeResult.MergeStatus.
9
+ */
10
+ export enum MergeStatus {
11
+ /** Merge is a fast-forward (only HEAD moved) */
12
+ FAST_FORWARD = "fast-forward",
13
+ /** Fast-forward merge with squash (HEAD not moved, changes staged) */
14
+ FAST_FORWARD_SQUASHED = "fast-forward-squashed",
15
+ /** Merge was a no-op - already up to date */
16
+ ALREADY_UP_TO_DATE = "already-up-to-date",
17
+ /** Merge completed successfully (merge commit created) */
18
+ MERGED = "merged",
19
+ /** Merge completed but not committed (--no-commit) */
20
+ MERGED_NOT_COMMITTED = "merged-not-committed",
21
+ /** Merge was squashed (not committed, HEAD not updated) */
22
+ MERGED_SQUASHED = "merged-squashed",
23
+ /** Merge has conflicts that need to be resolved */
24
+ CONFLICTING = "conflicting",
25
+ /** Merge failed (preconditions not met) */
26
+ FAILED = "failed",
27
+ /** Merge aborted (e.g., FF_ONLY when not possible) */
28
+ ABORTED = "aborted",
29
+ }
30
+
31
+ /**
32
+ * Fast-forward merge mode.
33
+ *
34
+ * Based on JGit's MergeCommand.FastForwardMode.
35
+ */
36
+ export enum FastForwardMode {
37
+ /** Allow fast-forward when possible (default) */
38
+ FF = "ff",
39
+ /** Never fast-forward, always create merge commit */
40
+ NO_FF = "no-ff",
41
+ /** Only allow fast-forward, abort if not possible */
42
+ FF_ONLY = "ff-only",
43
+ }
44
+
45
+ /**
46
+ * Content merge strategy.
47
+ *
48
+ * Determines how to handle file-level conflicts.
49
+ * Based on JGit's ContentMergeStrategy.
50
+ */
51
+ export enum ContentMergeStrategy {
52
+ /** Take our version for conflicts */
53
+ OURS = "ours",
54
+ /** Take their version for conflicts */
55
+ THEIRS = "theirs",
56
+ /** Perform union merge (both sides) */
57
+ UNION = "union",
58
+ }
59
+
60
+ /**
61
+ * Merge strategy.
62
+ *
63
+ * Based on JGit's MergeStrategy.
64
+ */
65
+ export enum MergeStrategy {
66
+ /**
67
+ * Recursive three-way merge (default).
68
+ *
69
+ * Standard merge algorithm that finds common ancestor and
70
+ * performs three-way merge on each file.
71
+ */
72
+ RECURSIVE = "recursive",
73
+
74
+ /**
75
+ * Always take our side.
76
+ *
77
+ * Creates a merge commit but keeps our tree unchanged.
78
+ * The other branch's changes are completely ignored.
79
+ * Use case: record that merge happened without accepting changes.
80
+ */
81
+ OURS = "ours",
82
+
83
+ /**
84
+ * Always take their side.
85
+ *
86
+ * Creates a merge commit but replaces our tree with theirs.
87
+ * Our changes are completely discarded.
88
+ * Use case: replace our branch with theirs while preserving history.
89
+ */
90
+ THEIRS = "theirs",
91
+
92
+ /**
93
+ * Simple resolve strategy.
94
+ *
95
+ * Similar to recursive but doesn't handle criss-cross merges.
96
+ * Uses a single merge base.
97
+ */
98
+ RESOLVE = "resolve",
99
+ }
100
+
101
+ /**
102
+ * Result of a merge operation.
103
+ *
104
+ * Based on JGit's MergeResult.
105
+ */
106
+ export interface MergeResult {
107
+ /** Status of the merge operation */
108
+ readonly status: MergeStatus;
109
+ /** New HEAD commit after merge (if successful) */
110
+ readonly newHead?: ObjectId;
111
+ /** Merge base commit (common ancestor) */
112
+ readonly mergeBase?: ObjectId;
113
+ /** Commits that were merged */
114
+ readonly mergedCommits: ObjectId[];
115
+ /** Paths with conflicts (for CONFLICTING status) */
116
+ readonly conflicts?: string[];
117
+ /** Paths that failed (for FAILED status) */
118
+ readonly failingPaths?: Map<string, MergeFailureReason>;
119
+ /** Informational message */
120
+ readonly message?: string;
121
+ }
122
+
123
+ /**
124
+ * Check if merge status represents a successful merge.
125
+ */
126
+ export function isMergeSuccessful(status: MergeStatus): boolean {
127
+ return (
128
+ status === MergeStatus.FAST_FORWARD ||
129
+ status === MergeStatus.FAST_FORWARD_SQUASHED ||
130
+ status === MergeStatus.ALREADY_UP_TO_DATE ||
131
+ status === MergeStatus.MERGED ||
132
+ status === MergeStatus.MERGED_NOT_COMMITTED ||
133
+ status === MergeStatus.MERGED_SQUASHED
134
+ );
135
+ }
@@ -0,0 +1,27 @@
1
+ import type { FetchResult } from "./fetch-result.js";
2
+ import type { MergeResult } from "./merge-result.js";
3
+
4
+ /**
5
+ * Result of a pull operation.
6
+ *
7
+ * Based on JGit's PullResult.
8
+ */
9
+ export interface PullResult {
10
+ /** Result of the fetch phase */
11
+ fetchResult: FetchResult;
12
+ /** Result of the merge phase (if applicable) */
13
+ mergeResult?: MergeResult;
14
+ /** Whether rebase was used instead of merge */
15
+ rebaseUsed: boolean;
16
+ /** Whether pull was successful */
17
+ successful: boolean;
18
+ /** Fetch-from remote */
19
+ fetchedFrom: string;
20
+ }
21
+
22
+ /**
23
+ * Check if pull result was successful.
24
+ */
25
+ export function isPullSuccessful(result: PullResult): boolean {
26
+ return result.successful;
27
+ }
@@ -0,0 +1,86 @@
1
+ import type { ObjectId } from "@statewalker/vcs-core";
2
+
3
+ /**
4
+ * Status of a ref update during push.
5
+ *
6
+ * Based on JGit's RemoteRefUpdate.Status.
7
+ */
8
+ export enum PushStatus {
9
+ /** Update was performed successfully */
10
+ OK = "ok",
11
+ /** Update was rejected (not fast-forward) */
12
+ REJECTED_NONFASTFORWARD = "rejected-nonfastforward",
13
+ /** Update was rejected (other reason) */
14
+ REJECTED_OTHER = "rejected-other",
15
+ /** Update failed (remote error) */
16
+ FAILED = "failed",
17
+ /** Update not attempted (nothing to push) */
18
+ NOT_ATTEMPTED = "not-attempted",
19
+ /** Update already up to date */
20
+ UP_TO_DATE = "up-to-date",
21
+ /** Waiting for other updates to complete (atomic push) */
22
+ AWAITING_REPORT = "awaiting-report",
23
+ }
24
+
25
+ /**
26
+ * Result of updating a single ref during push.
27
+ *
28
+ * Based on JGit's RemoteRefUpdate.
29
+ */
30
+ export interface RemoteRefUpdate {
31
+ /** Local ref name that was pushed */
32
+ srcRef?: string;
33
+ /** Remote ref name that was updated */
34
+ remoteName: string;
35
+ /** Expected old object ID (for compare-and-swap) */
36
+ expectedOldObjectId?: ObjectId;
37
+ /** New object ID that was pushed */
38
+ newObjectId: ObjectId;
39
+ /** Status of the update */
40
+ status: PushStatus;
41
+ /** Message from server (if any) */
42
+ message?: string;
43
+ /** Whether this was a forced update */
44
+ forceUpdate: boolean;
45
+ /** Whether this was a delete operation */
46
+ delete: boolean;
47
+ }
48
+
49
+ /**
50
+ * Result of a push operation.
51
+ *
52
+ * Based on JGit's PushResult.
53
+ */
54
+ export interface PushResult {
55
+ /** URI of the remote that was pushed to */
56
+ uri: string;
57
+ /** Results for each ref update */
58
+ remoteUpdates: RemoteRefUpdate[];
59
+ /** Total bytes sent */
60
+ bytesSent: number;
61
+ /** Number of objects sent */
62
+ objectCount: number;
63
+ /** Server messages */
64
+ messages: string[];
65
+ }
66
+
67
+ /**
68
+ * Check if all updates in push result were successful.
69
+ */
70
+ export function isPushSuccessful(result: PushResult): boolean {
71
+ return result.remoteUpdates.every(
72
+ (u) => u.status === PushStatus.OK || u.status === PushStatus.UP_TO_DATE,
73
+ );
74
+ }
75
+
76
+ /**
77
+ * Get failed updates from push result.
78
+ */
79
+ export function getFailedUpdates(result: PushResult): RemoteRefUpdate[] {
80
+ return result.remoteUpdates.filter(
81
+ (u) =>
82
+ u.status !== PushStatus.OK &&
83
+ u.status !== PushStatus.UP_TO_DATE &&
84
+ u.status !== PushStatus.NOT_ATTEMPTED,
85
+ );
86
+ }
@@ -0,0 +1,140 @@
1
+ import type { ObjectId } from "@statewalker/vcs-core";
2
+
3
+ /**
4
+ * Status of a rebase operation.
5
+ *
6
+ * Based on JGit's RebaseResult.Status.
7
+ */
8
+ export enum RebaseStatus {
9
+ /**
10
+ * Rebase was successful.
11
+ */
12
+ OK = "ok",
13
+
14
+ /**
15
+ * Fast-forward was performed (no actual rebase needed).
16
+ */
17
+ FAST_FORWARD = "fast-forward",
18
+
19
+ /**
20
+ * Already up-to-date (no rebase needed).
21
+ */
22
+ UP_TO_DATE = "up-to-date",
23
+
24
+ /**
25
+ * Rebase stopped due to conflict.
26
+ */
27
+ STOPPED = "stopped",
28
+
29
+ /**
30
+ * Rebase was aborted.
31
+ */
32
+ ABORTED = "aborted",
33
+
34
+ /**
35
+ * Rebase was aborted due to failure (not conflict).
36
+ */
37
+ FAILED = "failed",
38
+
39
+ /**
40
+ * Uncommitted changes prevented rebase from starting.
41
+ */
42
+ UNCOMMITTED_CHANGES = "uncommitted-changes",
43
+
44
+ /**
45
+ * Interactive rebase is prepared but not started.
46
+ */
47
+ INTERACTIVE_PREPARED = "interactive-prepared",
48
+
49
+ /**
50
+ * Continue was called but there was nothing to commit.
51
+ */
52
+ NOTHING_TO_COMMIT = "nothing-to-commit",
53
+
54
+ /**
55
+ * Stash apply failed after successful rebase.
56
+ */
57
+ STASH_APPLY_CONFLICTS = "stash-apply-conflicts",
58
+
59
+ /**
60
+ * Rebase stopped at edit step.
61
+ */
62
+ EDIT = "edit",
63
+ }
64
+
65
+ /**
66
+ * Rebase todo line action.
67
+ *
68
+ * Based on JGit's RebaseTodoLine.Action.
69
+ */
70
+ export enum RebaseAction {
71
+ /** Pick the commit (apply it) */
72
+ PICK = "pick",
73
+
74
+ /** Reword: pick but edit commit message */
75
+ REWORD = "reword",
76
+
77
+ /** Edit: stop for amending */
78
+ EDIT = "edit",
79
+
80
+ /** Squash into previous commit (combine messages) */
81
+ SQUASH = "squash",
82
+
83
+ /** Fixup: squash but discard this commit's message */
84
+ FIXUP = "fixup",
85
+
86
+ /** Comment line (ignored) */
87
+ COMMENT = "comment",
88
+ }
89
+
90
+ /**
91
+ * A single line in the rebase todo list.
92
+ *
93
+ * Based on JGit's RebaseTodoLine.
94
+ */
95
+ export interface RebaseTodoLine {
96
+ /** The action to perform */
97
+ action: RebaseAction;
98
+
99
+ /** The commit ID (abbreviated) */
100
+ commit: string;
101
+
102
+ /** Short message of the commit */
103
+ shortMessage: string;
104
+ }
105
+
106
+ /**
107
+ * Result of a rebase operation.
108
+ *
109
+ * Based on JGit's RebaseResult.
110
+ */
111
+ export interface RebaseResult {
112
+ /** Status of the rebase */
113
+ readonly status: RebaseStatus;
114
+
115
+ /** New HEAD after successful rebase */
116
+ readonly newHead?: ObjectId;
117
+
118
+ /** Commit that caused the stop (for conflicts/edit) */
119
+ readonly currentCommit?: ObjectId;
120
+
121
+ /** List of conflicting paths */
122
+ readonly conflicts?: string[];
123
+
124
+ /** List of failing paths (not conflicts) */
125
+ readonly failingPaths?: Map<string, string>;
126
+
127
+ /** Uncommitted changes that prevented rebase */
128
+ readonly uncommittedChanges?: string[];
129
+ }
130
+
131
+ /**
132
+ * Check if rebase status indicates success.
133
+ */
134
+ export function isRebaseSuccessful(status: RebaseStatus): boolean {
135
+ return (
136
+ status === RebaseStatus.OK ||
137
+ status === RebaseStatus.FAST_FORWARD ||
138
+ status === RebaseStatus.UP_TO_DATE
139
+ );
140
+ }
@@ -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 revert operation.
7
+ *
8
+ * Based on JGit's RevertCommand result patterns.
9
+ */
10
+ export enum RevertStatus {
11
+ /** Revert completed successfully */
12
+ OK = "ok",
13
+ /** Revert resulted in conflicts */
14
+ CONFLICTING = "conflicting",
15
+ /** Revert failed due to dirty working tree or other issues */
16
+ FAILED = "failed",
17
+ }
18
+
19
+ /**
20
+ * Result of a revert operation.
21
+ *
22
+ * Contains the status, new HEAD, and details about reverted commits or conflicts.
23
+ */
24
+ export interface RevertResult {
25
+ /** Status of the revert operation */
26
+ readonly status: RevertStatus;
27
+ /** New HEAD commit after revert (undefined if failed/conflicting) */
28
+ readonly newHead?: ObjectId;
29
+ /** Commits that were successfully reverted */
30
+ readonly revertedRefs: ObjectId[];
31
+ /** Conflicting paths (if status is CONFLICTING) */
32
+ readonly conflicts?: string[];
33
+ /** Paths that failed (if status is FAILED) */
34
+ readonly failingPaths?: Map<string, MergeFailureReason>;
35
+ }
@@ -0,0 +1,60 @@
1
+ import type { ObjectId } from "@statewalker/vcs-core";
2
+
3
+ /**
4
+ * Represents a stashed commit entry.
5
+ *
6
+ * Based on JGit's stash structure where each stash is a merge commit with:
7
+ * - Parent 0: The HEAD commit at stash time
8
+ * - Parent 1: The index state
9
+ * - Parent 2 (optional): Untracked files
10
+ */
11
+ export interface StashEntry {
12
+ /** The stash commit ID */
13
+ readonly commitId: ObjectId;
14
+
15
+ /** The original HEAD commit at stash time */
16
+ readonly headCommit: ObjectId;
17
+
18
+ /** The index commit (staged changes) */
19
+ readonly indexCommit: ObjectId;
20
+
21
+ /** The untracked files commit (optional) */
22
+ readonly untrackedCommit?: ObjectId;
23
+
24
+ /** The stash message */
25
+ readonly message: string;
26
+
27
+ /** The stash index (0-based, most recent first) */
28
+ readonly index: number;
29
+
30
+ /** Timestamp when stash was created */
31
+ readonly timestamp: number;
32
+ }
33
+
34
+ /**
35
+ * Status of stash apply operation.
36
+ */
37
+ export enum StashApplyStatus {
38
+ /** Stash was applied successfully */
39
+ OK = "ok",
40
+
41
+ /** Stash apply resulted in conflicts */
42
+ CONFLICTS = "conflicts",
43
+
44
+ /** Stash apply failed */
45
+ FAILED = "failed",
46
+ }
47
+
48
+ /**
49
+ * Result of stash apply operation.
50
+ */
51
+ export interface StashApplyResult {
52
+ /** Status of the apply */
53
+ readonly status: StashApplyStatus;
54
+
55
+ /** The stash commit that was applied */
56
+ readonly stashCommit?: ObjectId;
57
+
58
+ /** List of conflicting paths */
59
+ readonly conflicts?: string[];
60
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Status of the staging area compared to HEAD.
3
+ *
4
+ * This is a simplified version for repositories without working trees,
5
+ * focusing on staged changes and conflicts.
6
+ *
7
+ * Based on JGit's Status but without working tree operations.
8
+ */
9
+ export interface Status {
10
+ /**
11
+ * Files added to staging (not in HEAD).
12
+ */
13
+ readonly added: Set<string>;
14
+
15
+ /**
16
+ * Files modified in staging (different from HEAD).
17
+ */
18
+ readonly changed: Set<string>;
19
+
20
+ /**
21
+ * Files removed from staging (in HEAD but not in staging).
22
+ */
23
+ readonly removed: Set<string>;
24
+
25
+ /**
26
+ * Files with merge conflicts.
27
+ */
28
+ readonly conflicting: Set<string>;
29
+
30
+ /**
31
+ * Check if the staging area is clean (no changes, no conflicts).
32
+ */
33
+ isClean(): boolean;
34
+
35
+ /**
36
+ * Check if there are uncommitted changes.
37
+ * True if any files are added, changed, removed, or conflicting.
38
+ */
39
+ hasUncommittedChanges(): boolean;
40
+ }
41
+
42
+ /**
43
+ * Implementation of Status interface.
44
+ */
45
+ export class StatusImpl implements Status {
46
+ constructor(
47
+ public readonly added: Set<string>,
48
+ public readonly changed: Set<string>,
49
+ public readonly removed: Set<string>,
50
+ public readonly conflicting: Set<string>,
51
+ ) {}
52
+
53
+ isClean(): boolean {
54
+ return (
55
+ this.added.size === 0 &&
56
+ this.changed.size === 0 &&
57
+ this.removed.size === 0 &&
58
+ this.conflicting.size === 0
59
+ );
60
+ }
61
+
62
+ hasUncommittedChanges(): boolean {
63
+ return !this.isClean();
64
+ }
65
+ }
@@ -0,0 +1,125 @@
1
+ import type { Credentials, ProgressInfo } from "@statewalker/vcs-transport";
2
+
3
+ import { GitCommand } from "./git-command.js";
4
+
5
+ /**
6
+ * Progress callback type for transport operations.
7
+ */
8
+ export type ProgressCallback = (info: ProgressInfo) => void;
9
+
10
+ /**
11
+ * Options for transport operations.
12
+ */
13
+ export interface TransportOptions {
14
+ /** Authentication credentials */
15
+ auth?: Credentials;
16
+ /** Custom HTTP headers */
17
+ headers?: Record<string, string>;
18
+ /** Request timeout in milliseconds */
19
+ timeout?: number;
20
+ /** Progress callback */
21
+ onProgress?: ProgressCallback;
22
+ /** Raw progress message callback */
23
+ onProgressMessage?: (message: string) => void;
24
+ }
25
+
26
+ /**
27
+ * Base class for commands that require network transport.
28
+ *
29
+ * Adds authentication, timeout, and progress support on top of GitCommand.
30
+ * Based on JGit's TransportCommand<C, R>.
31
+ *
32
+ * @typeParam T - The return type of the command's call() method
33
+ */
34
+ export abstract class TransportCommand<T> extends GitCommand<T> {
35
+ /** Authentication credentials */
36
+ protected credentials?: Credentials;
37
+ /** Request timeout in milliseconds */
38
+ protected timeout?: number;
39
+ /** Custom HTTP headers */
40
+ protected headers?: Record<string, string>;
41
+ /** Progress callback */
42
+ protected progressCallback?: ProgressCallback;
43
+ /** Progress message callback */
44
+ protected progressMessageCallback?: (message: string) => void;
45
+
46
+ /**
47
+ * Set authentication credentials.
48
+ *
49
+ * @param credentials Username/password or token credentials
50
+ */
51
+ setCredentials(credentials: Credentials): this {
52
+ this.checkCallable();
53
+ this.credentials = credentials;
54
+ return this;
55
+ }
56
+
57
+ /**
58
+ * Set authentication using username and password.
59
+ *
60
+ * @param username Username
61
+ * @param password Password
62
+ */
63
+ setCredentialsProvider(username: string, password: string): this {
64
+ this.checkCallable();
65
+ this.credentials = { username, password };
66
+ return this;
67
+ }
68
+
69
+ /**
70
+ * Set request timeout.
71
+ *
72
+ * @param timeout Timeout in milliseconds
73
+ */
74
+ setTimeout(timeout: number): this {
75
+ this.checkCallable();
76
+ this.timeout = timeout;
77
+ return this;
78
+ }
79
+
80
+ /**
81
+ * Set custom HTTP headers.
82
+ *
83
+ * @param headers Custom headers
84
+ */
85
+ setHeaders(headers: Record<string, string>): this {
86
+ this.checkCallable();
87
+ this.headers = headers;
88
+ return this;
89
+ }
90
+
91
+ /**
92
+ * Set progress callback.
93
+ *
94
+ * @param callback Progress callback function
95
+ */
96
+ setProgressMonitor(callback: ProgressCallback): this {
97
+ this.checkCallable();
98
+ this.progressCallback = callback;
99
+ return this;
100
+ }
101
+
102
+ /**
103
+ * Set progress message callback.
104
+ *
105
+ * @param callback Progress message callback function
106
+ */
107
+ setProgressMessageCallback(callback: (message: string) => void): this {
108
+ this.checkCallable();
109
+ this.progressMessageCallback = callback;
110
+ return this;
111
+ }
112
+
113
+ /**
114
+ * Get transport options for passing to transport operations.
115
+ */
116
+ protected getTransportOptions(): TransportOptions {
117
+ return {
118
+ auth: this.credentials,
119
+ headers: this.headers,
120
+ timeout: this.timeout,
121
+ onProgress: this.progressCallback,
122
+ onProgressMessage: this.progressMessageCallback,
123
+ };
124
+ }
125
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Path-level three-way tree merge shared by the commands that replay one
3
+ * tree's changes onto another (`rebase`, `stash apply`).
4
+ *
5
+ * Internal: not re-exported from `src/index.ts`.
6
+ */
7
+
8
+ export { mergeTreesThreeWay, type TreeMergeResult } from "./tree-merge.js";