gitx.do 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/blame.d.ts +259 -0
- package/dist/cli/commands/blame.d.ts.map +1 -0
- package/dist/cli/commands/blame.js +609 -0
- package/dist/cli/commands/blame.js.map +1 -0
- package/dist/cli/commands/branch.d.ts +249 -0
- package/dist/cli/commands/branch.d.ts.map +1 -0
- package/dist/cli/commands/branch.js +693 -0
- package/dist/cli/commands/branch.js.map +1 -0
- package/dist/cli/commands/commit.d.ts +182 -0
- package/dist/cli/commands/commit.d.ts.map +1 -0
- package/dist/cli/commands/commit.js +437 -0
- package/dist/cli/commands/commit.js.map +1 -0
- package/dist/cli/commands/diff.d.ts +464 -0
- package/dist/cli/commands/diff.d.ts.map +1 -0
- package/dist/cli/commands/diff.js +958 -0
- package/dist/cli/commands/diff.js.map +1 -0
- package/dist/cli/commands/log.d.ts +239 -0
- package/dist/cli/commands/log.d.ts.map +1 -0
- package/dist/cli/commands/log.js +535 -0
- package/dist/cli/commands/log.js.map +1 -0
- package/dist/cli/commands/review.d.ts +457 -0
- package/dist/cli/commands/review.d.ts.map +1 -0
- package/dist/cli/commands/review.js +533 -0
- package/dist/cli/commands/review.js.map +1 -0
- package/dist/cli/commands/status.d.ts +269 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +493 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/web.d.ts +199 -0
- package/dist/cli/commands/web.d.ts.map +1 -0
- package/dist/cli/commands/web.js +696 -0
- package/dist/cli/commands/web.js.map +1 -0
- package/dist/cli/fs-adapter.d.ts +656 -0
- package/dist/cli/fs-adapter.d.ts.map +1 -0
- package/dist/cli/fs-adapter.js +1179 -0
- package/dist/cli/fs-adapter.js.map +1 -0
- package/dist/cli/index.d.ts +387 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +523 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/ui/components/DiffView.d.ts +7 -0
- package/dist/cli/ui/components/DiffView.d.ts.map +1 -0
- package/dist/cli/ui/components/DiffView.js +11 -0
- package/dist/cli/ui/components/DiffView.js.map +1 -0
- package/dist/cli/ui/components/ErrorDisplay.d.ts +6 -0
- package/dist/cli/ui/components/ErrorDisplay.d.ts.map +1 -0
- package/dist/cli/ui/components/ErrorDisplay.js +11 -0
- package/dist/cli/ui/components/ErrorDisplay.js.map +1 -0
- package/dist/cli/ui/components/FuzzySearch.d.ts +9 -0
- package/dist/cli/ui/components/FuzzySearch.d.ts.map +1 -0
- package/dist/cli/ui/components/FuzzySearch.js +12 -0
- package/dist/cli/ui/components/FuzzySearch.js.map +1 -0
- package/dist/cli/ui/components/LoadingSpinner.d.ts +6 -0
- package/dist/cli/ui/components/LoadingSpinner.d.ts.map +1 -0
- package/dist/cli/ui/components/LoadingSpinner.js +10 -0
- package/dist/cli/ui/components/LoadingSpinner.js.map +1 -0
- package/dist/cli/ui/components/NavigationList.d.ts +9 -0
- package/dist/cli/ui/components/NavigationList.d.ts.map +1 -0
- package/dist/cli/ui/components/NavigationList.js +11 -0
- package/dist/cli/ui/components/NavigationList.js.map +1 -0
- package/dist/cli/ui/components/ScrollableContent.d.ts +8 -0
- package/dist/cli/ui/components/ScrollableContent.d.ts.map +1 -0
- package/dist/cli/ui/components/ScrollableContent.js +11 -0
- package/dist/cli/ui/components/ScrollableContent.js.map +1 -0
- package/dist/cli/ui/components/index.d.ts +7 -0
- package/dist/cli/ui/components/index.d.ts.map +1 -0
- package/dist/cli/ui/components/index.js +9 -0
- package/dist/cli/ui/components/index.js.map +1 -0
- package/dist/cli/ui/terminal-ui.d.ts +52 -0
- package/dist/cli/ui/terminal-ui.d.ts.map +1 -0
- package/dist/cli/ui/terminal-ui.js +121 -0
- package/dist/cli/ui/terminal-ui.js.map +1 -0
- package/dist/durable-object/object-store.d.ts +401 -23
- package/dist/durable-object/object-store.d.ts.map +1 -1
- package/dist/durable-object/object-store.js +414 -25
- package/dist/durable-object/object-store.js.map +1 -1
- package/dist/durable-object/schema.d.ts +188 -0
- package/dist/durable-object/schema.d.ts.map +1 -1
- package/dist/durable-object/schema.js +160 -0
- package/dist/durable-object/schema.js.map +1 -1
- package/dist/durable-object/wal.d.ts +336 -31
- package/dist/durable-object/wal.d.ts.map +1 -1
- package/dist/durable-object/wal.js +272 -27
- package/dist/durable-object/wal.js.map +1 -1
- package/dist/index.d.ts +379 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +379 -7
- package/dist/index.js.map +1 -1
- package/dist/mcp/adapter.d.ts +579 -38
- package/dist/mcp/adapter.d.ts.map +1 -1
- package/dist/mcp/adapter.js +426 -33
- package/dist/mcp/adapter.js.map +1 -1
- package/dist/mcp/sandbox.d.ts +532 -29
- package/dist/mcp/sandbox.d.ts.map +1 -1
- package/dist/mcp/sandbox.js +389 -22
- package/dist/mcp/sandbox.js.map +1 -1
- package/dist/mcp/sdk-adapter.d.ts +478 -56
- package/dist/mcp/sdk-adapter.d.ts.map +1 -1
- package/dist/mcp/sdk-adapter.js +346 -44
- package/dist/mcp/sdk-adapter.js.map +1 -1
- package/dist/mcp/tools.d.ts +445 -30
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +363 -33
- package/dist/mcp/tools.js.map +1 -1
- package/dist/ops/blame.d.ts +424 -21
- package/dist/ops/blame.d.ts.map +1 -1
- package/dist/ops/blame.js +303 -20
- package/dist/ops/blame.js.map +1 -1
- package/dist/ops/branch.d.ts +583 -32
- package/dist/ops/branch.d.ts.map +1 -1
- package/dist/ops/branch.js +365 -23
- package/dist/ops/branch.js.map +1 -1
- package/dist/ops/commit-traversal.d.ts +164 -24
- package/dist/ops/commit-traversal.d.ts.map +1 -1
- package/dist/ops/commit-traversal.js +68 -2
- package/dist/ops/commit-traversal.js.map +1 -1
- package/dist/ops/commit.d.ts +387 -53
- package/dist/ops/commit.d.ts.map +1 -1
- package/dist/ops/commit.js +249 -29
- package/dist/ops/commit.js.map +1 -1
- package/dist/ops/merge-base.d.ts +195 -21
- package/dist/ops/merge-base.d.ts.map +1 -1
- package/dist/ops/merge-base.js +122 -12
- package/dist/ops/merge-base.js.map +1 -1
- package/dist/ops/merge.d.ts +600 -130
- package/dist/ops/merge.d.ts.map +1 -1
- package/dist/ops/merge.js +408 -60
- package/dist/ops/merge.js.map +1 -1
- package/dist/ops/tag.d.ts +67 -2
- package/dist/ops/tag.d.ts.map +1 -1
- package/dist/ops/tag.js +42 -1
- package/dist/ops/tag.js.map +1 -1
- package/dist/ops/tree-builder.d.ts +102 -6
- package/dist/ops/tree-builder.d.ts.map +1 -1
- package/dist/ops/tree-builder.js +30 -5
- package/dist/ops/tree-builder.js.map +1 -1
- package/dist/ops/tree-diff.d.ts +50 -2
- package/dist/ops/tree-diff.d.ts.map +1 -1
- package/dist/ops/tree-diff.js +50 -2
- package/dist/ops/tree-diff.js.map +1 -1
- package/dist/pack/delta.d.ts +211 -39
- package/dist/pack/delta.d.ts.map +1 -1
- package/dist/pack/delta.js +232 -46
- package/dist/pack/delta.js.map +1 -1
- package/dist/pack/format.d.ts +390 -28
- package/dist/pack/format.d.ts.map +1 -1
- package/dist/pack/format.js +344 -33
- package/dist/pack/format.js.map +1 -1
- package/dist/pack/full-generation.d.ts +313 -28
- package/dist/pack/full-generation.d.ts.map +1 -1
- package/dist/pack/full-generation.js +238 -19
- package/dist/pack/full-generation.js.map +1 -1
- package/dist/pack/generation.d.ts +346 -23
- package/dist/pack/generation.d.ts.map +1 -1
- package/dist/pack/generation.js +269 -21
- package/dist/pack/generation.js.map +1 -1
- package/dist/pack/index.d.ts +407 -86
- package/dist/pack/index.d.ts.map +1 -1
- package/dist/pack/index.js +351 -70
- package/dist/pack/index.js.map +1 -1
- package/dist/refs/branch.d.ts +517 -71
- package/dist/refs/branch.d.ts.map +1 -1
- package/dist/refs/branch.js +410 -26
- package/dist/refs/branch.js.map +1 -1
- package/dist/refs/storage.d.ts +610 -57
- package/dist/refs/storage.d.ts.map +1 -1
- package/dist/refs/storage.js +481 -29
- package/dist/refs/storage.js.map +1 -1
- package/dist/refs/tag.d.ts +677 -67
- package/dist/refs/tag.d.ts.map +1 -1
- package/dist/refs/tag.js +497 -30
- package/dist/refs/tag.js.map +1 -1
- package/dist/storage/lru-cache.d.ts +556 -53
- package/dist/storage/lru-cache.d.ts.map +1 -1
- package/dist/storage/lru-cache.js +439 -36
- package/dist/storage/lru-cache.js.map +1 -1
- package/dist/storage/object-index.d.ts +483 -38
- package/dist/storage/object-index.d.ts.map +1 -1
- package/dist/storage/object-index.js +388 -22
- package/dist/storage/object-index.js.map +1 -1
- package/dist/storage/r2-pack.d.ts +957 -94
- package/dist/storage/r2-pack.d.ts.map +1 -1
- package/dist/storage/r2-pack.js +756 -48
- package/dist/storage/r2-pack.js.map +1 -1
- package/dist/tiered/cdc-pipeline.d.ts +1610 -38
- package/dist/tiered/cdc-pipeline.d.ts.map +1 -1
- package/dist/tiered/cdc-pipeline.js +1131 -22
- package/dist/tiered/cdc-pipeline.js.map +1 -1
- package/dist/tiered/migration.d.ts +903 -41
- package/dist/tiered/migration.d.ts.map +1 -1
- package/dist/tiered/migration.js +646 -24
- package/dist/tiered/migration.js.map +1 -1
- package/dist/tiered/parquet-writer.d.ts +944 -47
- package/dist/tiered/parquet-writer.d.ts.map +1 -1
- package/dist/tiered/parquet-writer.js +667 -39
- package/dist/tiered/parquet-writer.js.map +1 -1
- package/dist/tiered/read-path.d.ts +728 -34
- package/dist/tiered/read-path.d.ts.map +1 -1
- package/dist/tiered/read-path.js +310 -27
- package/dist/tiered/read-path.js.map +1 -1
- package/dist/types/objects.d.ts +457 -0
- package/dist/types/objects.d.ts.map +1 -1
- package/dist/types/objects.js +305 -4
- package/dist/types/objects.js.map +1 -1
- package/dist/types/storage.d.ts +407 -35
- package/dist/types/storage.d.ts.map +1 -1
- package/dist/types/storage.js +27 -3
- package/dist/types/storage.js.map +1 -1
- package/dist/utils/hash.d.ts +133 -12
- package/dist/utils/hash.d.ts.map +1 -1
- package/dist/utils/hash.js +133 -12
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/sha1.d.ts +102 -9
- package/dist/utils/sha1.d.ts.map +1 -1
- package/dist/utils/sha1.js +114 -11
- package/dist/utils/sha1.js.map +1 -1
- package/dist/wire/capabilities.d.ts +896 -88
- package/dist/wire/capabilities.d.ts.map +1 -1
- package/dist/wire/capabilities.js +566 -62
- package/dist/wire/capabilities.js.map +1 -1
- package/dist/wire/pkt-line.d.ts +293 -15
- package/dist/wire/pkt-line.d.ts.map +1 -1
- package/dist/wire/pkt-line.js +251 -15
- package/dist/wire/pkt-line.js.map +1 -1
- package/dist/wire/receive-pack.d.ts +814 -64
- package/dist/wire/receive-pack.d.ts.map +1 -1
- package/dist/wire/receive-pack.js +542 -41
- package/dist/wire/receive-pack.js.map +1 -1
- package/dist/wire/smart-http.d.ts +575 -97
- package/dist/wire/smart-http.d.ts.map +1 -1
- package/dist/wire/smart-http.js +337 -46
- package/dist/wire/smart-http.js.map +1 -1
- package/dist/wire/upload-pack.d.ts +492 -98
- package/dist/wire/upload-pack.d.ts.map +1 -1
- package/dist/wire/upload-pack.js +347 -59
- package/dist/wire/upload-pack.js.map +1 -1
- package/package.json +10 -2
package/dist/ops/merge.d.ts
CHANGED
|
@@ -1,219 +1,447 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Three-way
|
|
2
|
+
* @fileoverview Three-way Merge Implementation for Git
|
|
3
3
|
*
|
|
4
|
-
* This module provides
|
|
5
|
-
*
|
|
4
|
+
* This module provides a complete implementation of Git's three-way merge algorithm,
|
|
5
|
+
* enabling branch merging with automatic conflict detection and resolution capabilities.
|
|
6
|
+
*
|
|
7
|
+
* ## Overview
|
|
8
|
+
*
|
|
9
|
+
* The three-way merge algorithm works by:
|
|
10
|
+
* 1. Finding the common ancestor (merge base) of two commits
|
|
11
|
+
* 2. Comparing both branches against this base to identify changes
|
|
12
|
+
* 3. Automatically merging non-conflicting changes
|
|
13
|
+
* 4. Detecting and reporting conflicts for manual resolution
|
|
14
|
+
*
|
|
15
|
+
* ## Supported Features
|
|
16
|
+
*
|
|
17
|
+
* - Fast-forward merges when possible
|
|
18
|
+
* - Three-way content merging for text files
|
|
19
|
+
* - Binary file detection and handling
|
|
20
|
+
* - Multiple conflict types (content, add-add, modify-delete, etc.)
|
|
21
|
+
* - Conflict resolution strategies (ours, theirs, custom)
|
|
22
|
+
* - Merge state persistence for multi-step conflict resolution
|
|
23
|
+
*
|
|
24
|
+
* ## Usage Example
|
|
25
|
+
*
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { merge, resolveConflict, continueMerge } from './ops/merge'
|
|
28
|
+
*
|
|
29
|
+
* // Perform a merge
|
|
30
|
+
* const result = await merge(storage, currentBranchSha, featureBranchSha, {
|
|
31
|
+
* message: 'Merge feature branch',
|
|
32
|
+
* allowFastForward: true
|
|
33
|
+
* })
|
|
34
|
+
*
|
|
35
|
+
* if (result.status === 'conflicted') {
|
|
36
|
+
* // Resolve conflicts
|
|
37
|
+
* for (const conflict of result.conflicts) {
|
|
38
|
+
* await resolveConflict(storage, conflict.path, { resolution: 'ours' })
|
|
39
|
+
* }
|
|
40
|
+
* // Complete the merge
|
|
41
|
+
* await continueMerge(storage)
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @module ops/merge
|
|
6
46
|
*/
|
|
7
47
|
/**
|
|
8
|
-
* Types of merge conflicts that can occur
|
|
48
|
+
* Types of merge conflicts that can occur during a three-way merge.
|
|
49
|
+
*
|
|
50
|
+
* @description
|
|
51
|
+
* Each conflict type represents a different scenario where automatic
|
|
52
|
+
* merging is not possible and manual intervention is required.
|
|
53
|
+
*
|
|
54
|
+
* - `content`: Both sides modified the same file with different changes
|
|
55
|
+
* - `add-add`: Both sides added the same file with different content
|
|
56
|
+
* - `modify-delete`: One side modified a file that the other side deleted
|
|
57
|
+
* - `delete-modify`: One side deleted a file that the other side modified
|
|
58
|
+
* - `rename-rename`: Both sides renamed the same file to different names
|
|
59
|
+
* - `rename-delete`: One side renamed a file that the other side deleted
|
|
60
|
+
* - `directory-file`: One side has a directory where the other has a file
|
|
9
61
|
*/
|
|
10
62
|
export type ConflictType = 'content' | 'add-add' | 'modify-delete' | 'delete-modify' | 'rename-rename' | 'rename-delete' | 'directory-file';
|
|
11
63
|
/**
|
|
12
|
-
*
|
|
64
|
+
* Available merge strategies for combining branches.
|
|
65
|
+
*
|
|
66
|
+
* @description
|
|
67
|
+
* Different strategies determine how the merge algorithm handles
|
|
68
|
+
* combining changes from multiple branches.
|
|
69
|
+
*
|
|
70
|
+
* - `recursive`: Default three-way merge with recursive conflict resolution
|
|
71
|
+
* - `ours`: Automatically resolve all conflicts favoring the current branch
|
|
72
|
+
* - `theirs`: Automatically resolve all conflicts favoring the merged branch
|
|
73
|
+
* - `octopus`: Merge multiple branches simultaneously (no conflict resolution)
|
|
74
|
+
* - `subtree`: Merge into a subdirectory of the current tree
|
|
13
75
|
*/
|
|
14
76
|
export type MergeStrategy = 'recursive' | 'ours' | 'theirs' | 'octopus' | 'subtree';
|
|
15
77
|
/**
|
|
16
|
-
* Status of a merge operation
|
|
78
|
+
* Status indicating the outcome of a merge operation.
|
|
79
|
+
*
|
|
80
|
+
* @description
|
|
81
|
+
* The merge status determines what action, if any, needs to be taken
|
|
82
|
+
* after a merge operation completes.
|
|
83
|
+
*
|
|
84
|
+
* - `fast-forward`: Branch pointer was simply moved forward (no merge commit)
|
|
85
|
+
* - `merged`: Changes were successfully combined into a merge commit
|
|
86
|
+
* - `conflicted`: Merge has conflicts requiring manual resolution
|
|
87
|
+
* - `up-to-date`: Target branch is already merged; nothing to do
|
|
88
|
+
* - `aborted`: Merge was cancelled and changes were rolled back
|
|
89
|
+
* - `in-progress`: Merge started but not yet completed (conflicts pending)
|
|
17
90
|
*/
|
|
18
91
|
export type MergeStatus = 'fast-forward' | 'merged' | 'conflicted' | 'up-to-date' | 'aborted' | 'in-progress';
|
|
19
92
|
/**
|
|
20
|
-
* Represents
|
|
93
|
+
* Represents the position and content of conflict markers in a file.
|
|
94
|
+
*
|
|
95
|
+
* @description
|
|
96
|
+
* When a content conflict occurs, the file is written with standard Git
|
|
97
|
+
* conflict markers. This interface describes the location and content
|
|
98
|
+
* of each conflicting section.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* // A typical conflict marker structure in a file:
|
|
103
|
+
* // <<<<<<< ours
|
|
104
|
+
* // our changes here
|
|
105
|
+
* // =======
|
|
106
|
+
* // their changes here
|
|
107
|
+
* // >>>>>>> theirs
|
|
108
|
+
*
|
|
109
|
+
* const marker: ConflictMarker = {
|
|
110
|
+
* startLine: 10,
|
|
111
|
+
* endLine: 16,
|
|
112
|
+
* baseContent: 'original line',
|
|
113
|
+
* oursContent: 'our changes here',
|
|
114
|
+
* theirsContent: 'their changes here'
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
21
117
|
*/
|
|
22
118
|
export interface ConflictMarker {
|
|
23
|
-
/** Line number where marker starts (1-indexed) */
|
|
119
|
+
/** Line number where the conflict marker starts (1-indexed) */
|
|
24
120
|
startLine: number;
|
|
25
|
-
/** Line number where marker ends (1-indexed) */
|
|
121
|
+
/** Line number where the conflict marker ends (1-indexed) */
|
|
26
122
|
endLine: number;
|
|
27
|
-
/** The conflicting content from the base version */
|
|
123
|
+
/** The conflicting content from the base (common ancestor) version */
|
|
28
124
|
baseContent?: string;
|
|
29
|
-
/** The conflicting content from our (current) version */
|
|
125
|
+
/** The conflicting content from our (current branch) version */
|
|
30
126
|
oursContent: string;
|
|
31
|
-
/** The conflicting content from
|
|
127
|
+
/** The conflicting content from their (merged branch) version */
|
|
32
128
|
theirsContent: string;
|
|
33
129
|
}
|
|
34
130
|
/**
|
|
35
|
-
* Represents a single merge conflict
|
|
131
|
+
* Represents a single merge conflict that requires resolution.
|
|
132
|
+
*
|
|
133
|
+
* @description
|
|
134
|
+
* A MergeConflict contains all information needed to understand and
|
|
135
|
+
* resolve a conflict between two versions of a file. It includes
|
|
136
|
+
* references to all three versions (base, ours, theirs) when available.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const conflict: MergeConflict = {
|
|
141
|
+
* type: 'content',
|
|
142
|
+
* path: 'src/utils.ts',
|
|
143
|
+
* baseSha: 'abc123...',
|
|
144
|
+
* oursSha: 'def456...',
|
|
145
|
+
* theirsSha: 'ghi789...',
|
|
146
|
+
* baseMode: '100644',
|
|
147
|
+
* oursMode: '100644',
|
|
148
|
+
* theirsMode: '100644',
|
|
149
|
+
* conflictedContent: mergedContentWithMarkers,
|
|
150
|
+
* markers: [{ startLine: 10, endLine: 16, ... }]
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
36
153
|
*/
|
|
37
154
|
export interface MergeConflict {
|
|
38
|
-
/**
|
|
155
|
+
/** The type of conflict that occurred */
|
|
39
156
|
type: ConflictType;
|
|
40
|
-
/** Path to the conflicted file */
|
|
157
|
+
/** Path to the conflicted file relative to repository root */
|
|
41
158
|
path: string;
|
|
42
|
-
/** SHA of the file in base (common ancestor) */
|
|
159
|
+
/** SHA of the file in the base (common ancestor) commit */
|
|
43
160
|
baseSha?: string;
|
|
44
|
-
/** SHA of the file in our (current
|
|
161
|
+
/** SHA of the file in our (current branch) commit */
|
|
45
162
|
oursSha?: string;
|
|
46
|
-
/** SHA of the file in their (merged
|
|
163
|
+
/** SHA of the file in their (merged branch) commit */
|
|
47
164
|
theirsSha?: string;
|
|
48
|
-
/**
|
|
165
|
+
/** File mode (permissions) in the base version */
|
|
49
166
|
baseMode?: string;
|
|
50
|
-
/**
|
|
167
|
+
/** File mode (permissions) in our version */
|
|
51
168
|
oursMode?: string;
|
|
52
|
-
/**
|
|
169
|
+
/** File mode (permissions) in their version */
|
|
53
170
|
theirsMode?: string;
|
|
54
|
-
/**
|
|
171
|
+
/** Merged content with conflict markers embedded (for content conflicts) */
|
|
55
172
|
conflictedContent?: Uint8Array;
|
|
56
|
-
/** Detailed conflict
|
|
173
|
+
/** Detailed information about each conflict region in the file */
|
|
57
174
|
markers?: ConflictMarker[];
|
|
58
|
-
/** Original path if this
|
|
175
|
+
/** Original path if this conflict involves a rename */
|
|
59
176
|
originalPath?: string;
|
|
60
|
-
/** Renamed
|
|
177
|
+
/** Renamed paths when both sides renamed the same file differently */
|
|
61
178
|
renamedPaths?: {
|
|
179
|
+
/** Path the file was renamed to in our branch */
|
|
62
180
|
ours?: string;
|
|
181
|
+
/** Path the file was renamed to in their branch */
|
|
63
182
|
theirs?: string;
|
|
64
183
|
};
|
|
65
184
|
}
|
|
66
185
|
/**
|
|
67
|
-
*
|
|
186
|
+
* Configuration options for merge operations.
|
|
187
|
+
*
|
|
188
|
+
* @description
|
|
189
|
+
* These options control how the merge algorithm behaves, including
|
|
190
|
+
* whether to allow fast-forward merges, how to handle conflicts,
|
|
191
|
+
* and metadata for the resulting merge commit.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* const options: MergeOptions = {
|
|
196
|
+
* strategy: 'recursive',
|
|
197
|
+
* allowFastForward: true,
|
|
198
|
+
* message: 'Merge feature/new-feature into main',
|
|
199
|
+
* author: {
|
|
200
|
+
* name: 'Developer',
|
|
201
|
+
* email: 'dev@example.com'
|
|
202
|
+
* },
|
|
203
|
+
* detectRenames: true,
|
|
204
|
+
* renameThreshold: 60
|
|
205
|
+
* }
|
|
206
|
+
* ```
|
|
68
207
|
*/
|
|
69
208
|
export interface MergeOptions {
|
|
70
209
|
/** Merge strategy to use (default: 'recursive') */
|
|
71
210
|
strategy?: MergeStrategy;
|
|
72
|
-
/** Whether to allow fast-forward merges (default: true) */
|
|
211
|
+
/** Whether to allow fast-forward merges when possible (default: true) */
|
|
73
212
|
allowFastForward?: boolean;
|
|
74
|
-
/**
|
|
213
|
+
/** Only allow fast-forward merges; fail if not possible (default: false) */
|
|
75
214
|
fastForwardOnly?: boolean;
|
|
76
|
-
/** Automatically resolve conflicts using strategy (default: false) */
|
|
215
|
+
/** Automatically resolve conflicts using the specified strategy (default: false) */
|
|
77
216
|
autoResolve?: boolean;
|
|
78
|
-
/** Strategy
|
|
217
|
+
/** Strategy for automatic conflict resolution when autoResolve is true */
|
|
79
218
|
conflictStrategy?: 'ours' | 'theirs' | 'union';
|
|
80
|
-
/** Commit message for merge commit */
|
|
219
|
+
/** Commit message for the merge commit */
|
|
81
220
|
message?: string;
|
|
82
|
-
/**
|
|
221
|
+
/** Stage changes but do not create a merge commit (default: false) */
|
|
83
222
|
noCommit?: boolean;
|
|
84
|
-
/** Squash commits from the merged branch */
|
|
223
|
+
/** Squash all commits from the merged branch into a single change (default: false) */
|
|
85
224
|
squash?: boolean;
|
|
86
|
-
/**
|
|
225
|
+
/** Additional branch SHAs for octopus merges */
|
|
87
226
|
additionalBranches?: string[];
|
|
88
|
-
/**
|
|
227
|
+
/** Similarity threshold for rename detection (0-100, default: 50) */
|
|
89
228
|
renameThreshold?: number;
|
|
90
|
-
/**
|
|
229
|
+
/** Enable rename detection during merge (default: true) */
|
|
91
230
|
detectRenames?: boolean;
|
|
92
|
-
/**
|
|
231
|
+
/** Enable copy detection during merge (default: false) */
|
|
93
232
|
detectCopies?: boolean;
|
|
94
|
-
/** Author for the merge commit */
|
|
233
|
+
/** Author information for the merge commit */
|
|
95
234
|
author?: {
|
|
235
|
+
/** Author's name */
|
|
96
236
|
name: string;
|
|
237
|
+
/** Author's email address */
|
|
97
238
|
email: string;
|
|
239
|
+
/** Unix timestamp in seconds */
|
|
98
240
|
timestamp?: number;
|
|
241
|
+
/** Timezone offset (e.g., '+0000', '-0500') */
|
|
99
242
|
timezone?: string;
|
|
100
243
|
};
|
|
101
|
-
/** Committer for the merge commit */
|
|
244
|
+
/** Committer information for the merge commit (defaults to author if not specified) */
|
|
102
245
|
committer?: {
|
|
246
|
+
/** Committer's name */
|
|
103
247
|
name: string;
|
|
248
|
+
/** Committer's email address */
|
|
104
249
|
email: string;
|
|
250
|
+
/** Unix timestamp in seconds */
|
|
105
251
|
timestamp?: number;
|
|
252
|
+
/** Timezone offset (e.g., '+0000', '-0500') */
|
|
106
253
|
timezone?: string;
|
|
107
254
|
};
|
|
108
255
|
}
|
|
109
256
|
/**
|
|
110
|
-
* Statistics about
|
|
257
|
+
* Statistics about files changed during a merge operation.
|
|
258
|
+
*
|
|
259
|
+
* @description
|
|
260
|
+
* Provides a summary of what changes were made during the merge,
|
|
261
|
+
* useful for displaying merge summaries to users.
|
|
111
262
|
*/
|
|
112
263
|
export interface MergeStats {
|
|
113
|
-
/** Number of files added */
|
|
264
|
+
/** Number of files that were added */
|
|
114
265
|
filesAdded: number;
|
|
115
|
-
/** Number of files modified */
|
|
266
|
+
/** Number of files that were modified */
|
|
116
267
|
filesModified: number;
|
|
117
|
-
/** Number of files deleted */
|
|
268
|
+
/** Number of files that were deleted */
|
|
118
269
|
filesDeleted: number;
|
|
119
|
-
/** Number of files renamed */
|
|
270
|
+
/** Number of files that were renamed */
|
|
120
271
|
filesRenamed: number;
|
|
121
|
-
/** Number of binary files changed */
|
|
272
|
+
/** Number of binary files that were changed */
|
|
122
273
|
binaryFilesChanged: number;
|
|
123
|
-
/** Total lines added
|
|
274
|
+
/** Total lines added across all text files */
|
|
124
275
|
linesAdded: number;
|
|
125
|
-
/** Total lines removed
|
|
276
|
+
/** Total lines removed across all text files */
|
|
126
277
|
linesRemoved: number;
|
|
127
278
|
}
|
|
128
279
|
/**
|
|
129
|
-
* Result
|
|
280
|
+
* Result returned from a merge operation.
|
|
281
|
+
*
|
|
282
|
+
* @description
|
|
283
|
+
* Contains complete information about the merge outcome, including
|
|
284
|
+
* the status, any conflicts that occurred, and statistics about
|
|
285
|
+
* the changes made.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* const result = await merge(storage, oursSha, theirsSha, options)
|
|
290
|
+
*
|
|
291
|
+
* switch (result.status) {
|
|
292
|
+
* case 'fast-forward':
|
|
293
|
+
* console.log(`Fast-forwarded to ${result.treeSha}`)
|
|
294
|
+
* break
|
|
295
|
+
* case 'merged':
|
|
296
|
+
* console.log(`Created merge commit ${result.commitSha}`)
|
|
297
|
+
* break
|
|
298
|
+
* case 'conflicted':
|
|
299
|
+
* console.log(`${result.conflicts?.length} conflicts to resolve`)
|
|
300
|
+
* break
|
|
301
|
+
* case 'up-to-date':
|
|
302
|
+
* console.log('Already up to date')
|
|
303
|
+
* break
|
|
304
|
+
* }
|
|
305
|
+
* ```
|
|
130
306
|
*/
|
|
131
307
|
export interface MergeResult {
|
|
132
|
-
/**
|
|
308
|
+
/** The outcome status of the merge operation */
|
|
133
309
|
status: MergeStatus;
|
|
134
|
-
/** SHA of the
|
|
310
|
+
/** SHA of the created merge commit (if a commit was created) */
|
|
135
311
|
commitSha?: string;
|
|
136
|
-
/** SHA of the resulting tree */
|
|
312
|
+
/** SHA of the resulting merged tree */
|
|
137
313
|
treeSha?: string;
|
|
138
|
-
/**
|
|
314
|
+
/** SHA of the common ancestor commit used as merge base */
|
|
139
315
|
baseSha?: string;
|
|
140
|
-
/** SHA of the current branch before merge */
|
|
316
|
+
/** SHA of the current branch's commit before the merge */
|
|
141
317
|
oursSha: string;
|
|
142
|
-
/** SHA of the merged
|
|
318
|
+
/** SHA of the commit that was merged in */
|
|
143
319
|
theirsSha: string;
|
|
144
320
|
/** List of conflicts if status is 'conflicted' */
|
|
145
321
|
conflicts?: MergeConflict[];
|
|
146
|
-
/** Statistics about the merge */
|
|
322
|
+
/** Statistics about files changed during the merge */
|
|
147
323
|
stats?: MergeStats;
|
|
148
|
-
/**
|
|
324
|
+
/** The merge commit message */
|
|
149
325
|
message?: string;
|
|
150
|
-
/** Whether
|
|
326
|
+
/** Whether this was a fast-forward merge (no merge commit created) */
|
|
151
327
|
fastForward: boolean;
|
|
152
328
|
}
|
|
153
329
|
/**
|
|
154
|
-
*
|
|
330
|
+
* Persistent state of an in-progress merge operation.
|
|
331
|
+
*
|
|
332
|
+
* @description
|
|
333
|
+
* When a merge results in conflicts, this state is persisted to allow
|
|
334
|
+
* the user to resolve conflicts and continue the merge in a separate
|
|
335
|
+
* operation. Corresponds to Git's .git/MERGE_HEAD and related files.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```typescript
|
|
339
|
+
* const state = await storage.readMergeState()
|
|
340
|
+
* if (state) {
|
|
341
|
+
* console.log(`Merge in progress from ${state.mergeHead}`)
|
|
342
|
+
* console.log(`${state.unresolvedConflicts.length} conflicts remaining`)
|
|
343
|
+
* }
|
|
344
|
+
* ```
|
|
155
345
|
*/
|
|
156
346
|
export interface MergeState {
|
|
157
|
-
/** SHA of the commit being merged */
|
|
347
|
+
/** SHA of the commit being merged (stored in MERGE_HEAD) */
|
|
158
348
|
mergeHead: string;
|
|
159
|
-
/** SHA of
|
|
349
|
+
/** SHA of HEAD before the merge started (stored in ORIG_HEAD) */
|
|
160
350
|
origHead: string;
|
|
161
|
-
/** Commit message for the merge */
|
|
351
|
+
/** Commit message for the eventual merge commit */
|
|
162
352
|
message: string;
|
|
163
|
-
/**
|
|
353
|
+
/** Special merge mode if applicable */
|
|
164
354
|
mode?: 'squash' | 'no-ff';
|
|
165
|
-
/**
|
|
355
|
+
/** Conflicts that have not yet been resolved */
|
|
166
356
|
unresolvedConflicts: MergeConflict[];
|
|
167
|
-
/**
|
|
357
|
+
/** Conflicts that have been resolved */
|
|
168
358
|
resolvedConflicts: MergeConflict[];
|
|
169
|
-
/** Options
|
|
359
|
+
/** Options that were passed to the original merge operation */
|
|
170
360
|
options: MergeOptions;
|
|
171
361
|
}
|
|
172
362
|
/**
|
|
173
|
-
* Options for resolving
|
|
363
|
+
* Options for resolving an individual merge conflict.
|
|
364
|
+
*
|
|
365
|
+
* @description
|
|
366
|
+
* Specifies how to resolve a particular conflict. Can use one of the
|
|
367
|
+
* three-way merge versions (ours, theirs, base) or provide custom content.
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```typescript
|
|
371
|
+
* // Use our version
|
|
372
|
+
* await resolveConflict(storage, 'file.ts', { resolution: 'ours' })
|
|
373
|
+
*
|
|
374
|
+
* // Use their version
|
|
375
|
+
* await resolveConflict(storage, 'file.ts', { resolution: 'theirs' })
|
|
376
|
+
*
|
|
377
|
+
* // Provide custom merged content
|
|
378
|
+
* await resolveConflict(storage, 'file.ts', {
|
|
379
|
+
* resolution: 'custom',
|
|
380
|
+
* customContent: encoder.encode('manually merged content')
|
|
381
|
+
* })
|
|
382
|
+
* ```
|
|
174
383
|
*/
|
|
175
384
|
export interface ResolveOptions {
|
|
176
|
-
/**
|
|
385
|
+
/** Which version to use for resolution */
|
|
177
386
|
resolution: 'ours' | 'theirs' | 'base' | 'custom';
|
|
178
387
|
/** Custom content when resolution is 'custom' */
|
|
179
388
|
customContent?: Uint8Array;
|
|
180
|
-
/** Custom mode when resolution is 'custom' */
|
|
389
|
+
/** Custom file mode when resolution is 'custom' */
|
|
181
390
|
customMode?: string;
|
|
182
391
|
}
|
|
183
392
|
/**
|
|
184
|
-
* Result of conflict
|
|
393
|
+
* Result of resolving a single conflict.
|
|
394
|
+
*
|
|
395
|
+
* @description
|
|
396
|
+
* Indicates whether the conflict was successfully resolved and how
|
|
397
|
+
* many conflicts remain to be resolved before the merge can continue.
|
|
185
398
|
*/
|
|
186
399
|
export interface ResolveResult {
|
|
187
|
-
/** Whether resolution was successful */
|
|
400
|
+
/** Whether the resolution was successful */
|
|
188
401
|
success: boolean;
|
|
189
|
-
/** Path that was resolved */
|
|
402
|
+
/** Path of the file that was resolved */
|
|
190
403
|
path: string;
|
|
191
404
|
/** Error message if resolution failed */
|
|
192
405
|
error?: string;
|
|
193
|
-
/**
|
|
406
|
+
/** Number of conflicts still remaining after this resolution */
|
|
194
407
|
remainingConflicts: number;
|
|
195
408
|
}
|
|
196
409
|
/**
|
|
197
|
-
* Result of abort
|
|
410
|
+
* Result of merge management operations (abort, continue).
|
|
411
|
+
*
|
|
412
|
+
* @description
|
|
413
|
+
* Used for operations that manage merge state rather than performing
|
|
414
|
+
* the actual merge, such as aborting or continuing a conflicted merge.
|
|
198
415
|
*/
|
|
199
416
|
export interface MergeOperationResult {
|
|
200
|
-
/** Whether the operation
|
|
417
|
+
/** Whether the operation completed successfully */
|
|
201
418
|
success: boolean;
|
|
202
|
-
/** Error message if operation failed */
|
|
419
|
+
/** Error message if the operation failed */
|
|
203
420
|
error?: string;
|
|
204
|
-
/** Current HEAD SHA after operation */
|
|
421
|
+
/** Current HEAD SHA after the operation */
|
|
205
422
|
headSha?: string;
|
|
206
|
-
/**
|
|
423
|
+
/** Human-readable status message */
|
|
207
424
|
message?: string;
|
|
208
425
|
}
|
|
209
426
|
/**
|
|
210
|
-
* Extended object type that may include parsed commit/tree data
|
|
427
|
+
* Extended object type that may include parsed commit/tree data.
|
|
428
|
+
*
|
|
429
|
+
* @description
|
|
430
|
+
* Internal type used to represent Git objects that may have been
|
|
431
|
+
* pre-parsed for efficiency in testing or caching scenarios.
|
|
432
|
+
*
|
|
433
|
+
* @internal
|
|
211
434
|
*/
|
|
212
435
|
interface ExtendedObject {
|
|
436
|
+
/** Object type ('commit', 'tree', 'blob', 'tag') */
|
|
213
437
|
type: string;
|
|
438
|
+
/** Raw object data */
|
|
214
439
|
data: Uint8Array;
|
|
440
|
+
/** Pre-parsed tree SHA for commit objects */
|
|
215
441
|
tree?: string;
|
|
442
|
+
/** Pre-parsed parent SHAs for commit objects */
|
|
216
443
|
parents?: string[];
|
|
444
|
+
/** Pre-parsed entries for tree objects */
|
|
217
445
|
entries?: Array<{
|
|
218
446
|
mode: string;
|
|
219
447
|
name: string;
|
|
@@ -221,26 +449,78 @@ interface ExtendedObject {
|
|
|
221
449
|
}>;
|
|
222
450
|
}
|
|
223
451
|
/**
|
|
224
|
-
*
|
|
452
|
+
* Storage interface required for merge operations.
|
|
453
|
+
*
|
|
454
|
+
* @description
|
|
455
|
+
* Defines the storage layer abstraction that merge operations use to
|
|
456
|
+
* read and write Git objects, references, and merge state. Implementations
|
|
457
|
+
* must provide all methods for merge functionality to work correctly.
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
* ```typescript
|
|
461
|
+
* class GitStorage implements MergeStorage {
|
|
462
|
+
* async readObject(sha: string) {
|
|
463
|
+
* // Read from .git/objects
|
|
464
|
+
* }
|
|
465
|
+
* async writeObject(type: string, data: Uint8Array) {
|
|
466
|
+
* // Write to .git/objects and return SHA
|
|
467
|
+
* }
|
|
468
|
+
* // ... other methods
|
|
469
|
+
* }
|
|
470
|
+
* ```
|
|
225
471
|
*/
|
|
226
472
|
export interface MergeStorage {
|
|
227
|
-
/**
|
|
473
|
+
/**
|
|
474
|
+
* Read a Git object by its SHA.
|
|
475
|
+
* @param sha - The 40-character hexadecimal SHA
|
|
476
|
+
* @returns The object if found, null otherwise
|
|
477
|
+
*/
|
|
228
478
|
readObject(sha: string): Promise<ExtendedObject | null>;
|
|
229
|
-
/**
|
|
479
|
+
/**
|
|
480
|
+
* Write a Git object and return its SHA.
|
|
481
|
+
* @param type - Object type ('commit', 'tree', 'blob', 'tag')
|
|
482
|
+
* @param data - Raw object content
|
|
483
|
+
* @returns The SHA of the written object
|
|
484
|
+
*/
|
|
230
485
|
writeObject(type: string, data: Uint8Array): Promise<string>;
|
|
231
|
-
/**
|
|
486
|
+
/**
|
|
487
|
+
* Read a Git reference (branch, tag, etc.).
|
|
488
|
+
* @param ref - Reference path (e.g., 'refs/heads/main')
|
|
489
|
+
* @returns The SHA the reference points to, or null
|
|
490
|
+
*/
|
|
232
491
|
readRef(ref: string): Promise<string | null>;
|
|
233
|
-
/**
|
|
492
|
+
/**
|
|
493
|
+
* Write/update a Git reference.
|
|
494
|
+
* @param ref - Reference path
|
|
495
|
+
* @param sha - SHA to point the reference to
|
|
496
|
+
*/
|
|
234
497
|
writeRef(ref: string, sha: string): Promise<void>;
|
|
235
|
-
/**
|
|
498
|
+
/**
|
|
499
|
+
* Read the current merge state if a merge is in progress.
|
|
500
|
+
* @returns Merge state if present, null otherwise
|
|
501
|
+
*/
|
|
236
502
|
readMergeState(): Promise<MergeState | null>;
|
|
237
|
-
/**
|
|
503
|
+
/**
|
|
504
|
+
* Persist merge state for conflict resolution.
|
|
505
|
+
* @param state - The merge state to persist
|
|
506
|
+
*/
|
|
238
507
|
writeMergeState(state: MergeState): Promise<void>;
|
|
239
|
-
/**
|
|
508
|
+
/**
|
|
509
|
+
* Delete merge state after merge completes or is aborted.
|
|
510
|
+
*/
|
|
240
511
|
deleteMergeState(): Promise<void>;
|
|
241
|
-
/**
|
|
512
|
+
/**
|
|
513
|
+
* Stage a file in the index.
|
|
514
|
+
* @param path - File path
|
|
515
|
+
* @param sha - Blob SHA
|
|
516
|
+
* @param mode - File mode
|
|
517
|
+
* @param stage - Stage number (0 for normal, 1-3 for conflicts)
|
|
518
|
+
*/
|
|
242
519
|
stageFile(path: string, sha: string, mode: string, stage?: number): Promise<void>;
|
|
243
|
-
/**
|
|
520
|
+
/**
|
|
521
|
+
* Get all entries from the current index.
|
|
522
|
+
* @returns Map of path to index entry
|
|
523
|
+
*/
|
|
244
524
|
getIndex(): Promise<Map<string, {
|
|
245
525
|
sha: string;
|
|
246
526
|
mode: string;
|
|
@@ -250,52 +530,116 @@ export interface MergeStorage {
|
|
|
250
530
|
/**
|
|
251
531
|
* Performs a three-way merge between the current branch and another commit.
|
|
252
532
|
*
|
|
533
|
+
* @description
|
|
253
534
|
* This function implements Git's three-way merge algorithm:
|
|
254
535
|
* 1. Find the common ancestor (merge base) of the two commits
|
|
255
536
|
* 2. Compare both sides against the base to identify changes
|
|
256
537
|
* 3. Apply non-conflicting changes automatically
|
|
257
538
|
* 4. Identify and report conflicts for manual resolution
|
|
258
539
|
*
|
|
259
|
-
*
|
|
540
|
+
* The merge can result in several outcomes:
|
|
541
|
+
* - **fast-forward**: If the current branch is an ancestor of the target,
|
|
542
|
+
* the branch pointer is simply moved forward
|
|
543
|
+
* - **merged**: Changes were successfully combined into a merge commit
|
|
544
|
+
* - **conflicted**: Some changes conflict and require manual resolution
|
|
545
|
+
* - **up-to-date**: The target is already merged; nothing to do
|
|
546
|
+
*
|
|
547
|
+
* @param storage - The storage interface for reading/writing Git objects
|
|
260
548
|
* @param oursSha - SHA of the current branch's HEAD commit
|
|
261
|
-
* @param theirsSha - SHA of the commit to merge
|
|
262
|
-
* @param options -
|
|
263
|
-
*
|
|
549
|
+
* @param theirsSha - SHA of the commit to merge into the current branch
|
|
550
|
+
* @param options - Configuration options for the merge operation
|
|
551
|
+
*
|
|
552
|
+
* @returns A promise resolving to the merge result with status and any conflicts
|
|
553
|
+
*
|
|
554
|
+
* @throws {Error} When commit objects cannot be read
|
|
555
|
+
* @throws {Error} When tree objects cannot be parsed
|
|
556
|
+
* @throws {Error} When fastForwardOnly is true but fast-forward is not possible
|
|
264
557
|
*
|
|
265
558
|
* @example
|
|
266
559
|
* ```typescript
|
|
560
|
+
* // Basic merge
|
|
267
561
|
* const result = await merge(storage, 'abc123', 'def456', {
|
|
268
|
-
* message: 'Merge feature branch'
|
|
269
|
-
* allowFastForward: true
|
|
562
|
+
* message: 'Merge feature branch'
|
|
270
563
|
* })
|
|
271
564
|
*
|
|
272
|
-
* if (result.status === '
|
|
273
|
-
* console.log('
|
|
565
|
+
* if (result.status === 'merged') {
|
|
566
|
+
* console.log('Merge successful:', result.commitSha)
|
|
567
|
+
* }
|
|
568
|
+
* ```
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```typescript
|
|
572
|
+
* // Fast-forward only merge
|
|
573
|
+
* try {
|
|
574
|
+
* const result = await merge(storage, 'abc123', 'def456', {
|
|
575
|
+
* fastForwardOnly: true
|
|
576
|
+
* })
|
|
577
|
+
* console.log('Fast-forwarded to:', result.treeSha)
|
|
578
|
+
* } catch (error) {
|
|
579
|
+
* console.log('Cannot fast-forward, branches have diverged')
|
|
274
580
|
* }
|
|
275
581
|
* ```
|
|
582
|
+
*
|
|
583
|
+
* @example
|
|
584
|
+
* ```typescript
|
|
585
|
+
* // Merge with auto-resolve conflicts using 'ours' strategy
|
|
586
|
+
* const result = await merge(storage, 'abc123', 'def456', {
|
|
587
|
+
* autoResolve: true,
|
|
588
|
+
* conflictStrategy: 'ours',
|
|
589
|
+
* message: 'Merge with our changes taking precedence'
|
|
590
|
+
* })
|
|
591
|
+
* ```
|
|
276
592
|
*/
|
|
277
593
|
export declare function merge(storage: MergeStorage, oursSha: string, theirsSha: string, options?: MergeOptions): Promise<MergeResult>;
|
|
278
594
|
/**
|
|
279
|
-
* Resolves a single merge conflict.
|
|
595
|
+
* Resolves a single merge conflict with the specified strategy.
|
|
280
596
|
*
|
|
597
|
+
* @description
|
|
281
598
|
* After a merge results in conflicts, use this function to resolve
|
|
282
|
-
* individual files.
|
|
283
|
-
*
|
|
599
|
+
* individual files. The resolution can use one of the three versions
|
|
600
|
+
* (ours, theirs, base) or provide custom merged content.
|
|
284
601
|
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* @
|
|
602
|
+
* Once all conflicts are resolved, use {@link continueMerge} to create
|
|
603
|
+
* the merge commit and complete the operation.
|
|
604
|
+
*
|
|
605
|
+
* @param storage - The storage interface for reading/writing objects
|
|
606
|
+
* @param path - Path to the conflicted file to resolve
|
|
607
|
+
* @param options - Resolution options specifying which version to use
|
|
608
|
+
*
|
|
609
|
+
* @returns A promise resolving to the resolution result
|
|
610
|
+
*
|
|
611
|
+
* @throws {Error} When no merge is in progress
|
|
612
|
+
* @throws {Error} When the specified path has no conflict
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* ```typescript
|
|
616
|
+
* // Resolve using our version
|
|
617
|
+
* const result = await resolveConflict(storage, 'src/file.ts', {
|
|
618
|
+
* resolution: 'ours'
|
|
619
|
+
* })
|
|
620
|
+
* console.log(`${result.remainingConflicts} conflicts remaining`)
|
|
621
|
+
* ```
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* ```typescript
|
|
625
|
+
* // Resolve using their version
|
|
626
|
+
* await resolveConflict(storage, 'config.json', {
|
|
627
|
+
* resolution: 'theirs'
|
|
628
|
+
* })
|
|
629
|
+
* ```
|
|
289
630
|
*
|
|
290
631
|
* @example
|
|
291
632
|
* ```typescript
|
|
292
|
-
* // Resolve
|
|
293
|
-
*
|
|
633
|
+
* // Resolve with manually merged content
|
|
634
|
+
* const mergedContent = new TextEncoder().encode(`
|
|
635
|
+
* // Manually resolved: kept both features
|
|
636
|
+
* export function feature1() { ... }
|
|
637
|
+
* export function feature2() { ... }
|
|
638
|
+
* `)
|
|
294
639
|
*
|
|
295
|
-
*
|
|
296
|
-
* await resolveConflict(storage, 'src/file.ts', {
|
|
640
|
+
* await resolveConflict(storage, 'src/features.ts', {
|
|
297
641
|
* resolution: 'custom',
|
|
298
|
-
* customContent:
|
|
642
|
+
* customContent: mergedContent
|
|
299
643
|
* })
|
|
300
644
|
* ```
|
|
301
645
|
*/
|
|
@@ -303,17 +647,28 @@ export declare function resolveConflict(storage: MergeStorage, path: string, opt
|
|
|
303
647
|
/**
|
|
304
648
|
* Aborts an in-progress merge operation.
|
|
305
649
|
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
650
|
+
* @description
|
|
651
|
+
* Cancels the current merge and restores the repository to its state
|
|
652
|
+
* before the merge began. Any conflict resolutions or staged changes
|
|
653
|
+
* from the merge will be discarded.
|
|
654
|
+
*
|
|
655
|
+
* This is equivalent to `git merge --abort`.
|
|
308
656
|
*
|
|
309
657
|
* @param storage - The storage interface
|
|
310
|
-
*
|
|
658
|
+
*
|
|
659
|
+
* @returns A promise resolving to the operation result
|
|
660
|
+
*
|
|
661
|
+
* @throws {Error} When no merge is in progress
|
|
311
662
|
*
|
|
312
663
|
* @example
|
|
313
664
|
* ```typescript
|
|
665
|
+
* // User decides to cancel the merge
|
|
314
666
|
* const result = await abortMerge(storage)
|
|
667
|
+
*
|
|
315
668
|
* if (result.success) {
|
|
316
|
-
* console.log('Merge aborted, HEAD
|
|
669
|
+
* console.log('Merge aborted, HEAD restored to', result.headSha)
|
|
670
|
+
* } else {
|
|
671
|
+
* console.error('Failed to abort:', result.error)
|
|
317
672
|
* }
|
|
318
673
|
* ```
|
|
319
674
|
*/
|
|
@@ -321,39 +676,105 @@ export declare function abortMerge(storage: MergeStorage): Promise<MergeOperatio
|
|
|
321
676
|
/**
|
|
322
677
|
* Continues a merge after all conflicts have been resolved.
|
|
323
678
|
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
679
|
+
* @description
|
|
680
|
+
* After resolving all conflicts using {@link resolveConflict}, call this
|
|
681
|
+
* function to create the merge commit and complete the merge operation.
|
|
682
|
+
* The merge state will be cleaned up automatically.
|
|
683
|
+
*
|
|
684
|
+
* This is equivalent to `git merge --continue` or `git commit` after
|
|
685
|
+
* resolving conflicts.
|
|
326
686
|
*
|
|
327
687
|
* @param storage - The storage interface
|
|
328
|
-
* @param message - Optional commit message (overrides stored message)
|
|
329
|
-
*
|
|
688
|
+
* @param message - Optional commit message (overrides the stored message)
|
|
689
|
+
*
|
|
690
|
+
* @returns A promise resolving to the operation result with the new commit SHA
|
|
691
|
+
*
|
|
692
|
+
* @throws {Error} When no merge is in progress
|
|
693
|
+
* @throws {Error} When unresolved conflicts remain
|
|
330
694
|
*
|
|
331
695
|
* @example
|
|
332
696
|
* ```typescript
|
|
333
697
|
* // After resolving all conflicts
|
|
334
698
|
* const result = await continueMerge(storage)
|
|
699
|
+
*
|
|
335
700
|
* if (result.success) {
|
|
336
|
-
* console.log('Merge completed
|
|
701
|
+
* console.log('Merge completed:', result.headSha)
|
|
702
|
+
* } else {
|
|
703
|
+
* console.error('Cannot continue:', result.error)
|
|
337
704
|
* }
|
|
338
705
|
* ```
|
|
706
|
+
*
|
|
707
|
+
* @example
|
|
708
|
+
* ```typescript
|
|
709
|
+
* // Continue with a custom commit message
|
|
710
|
+
* const result = await continueMerge(storage, 'Merge feature-x with conflict resolution')
|
|
711
|
+
* ```
|
|
339
712
|
*/
|
|
340
713
|
export declare function continueMerge(storage: MergeStorage, message?: string): Promise<MergeOperationResult>;
|
|
341
714
|
/**
|
|
342
|
-
* Finds the best common ancestor (merge base)
|
|
715
|
+
* Finds the best common ancestor (merge base) of two commits.
|
|
343
716
|
*
|
|
344
|
-
* @
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
717
|
+
* @description
|
|
718
|
+
* Implements the merge base algorithm by finding the most recent commit
|
|
719
|
+
* that is an ancestor of both input commits. This is the commit from
|
|
720
|
+
* which both branches diverged.
|
|
721
|
+
*
|
|
722
|
+
* Uses a breadth-first search from both commits to find their
|
|
723
|
+
* intersection in the commit graph.
|
|
724
|
+
*
|
|
725
|
+
* @param storage - The storage interface for reading commit objects
|
|
726
|
+
* @param commit1 - SHA of the first commit
|
|
727
|
+
* @param commit2 - SHA of the second commit
|
|
728
|
+
*
|
|
729
|
+
* @returns A promise resolving to the merge base SHA, or null if no common ancestor exists
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* ```typescript
|
|
733
|
+
* const base = await findMergeBase(storage, 'feature-sha', 'main-sha')
|
|
734
|
+
* if (base) {
|
|
735
|
+
* console.log('Common ancestor:', base)
|
|
736
|
+
* } else {
|
|
737
|
+
* console.log('No common history')
|
|
738
|
+
* }
|
|
739
|
+
* ```
|
|
348
740
|
*/
|
|
349
741
|
export declare function findMergeBase(storage: MergeStorage, commit1: string, commit2: string): Promise<string | null>;
|
|
350
742
|
/**
|
|
351
743
|
* Performs a content-level three-way merge on text files.
|
|
352
744
|
*
|
|
745
|
+
* @description
|
|
746
|
+
* Takes three versions of a file (base, ours, theirs) and attempts to
|
|
747
|
+
* automatically merge them. Non-conflicting changes are combined
|
|
748
|
+
* automatically. Conflicting changes are marked with standard Git
|
|
749
|
+
* conflict markers.
|
|
750
|
+
*
|
|
751
|
+
* The algorithm:
|
|
752
|
+
* 1. Compute the diff hunks from base to ours
|
|
753
|
+
* 2. Compute the diff hunks from base to theirs
|
|
754
|
+
* 3. Process hunks in order, detecting overlaps
|
|
755
|
+
* 4. Non-overlapping hunks are applied automatically
|
|
756
|
+
* 5. Overlapping hunks with identical changes are deduplicated
|
|
757
|
+
* 6. Overlapping hunks with different changes create conflict markers
|
|
758
|
+
*
|
|
353
759
|
* @param base - Content of the base (common ancestor) version
|
|
354
|
-
* @param ours - Content of our (current) version
|
|
355
|
-
* @param theirs - Content of their (merged) version
|
|
356
|
-
*
|
|
760
|
+
* @param ours - Content of our (current branch) version
|
|
761
|
+
* @param theirs - Content of their (merged branch) version
|
|
762
|
+
*
|
|
763
|
+
* @returns Object containing merged content, conflict flag, and marker locations
|
|
764
|
+
*
|
|
765
|
+
* @example
|
|
766
|
+
* ```typescript
|
|
767
|
+
* const result = mergeContent(baseContent, oursContent, theirsContent)
|
|
768
|
+
*
|
|
769
|
+
* if (result.hasConflicts) {
|
|
770
|
+
* console.log('Content has conflicts at:', result.markers)
|
|
771
|
+
* // Write file with conflict markers for manual resolution
|
|
772
|
+
* await writeFile(path, result.merged)
|
|
773
|
+
* } else {
|
|
774
|
+
* console.log('Content merged cleanly')
|
|
775
|
+
* await writeFile(path, result.merged)
|
|
776
|
+
* }
|
|
777
|
+
* ```
|
|
357
778
|
*/
|
|
358
779
|
export declare function mergeContent(base: Uint8Array, ours: Uint8Array, theirs: Uint8Array): {
|
|
359
780
|
merged: Uint8Array;
|
|
@@ -361,24 +782,73 @@ export declare function mergeContent(base: Uint8Array, ours: Uint8Array, theirs:
|
|
|
361
782
|
markers: ConflictMarker[];
|
|
362
783
|
};
|
|
363
784
|
/**
|
|
364
|
-
*
|
|
785
|
+
* Determines if a file is binary (non-text) based on its content.
|
|
786
|
+
*
|
|
787
|
+
* @description
|
|
788
|
+
* Uses Git's heuristic: a file is considered binary if it contains
|
|
789
|
+
* null bytes (0x00) within the first 8000 bytes, or if it has
|
|
790
|
+
* specific binary file magic numbers (PNG, JPEG, GIF).
|
|
791
|
+
*
|
|
792
|
+
* Binary files cannot be automatically merged and always result
|
|
793
|
+
* in conflicts when both sides modify them.
|
|
794
|
+
*
|
|
795
|
+
* @param content - File content to analyze
|
|
365
796
|
*
|
|
366
|
-
* @
|
|
367
|
-
*
|
|
797
|
+
* @returns true if the file appears to be binary, false for text files
|
|
798
|
+
*
|
|
799
|
+
* @example
|
|
800
|
+
* ```typescript
|
|
801
|
+
* const content = await readFile('image.png')
|
|
802
|
+
* if (isBinaryFile(content)) {
|
|
803
|
+
* console.log('Cannot perform text merge on binary file')
|
|
804
|
+
* }
|
|
805
|
+
* ```
|
|
368
806
|
*/
|
|
369
807
|
export declare function isBinaryFile(content: Uint8Array): boolean;
|
|
370
808
|
/**
|
|
371
809
|
* Gets the current merge state if a merge is in progress.
|
|
372
810
|
*
|
|
811
|
+
* @description
|
|
812
|
+
* Returns the persisted merge state, which includes information about
|
|
813
|
+
* the merge in progress, any unresolved conflicts, and the original
|
|
814
|
+
* merge options.
|
|
815
|
+
*
|
|
373
816
|
* @param storage - The storage interface
|
|
374
|
-
*
|
|
817
|
+
*
|
|
818
|
+
* @returns A promise resolving to the merge state, or null if no merge is in progress
|
|
819
|
+
*
|
|
820
|
+
* @example
|
|
821
|
+
* ```typescript
|
|
822
|
+
* const state = await getMergeState(storage)
|
|
823
|
+
* if (state) {
|
|
824
|
+
* console.log('Merging', state.mergeHead, 'into', state.origHead)
|
|
825
|
+
* console.log('Unresolved conflicts:', state.unresolvedConflicts.length)
|
|
826
|
+
* } else {
|
|
827
|
+
* console.log('No merge in progress')
|
|
828
|
+
* }
|
|
829
|
+
* ```
|
|
375
830
|
*/
|
|
376
831
|
export declare function getMergeState(storage: MergeStorage): Promise<MergeState | null>;
|
|
377
832
|
/**
|
|
378
833
|
* Checks if a merge is currently in progress.
|
|
379
834
|
*
|
|
835
|
+
* @description
|
|
836
|
+
* Quick check to determine if there's an active merge that hasn't
|
|
837
|
+
* been completed or aborted. Useful for UI state and command validation.
|
|
838
|
+
*
|
|
380
839
|
* @param storage - The storage interface
|
|
381
|
-
*
|
|
840
|
+
*
|
|
841
|
+
* @returns A promise resolving to true if a merge is in progress
|
|
842
|
+
*
|
|
843
|
+
* @example
|
|
844
|
+
* ```typescript
|
|
845
|
+
* if (await isMergeInProgress(storage)) {
|
|
846
|
+
* console.log('Please complete or abort the current merge first')
|
|
847
|
+
* } else {
|
|
848
|
+
* // Safe to start a new merge
|
|
849
|
+
* await merge(storage, oursSha, theirsSha, options)
|
|
850
|
+
* }
|
|
851
|
+
* ```
|
|
382
852
|
*/
|
|
383
853
|
export declare function isMergeInProgress(storage: MergeStorage): Promise<boolean>;
|
|
384
854
|
export {};
|