@statewalker/vcs-commands 0.1.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.
- package/LICENSE +21 -0
- package/README.md +591 -0
- package/dist/commands/add-command.d.ts +170 -0
- package/dist/commands/add-command.d.ts.map +1 -0
- package/dist/commands/blame-command.d.ts +267 -0
- package/dist/commands/blame-command.d.ts.map +1 -0
- package/dist/commands/branch-command.d.ts +211 -0
- package/dist/commands/branch-command.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +261 -0
- package/dist/commands/checkout-command.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +128 -0
- package/dist/commands/cherry-pick-command.d.ts.map +1 -0
- package/dist/commands/clean-command.d.ts +91 -0
- package/dist/commands/clean-command.d.ts.map +1 -0
- package/dist/commands/clone-command.d.ts +233 -0
- package/dist/commands/clone-command.d.ts.map +1 -0
- package/dist/commands/commit-command.d.ts +199 -0
- package/dist/commands/commit-command.d.ts.map +1 -0
- package/dist/commands/describe-command.d.ts +175 -0
- package/dist/commands/describe-command.d.ts.map +1 -0
- package/dist/commands/diff-command.d.ts +96 -0
- package/dist/commands/diff-command.d.ts.map +1 -0
- package/dist/commands/fetch-command.d.ts +266 -0
- package/dist/commands/fetch-command.d.ts.map +1 -0
- package/dist/commands/gc-command.d.ts +83 -0
- package/dist/commands/gc-command.d.ts.map +1 -0
- package/dist/commands/index.d.ts +32 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +2 -0
- package/dist/commands/init-command.d.ts +175 -0
- package/dist/commands/init-command.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts +246 -0
- package/dist/commands/log-command.d.ts.map +1 -0
- package/dist/commands/ls-remote-command.d.ts +122 -0
- package/dist/commands/ls-remote-command.d.ts.map +1 -0
- package/dist/commands/merge-command.d.ts +169 -0
- package/dist/commands/merge-command.d.ts.map +1 -0
- package/dist/commands/pack-refs-command.d.ts +57 -0
- package/dist/commands/pack-refs-command.d.ts.map +1 -0
- package/dist/commands/pull-command.d.ts +111 -0
- package/dist/commands/pull-command.d.ts.map +1 -0
- package/dist/commands/push-command.d.ts +220 -0
- package/dist/commands/push-command.d.ts.map +1 -0
- package/dist/commands/rebase-command.d.ts +186 -0
- package/dist/commands/rebase-command.d.ts.map +1 -0
- package/dist/commands/reflog-command.d.ts +45 -0
- package/dist/commands/reflog-command.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +205 -0
- package/dist/commands/remote-command.d.ts.map +1 -0
- package/dist/commands/reset-command.d.ts +114 -0
- package/dist/commands/reset-command.d.ts.map +1 -0
- package/dist/commands/revert-command.d.ts +129 -0
- package/dist/commands/revert-command.d.ts.map +1 -0
- package/dist/commands/rm-command.d.ts +72 -0
- package/dist/commands/rm-command.d.ts.map +1 -0
- package/dist/commands/stash-apply-command.d.ts +132 -0
- package/dist/commands/stash-apply-command.d.ts.map +1 -0
- package/dist/commands/stash-create-command.d.ts +137 -0
- package/dist/commands/stash-create-command.d.ts.map +1 -0
- package/dist/commands/stash-drop-command.d.ts +63 -0
- package/dist/commands/stash-drop-command.d.ts.map +1 -0
- package/dist/commands/stash-list-command.d.ts +42 -0
- package/dist/commands/stash-list-command.d.ts.map +1 -0
- package/dist/commands/status-command.d.ts +55 -0
- package/dist/commands/status-command.d.ts.map +1 -0
- package/dist/commands/tag-command.d.ts +155 -0
- package/dist/commands/tag-command.d.ts.map +1 -0
- package/dist/commands/tree-restore.d.ts +51 -0
- package/dist/commands/tree-restore.d.ts.map +1 -0
- package/dist/commands-COO4tJhv.js +10274 -0
- package/dist/core-commands/add.command.d.ts +71 -0
- package/dist/core-commands/add.command.d.ts.map +1 -0
- package/dist/core-commands/add.command.impl.d.ts +53 -0
- package/dist/core-commands/add.command.impl.d.ts.map +1 -0
- package/dist/core-commands/checkout.command.d.ts +103 -0
- package/dist/core-commands/checkout.command.d.ts.map +1 -0
- package/dist/core-commands/checkout.command.impl.d.ts +114 -0
- package/dist/core-commands/checkout.command.impl.d.ts.map +1 -0
- package/dist/core-commands/index.d.ts +6 -0
- package/dist/core-commands/index.d.ts.map +1 -0
- package/dist/errors/add-errors.d.ts +16 -0
- package/dist/errors/add-errors.d.ts.map +1 -0
- package/dist/errors/checkout-errors.d.ts +24 -0
- package/dist/errors/checkout-errors.d.ts.map +1 -0
- package/dist/errors/command-errors.d.ts +38 -0
- package/dist/errors/command-errors.d.ts.map +1 -0
- package/dist/errors/commit-errors.d.ts +27 -0
- package/dist/errors/commit-errors.d.ts.map +1 -0
- package/dist/errors/git-api-error.d.ts +9 -0
- package/dist/errors/git-api-error.d.ts.map +1 -0
- package/dist/errors/index.d.ts +13 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +509 -0
- package/dist/errors/merge-errors.d.ts +63 -0
- package/dist/errors/merge-errors.d.ts.map +1 -0
- package/dist/errors/rebase-errors.d.ts +21 -0
- package/dist/errors/rebase-errors.d.ts.map +1 -0
- package/dist/errors/ref-errors.d.ts +63 -0
- package/dist/errors/ref-errors.d.ts.map +1 -0
- package/dist/errors/remote-errors.d.ts +16 -0
- package/dist/errors/remote-errors.d.ts.map +1 -0
- package/dist/errors/stash-errors.d.ts +24 -0
- package/dist/errors/stash-errors.d.ts.map +1 -0
- package/dist/errors/tag-errors.d.ts +11 -0
- package/dist/errors/tag-errors.d.ts.map +1 -0
- package/dist/errors/transport-errors.d.ts +42 -0
- package/dist/errors/transport-errors.d.ts.map +1 -0
- package/dist/git-command.d.ts +139 -0
- package/dist/git-command.d.ts.map +1 -0
- package/dist/git.d.ts +637 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/pack-import/index.d.ts +8 -0
- package/dist/pack-import/index.d.ts.map +1 -0
- package/dist/pack-import/pack-import.d.ts +11 -0
- package/dist/pack-import/pack-import.d.ts.map +1 -0
- package/dist/remote-config/index.d.ts +7 -0
- package/dist/remote-config/index.d.ts.map +1 -0
- package/dist/remote-config/remote-config-store.d.ts +93 -0
- package/dist/remote-config/remote-config-store.d.ts.map +1 -0
- package/dist/rename/index.d.ts +5 -0
- package/dist/rename/index.d.ts.map +1 -0
- package/dist/rename/similarity-index.d.ts +64 -0
- package/dist/rename/similarity-index.d.ts.map +1 -0
- package/dist/results/cherry-pick-result.d.ts +33 -0
- package/dist/results/cherry-pick-result.d.ts.map +1 -0
- package/dist/results/clone-result.d.ts +24 -0
- package/dist/results/clone-result.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +77 -0
- package/dist/results/diff-entry.d.ts.map +1 -0
- package/dist/results/diff-formatter.d.ts +149 -0
- package/dist/results/diff-formatter.d.ts.map +1 -0
- package/dist/results/fetch-result.d.ts +78 -0
- package/dist/results/fetch-result.d.ts.map +1 -0
- package/dist/results/index.d.ts +14 -0
- package/dist/results/index.d.ts.map +1 -0
- package/dist/results/index.js +247 -0
- package/dist/results/init-result.d.ts +23 -0
- package/dist/results/init-result.d.ts.map +1 -0
- package/dist/results/merge-result.d.ts +117 -0
- package/dist/results/merge-result.d.ts.map +1 -0
- package/dist/results/pull-result.d.ts +24 -0
- package/dist/results/pull-result.d.ts.map +1 -0
- package/dist/results/push-result.d.ts +71 -0
- package/dist/results/push-result.d.ts.map +1 -0
- package/dist/results/rebase-result.d.ts +108 -0
- package/dist/results/rebase-result.d.ts.map +1 -0
- package/dist/results/revert-result.d.ts +33 -0
- package/dist/results/revert-result.d.ts.map +1 -0
- package/dist/results/stash-result.d.ts +48 -0
- package/dist/results/stash-result.d.ts.map +1 -0
- package/dist/results/status-result.d.ts +48 -0
- package/dist/results/status-result.d.ts.map +1 -0
- package/dist/status-result-BwAyxq6R.js +409 -0
- package/dist/transport-command.d.ts +83 -0
- package/dist/transport-command.d.ts.map +1 -0
- package/dist/tree-merge/index.d.ts +8 -0
- package/dist/tree-merge/index.d.ts.map +1 -0
- package/dist/tree-merge/tree-merge.d.ts +41 -0
- package/dist/tree-merge/tree-merge.d.ts.map +1 -0
- package/dist/types.d.ts +64 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present StateWalker Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
# @statewalker/vcs-commands
|
|
2
|
+
|
|
3
|
+
High-level Git command API for building version control applications.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides a Git-like command interface for VCS operations. Rather than working directly with low-level stores, you interact through familiar commands like `add`, `commit`, `push`, and `merge`. Each command encapsulates the complex multi-step workflows into a simple, type-safe API.
|
|
8
|
+
|
|
9
|
+
The design follows the command pattern with a fluent builder interface. You create commands through a `Git` factory, configure them with chainable methods, and execute with a single `call()`. This approach mirrors how developers interact with Git while providing the type safety and error handling expected from a library.
|
|
10
|
+
|
|
11
|
+
Commands work with any storage backend that implements the required store interfaces. Whether your repository lives in the filesystem, SQLite, IndexedDB, or memory, the same commands work identically. For remote operations like fetch and push, the package integrates with the transport layer to handle protocol negotiation and data transfer.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @statewalker/vcs-commands
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Dependencies:**
|
|
20
|
+
- `@statewalker/vcs-core` - Core types, store interfaces, and repository factories
|
|
21
|
+
- `@statewalker/vcs-transport` - Remote protocol implementation
|
|
22
|
+
- `@statewalker/vcs-utils` - Utility functions
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { Git } from "@statewalker/vcs-commands";
|
|
28
|
+
import { createWorkingCopy } from "@statewalker/vcs-core";
|
|
29
|
+
import { createNodeFilesApi } from "@statewalker/vcs-utils-node/files";
|
|
30
|
+
import * as fs from "node:fs/promises";
|
|
31
|
+
|
|
32
|
+
// Create a Git-compatible working copy
|
|
33
|
+
const files = createNodeFilesApi({ fs, rootDir: "/path/to/repo" });
|
|
34
|
+
const workingCopy = await createWorkingCopy(files, ".git");
|
|
35
|
+
|
|
36
|
+
// Create the Git command interface
|
|
37
|
+
const git = Git.fromWorkingCopy(workingCopy);
|
|
38
|
+
|
|
39
|
+
// Stage and commit changes
|
|
40
|
+
await git.add().addFilepattern(".").call();
|
|
41
|
+
await git.commit().setMessage("Initial commit").call();
|
|
42
|
+
|
|
43
|
+
// Check status
|
|
44
|
+
const status = await git.status().call();
|
|
45
|
+
console.log("Clean:", status.isClean());
|
|
46
|
+
|
|
47
|
+
// Clean up
|
|
48
|
+
git.dispose();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Public API
|
|
52
|
+
|
|
53
|
+
### Main Export
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import {
|
|
57
|
+
// Main entry point
|
|
58
|
+
Git,
|
|
59
|
+
GitCommand,
|
|
60
|
+
TransportCommand,
|
|
61
|
+
|
|
62
|
+
// Re-exported core types
|
|
63
|
+
type WorkingCopy,
|
|
64
|
+
type History,
|
|
65
|
+
type Checkout,
|
|
66
|
+
type Worktree,
|
|
67
|
+
type Staging,
|
|
68
|
+
|
|
69
|
+
// Enums
|
|
70
|
+
ResetMode,
|
|
71
|
+
ListBranchMode,
|
|
72
|
+
} from "@statewalker/vcs-commands";
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Sub-exports
|
|
76
|
+
|
|
77
|
+
| Export Path | Description |
|
|
78
|
+
|-------------|-------------|
|
|
79
|
+
| `@statewalker/vcs-commands/commands` | Individual command classes |
|
|
80
|
+
| `@statewalker/vcs-commands/errors` | Error types |
|
|
81
|
+
| `@statewalker/vcs-commands/results` | Result types and enums |
|
|
82
|
+
|
|
83
|
+
### Git Class Methods
|
|
84
|
+
|
|
85
|
+
The `Git` class provides factory methods for all commands:
|
|
86
|
+
|
|
87
|
+
| Category | Methods |
|
|
88
|
+
|----------|---------|
|
|
89
|
+
| **Staging** | `add()`, `rm()`, `status()` |
|
|
90
|
+
| **Committing** | `commit()`, `log()` |
|
|
91
|
+
| **Branches** | `branchCreate()`, `branchDelete()`, `branchList()`, `branchRename()`, `checkout()` |
|
|
92
|
+
| **Tags** | `tag()`, `tagDelete()`, `tagList()` |
|
|
93
|
+
| **History** | `reset()`, `rebase()`, `merge()`, `cherryPick()`, `revert()` |
|
|
94
|
+
| **Inspection** | `diff()`, `describe()` |
|
|
95
|
+
| **Remote** | `fetch()`, `push()`, `pull()`, `clone()`, `lsRemote()` |
|
|
96
|
+
| **Remotes** | `remoteAdd()`, `remoteRemove()`, `remoteList()`, `remoteSetUrl()` |
|
|
97
|
+
| **Stash** | `stashCreate()`, `stashApply()`, `stashDrop()`, `stashList()` |
|
|
98
|
+
|
|
99
|
+
## Usage Examples
|
|
100
|
+
|
|
101
|
+
### Staging and Committing
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { Git } from "@statewalker/vcs-commands";
|
|
105
|
+
|
|
106
|
+
// Stage specific files
|
|
107
|
+
await git.add()
|
|
108
|
+
.addFilepattern("src/")
|
|
109
|
+
.addFilepattern("package.json")
|
|
110
|
+
.call();
|
|
111
|
+
|
|
112
|
+
// Stage all changes including deletions
|
|
113
|
+
await git.add()
|
|
114
|
+
.addFilepattern(".")
|
|
115
|
+
.setUpdate(true)
|
|
116
|
+
.call();
|
|
117
|
+
|
|
118
|
+
// Create a commit
|
|
119
|
+
const commitId = await git.commit()
|
|
120
|
+
.setMessage("Add new feature")
|
|
121
|
+
.setAuthor({ name: "Developer", email: "dev@example.com" })
|
|
122
|
+
.call();
|
|
123
|
+
|
|
124
|
+
// Amend the previous commit
|
|
125
|
+
await git.commit()
|
|
126
|
+
.setMessage("Add new feature (fixed)")
|
|
127
|
+
.setAmend(true)
|
|
128
|
+
.call();
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Branch Operations
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
// Create a new branch
|
|
135
|
+
await git.branchCreate()
|
|
136
|
+
.setName("feature/login")
|
|
137
|
+
.call();
|
|
138
|
+
|
|
139
|
+
// Create and switch to a new branch
|
|
140
|
+
await git.branchCreate()
|
|
141
|
+
.setName("feature/login")
|
|
142
|
+
.setStartPoint("main")
|
|
143
|
+
.call();
|
|
144
|
+
await git.checkout()
|
|
145
|
+
.setName("feature/login")
|
|
146
|
+
.call();
|
|
147
|
+
|
|
148
|
+
// List all branches
|
|
149
|
+
const branches = await git.branchList()
|
|
150
|
+
.setListMode(ListBranchMode.ALL)
|
|
151
|
+
.call();
|
|
152
|
+
for (const branch of branches) {
|
|
153
|
+
console.log(branch.name, branch.objectId);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Delete a merged branch
|
|
157
|
+
await git.branchDelete()
|
|
158
|
+
.setBranchNames("feature/old")
|
|
159
|
+
.call();
|
|
160
|
+
|
|
161
|
+
// Force delete unmerged branch
|
|
162
|
+
await git.branchDelete()
|
|
163
|
+
.setBranchNames("feature/abandoned")
|
|
164
|
+
.setForce(true)
|
|
165
|
+
.call();
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Working with History
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
// View commit log
|
|
172
|
+
for await (const commit of git.log().setMaxCount(10).call()) {
|
|
173
|
+
console.log(`${commit.id.slice(0, 7)} ${commit.message.split("\n")[0]}`);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Log with filters
|
|
177
|
+
const commits = git.log()
|
|
178
|
+
.setMaxCount(50)
|
|
179
|
+
.setAuthor("developer@example.com")
|
|
180
|
+
.addPath("src/")
|
|
181
|
+
.call();
|
|
182
|
+
|
|
183
|
+
// Reset to previous commit (mixed mode - keeps changes unstaged)
|
|
184
|
+
await git.reset()
|
|
185
|
+
.setRef("HEAD~1")
|
|
186
|
+
.setMode(ResetMode.MIXED)
|
|
187
|
+
.call();
|
|
188
|
+
|
|
189
|
+
// Hard reset (discards all changes)
|
|
190
|
+
await git.reset()
|
|
191
|
+
.setRef("main")
|
|
192
|
+
.setMode(ResetMode.HARD)
|
|
193
|
+
.call();
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Merging and Rebasing
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import { MergeStatus, FastForwardMode } from "@statewalker/vcs-commands/results";
|
|
200
|
+
|
|
201
|
+
// Merge a branch
|
|
202
|
+
const result = await git.merge()
|
|
203
|
+
.include("feature/login")
|
|
204
|
+
.call();
|
|
205
|
+
|
|
206
|
+
if (result.status === MergeStatus.CONFLICTING) {
|
|
207
|
+
console.log("Conflicts in:", result.conflicts);
|
|
208
|
+
// Resolve conflicts, then commit
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Merge with no fast-forward (always create merge commit)
|
|
212
|
+
await git.merge()
|
|
213
|
+
.include("feature/login")
|
|
214
|
+
.setFastForward(FastForwardMode.NO_FF)
|
|
215
|
+
.setMessage("Merge feature/login")
|
|
216
|
+
.call();
|
|
217
|
+
|
|
218
|
+
// Rebase onto main
|
|
219
|
+
const rebaseResult = await git.rebase()
|
|
220
|
+
.setUpstream("main")
|
|
221
|
+
.call();
|
|
222
|
+
|
|
223
|
+
// Continue after resolving conflicts
|
|
224
|
+
await git.rebase()
|
|
225
|
+
.setOperation("continue")
|
|
226
|
+
.call();
|
|
227
|
+
|
|
228
|
+
// Abort rebase
|
|
229
|
+
await git.rebase()
|
|
230
|
+
.setOperation("abort")
|
|
231
|
+
.call();
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Cherry-Pick and Revert
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
// Cherry-pick a specific commit
|
|
238
|
+
const cherryResult = await git.cherryPick()
|
|
239
|
+
.include("abc1234")
|
|
240
|
+
.call();
|
|
241
|
+
|
|
242
|
+
// Revert a commit
|
|
243
|
+
const revertResult = await git.revert()
|
|
244
|
+
.include("def5678")
|
|
245
|
+
.call();
|
|
246
|
+
|
|
247
|
+
// Revert without committing (stage only)
|
|
248
|
+
await git.revert()
|
|
249
|
+
.include("def5678")
|
|
250
|
+
.setNoCommit(true)
|
|
251
|
+
.call();
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Remote Operations
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
// Configure a remote
|
|
258
|
+
await git.remoteAdd()
|
|
259
|
+
.setName("origin")
|
|
260
|
+
.setUri("https://github.com/user/repo.git")
|
|
261
|
+
.call();
|
|
262
|
+
|
|
263
|
+
// Fetch from remote
|
|
264
|
+
const fetchResult = await git.fetch()
|
|
265
|
+
.setRemote("origin")
|
|
266
|
+
.setCredentials({ username: "user", password: "token" })
|
|
267
|
+
.setProgressCallback((progress) => {
|
|
268
|
+
console.log(`${progress.phase}: ${progress.completed}/${progress.total}`);
|
|
269
|
+
})
|
|
270
|
+
.call();
|
|
271
|
+
|
|
272
|
+
console.log(`Fetched ${fetchResult.trackingRefUpdates.length} refs`);
|
|
273
|
+
|
|
274
|
+
// Push to remote
|
|
275
|
+
const pushResult = await git.push()
|
|
276
|
+
.setRemote("origin")
|
|
277
|
+
.add("refs/heads/main")
|
|
278
|
+
.setCredentials({ username: "user", password: "token" })
|
|
279
|
+
.call();
|
|
280
|
+
|
|
281
|
+
if (!pushResult.isSuccessful()) {
|
|
282
|
+
console.log("Push failed:", pushResult.messages);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Pull (fetch + merge)
|
|
286
|
+
await git.pull()
|
|
287
|
+
.setRemote("origin")
|
|
288
|
+
.setRemoteBranchName("main")
|
|
289
|
+
.call();
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Cloning Repositories
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
import { Git } from "@statewalker/vcs-commands";
|
|
296
|
+
import { createWorkingCopy } from "@statewalker/vcs-core";
|
|
297
|
+
|
|
298
|
+
// Create an in-memory working copy for the clone
|
|
299
|
+
const workingCopy = await createWorkingCopy();
|
|
300
|
+
|
|
301
|
+
// Clone a repository
|
|
302
|
+
const result = await Git.clone()
|
|
303
|
+
.setUri("https://github.com/user/repo.git")
|
|
304
|
+
.setWorkingCopy(workingCopy)
|
|
305
|
+
.setCredentials({ token: "github_pat_xxx" })
|
|
306
|
+
.setProgressCallback((progress) => {
|
|
307
|
+
console.log(`${progress.phase}: ${progress.message}`);
|
|
308
|
+
})
|
|
309
|
+
.call();
|
|
310
|
+
|
|
311
|
+
console.log(`Cloned to branch: ${result.defaultBranch}`);
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Stash Operations
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
// Create a stash with a message
|
|
318
|
+
const stashResult = await git.stashCreate()
|
|
319
|
+
.setMessage("WIP: feature work")
|
|
320
|
+
.call();
|
|
321
|
+
|
|
322
|
+
console.log(`Created stash: ${stashResult.stashRef}`);
|
|
323
|
+
|
|
324
|
+
// Include untracked files (like git stash -u)
|
|
325
|
+
await git.stashCreate()
|
|
326
|
+
.setMessage("WIP with new files")
|
|
327
|
+
.setIncludeUntracked(true)
|
|
328
|
+
.call();
|
|
329
|
+
|
|
330
|
+
// List stashes
|
|
331
|
+
const stashes = await git.stashList().call();
|
|
332
|
+
for (const stash of stashes) {
|
|
333
|
+
console.log(`stash@{${stash.index}}: ${stash.message}`);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Apply latest stash (keeps stash in list)
|
|
337
|
+
await git.stashApply()
|
|
338
|
+
.setStashRef("stash@{0}")
|
|
339
|
+
.call();
|
|
340
|
+
|
|
341
|
+
// Pop stash (apply and remove)
|
|
342
|
+
await git.stashPop()
|
|
343
|
+
.setStashRef("stash@{0}")
|
|
344
|
+
.call();
|
|
345
|
+
|
|
346
|
+
// Drop a specific stash
|
|
347
|
+
await git.stashDrop()
|
|
348
|
+
.setStashRef("stash@{1}")
|
|
349
|
+
.call();
|
|
350
|
+
|
|
351
|
+
// Clear all stashes
|
|
352
|
+
await git.stashClear().call();
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Stash commits follow Git's structure with 2-3 parents:
|
|
356
|
+
- Parent 1: HEAD at time of stash
|
|
357
|
+
- Parent 2: Index state commit
|
|
358
|
+
- Parent 3 (optional): Untracked files commit (when `includeUntracked: true`)
|
|
359
|
+
|
|
360
|
+
### Checkout Operations
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
// Switch to a branch
|
|
364
|
+
await git.checkout()
|
|
365
|
+
.setName("feature/login")
|
|
366
|
+
.call();
|
|
367
|
+
|
|
368
|
+
// Create and switch to new branch (like git checkout -b)
|
|
369
|
+
await git.checkout()
|
|
370
|
+
.setName("feature/new")
|
|
371
|
+
.setCreateBranch(true)
|
|
372
|
+
.call();
|
|
373
|
+
|
|
374
|
+
// Checkout specific commit (detached HEAD)
|
|
375
|
+
await git.checkout()
|
|
376
|
+
.setName("abc1234")
|
|
377
|
+
.call();
|
|
378
|
+
|
|
379
|
+
// Checkout specific files from another branch
|
|
380
|
+
await git.checkout()
|
|
381
|
+
.setName("main")
|
|
382
|
+
.addPath("src/config.ts")
|
|
383
|
+
.addPath("package.json")
|
|
384
|
+
.call();
|
|
385
|
+
|
|
386
|
+
// Force checkout (discard local changes)
|
|
387
|
+
await git.checkout()
|
|
388
|
+
.setName("main")
|
|
389
|
+
.setForce(true)
|
|
390
|
+
.call();
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
Checkout performs three-way conflict detection before switching branches:
|
|
394
|
+
|
|
395
|
+
```typescript
|
|
396
|
+
import { CheckoutConflictError } from "@statewalker/vcs-commands/errors";
|
|
397
|
+
|
|
398
|
+
try {
|
|
399
|
+
await git.checkout().setName("main").call();
|
|
400
|
+
} catch (error) {
|
|
401
|
+
if (error instanceof CheckoutConflictError) {
|
|
402
|
+
// Local modifications would be overwritten
|
|
403
|
+
console.log("Conflicting paths:");
|
|
404
|
+
for (const conflict of error.conflicts) {
|
|
405
|
+
console.log(` ${conflict.path}: ${conflict.message}`);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Options: stash changes, force checkout, or abort
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
Conflict types detected:
|
|
414
|
+
- **DIRTY_WORKTREE**: Modified file would be overwritten
|
|
415
|
+
- **DIRTY_INDEX**: Staged changes would be lost
|
|
416
|
+
- **UNTRACKED_FILE**: New file would be overwritten
|
|
417
|
+
|
|
418
|
+
### Tags
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
// Create annotated tag
|
|
422
|
+
await git.tag()
|
|
423
|
+
.setName("v1.0.0")
|
|
424
|
+
.setMessage("Release version 1.0.0")
|
|
425
|
+
.setTagger({ name: "Developer", email: "dev@example.com" })
|
|
426
|
+
.call();
|
|
427
|
+
|
|
428
|
+
// Create tag at specific commit
|
|
429
|
+
await git.tag()
|
|
430
|
+
.setName("v0.9.0")
|
|
431
|
+
.setObjectId("abc1234")
|
|
432
|
+
.call();
|
|
433
|
+
|
|
434
|
+
// List tags
|
|
435
|
+
const tags = await git.tagList().call();
|
|
436
|
+
for (const tag of tags) {
|
|
437
|
+
console.log(tag.name);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// Delete tag
|
|
441
|
+
await git.tagDelete()
|
|
442
|
+
.setTags("v0.9.0")
|
|
443
|
+
.call();
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
## Error Handling
|
|
447
|
+
|
|
448
|
+
Commands throw specific error types for different failure modes:
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
451
|
+
import {
|
|
452
|
+
RefNotFoundError,
|
|
453
|
+
MergeConflictError,
|
|
454
|
+
AuthenticationError,
|
|
455
|
+
PushRejectedException,
|
|
456
|
+
} from "@statewalker/vcs-commands/errors";
|
|
457
|
+
|
|
458
|
+
try {
|
|
459
|
+
await git.checkout().setName("nonexistent").call();
|
|
460
|
+
} catch (error) {
|
|
461
|
+
if (error instanceof RefNotFoundError) {
|
|
462
|
+
console.log(`Branch not found: ${error.refName}`);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
try {
|
|
467
|
+
await git.merge().include("feature").call();
|
|
468
|
+
} catch (error) {
|
|
469
|
+
if (error instanceof MergeConflictError) {
|
|
470
|
+
console.log("Conflicts:", error.conflicts);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
try {
|
|
475
|
+
await git.push().setRemote("origin").call();
|
|
476
|
+
} catch (error) {
|
|
477
|
+
if (error instanceof AuthenticationError) {
|
|
478
|
+
console.log("Authentication failed");
|
|
479
|
+
} else if (error instanceof PushRejectedException) {
|
|
480
|
+
console.log("Push rejected:", error.message);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
### Error Categories
|
|
486
|
+
|
|
487
|
+
| Category | Errors |
|
|
488
|
+
|----------|--------|
|
|
489
|
+
| **Command** | `MissingArgumentError`, `InvalidArgumentError`, `NotImplementedError` |
|
|
490
|
+
| **Reference** | `RefNotFoundError`, `RefAlreadyExistsError`, `CannotDeleteCurrentBranchError` |
|
|
491
|
+
| **Commit** | `NoMessageError`, `EmptyCommitError`, `UnmergedPathsError` |
|
|
492
|
+
| **Merge** | `MergeConflictError`, `NotFastForwardError`, `NoMergeBaseError` |
|
|
493
|
+
| **Transport** | `AuthenticationError`, `PushRejectedException`, `NonFastForwardError` |
|
|
494
|
+
| **Checkout** | `CheckoutConflictError`, `DirCacheCheckoutError` |
|
|
495
|
+
| **Stash** | `NoStashError`, `StashDropError` |
|
|
496
|
+
|
|
497
|
+
## Result Types
|
|
498
|
+
|
|
499
|
+
Commands return rich result objects with status information:
|
|
500
|
+
|
|
501
|
+
```typescript
|
|
502
|
+
import {
|
|
503
|
+
MergeStatus,
|
|
504
|
+
PushStatus,
|
|
505
|
+
RebaseStatus,
|
|
506
|
+
} from "@statewalker/vcs-commands/results";
|
|
507
|
+
|
|
508
|
+
// Check merge result
|
|
509
|
+
const mergeResult = await git.merge().include("feature").call();
|
|
510
|
+
switch (mergeResult.status) {
|
|
511
|
+
case MergeStatus.FAST_FORWARD:
|
|
512
|
+
console.log("Fast-forwarded");
|
|
513
|
+
break;
|
|
514
|
+
case MergeStatus.MERGED:
|
|
515
|
+
console.log("Created merge commit");
|
|
516
|
+
break;
|
|
517
|
+
case MergeStatus.CONFLICTING:
|
|
518
|
+
console.log("Conflicts need resolution");
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// Check push result
|
|
523
|
+
const pushResult = await git.push().call();
|
|
524
|
+
for (const update of pushResult.remoteUpdates) {
|
|
525
|
+
if (update.status === PushStatus.OK) {
|
|
526
|
+
console.log(`Updated: ${update.remoteName}`);
|
|
527
|
+
} else if (update.status === PushStatus.REJECTED_NONFASTFORWARD) {
|
|
528
|
+
console.log(`Rejected: ${update.remoteName} (non-fast-forward)`);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
## Configuration
|
|
534
|
+
|
|
535
|
+
### Transport Options
|
|
536
|
+
|
|
537
|
+
Remote commands support authentication and progress tracking:
|
|
538
|
+
|
|
539
|
+
```typescript
|
|
540
|
+
// Username/password authentication
|
|
541
|
+
await git.fetch()
|
|
542
|
+
.setRemote("origin")
|
|
543
|
+
.setCredentials({
|
|
544
|
+
username: "user",
|
|
545
|
+
password: "password",
|
|
546
|
+
})
|
|
547
|
+
.call();
|
|
548
|
+
|
|
549
|
+
// Token authentication
|
|
550
|
+
await git.push()
|
|
551
|
+
.setRemote("origin")
|
|
552
|
+
.setCredentials({
|
|
553
|
+
token: "github_pat_xxxx",
|
|
554
|
+
})
|
|
555
|
+
.call();
|
|
556
|
+
|
|
557
|
+
// Custom headers
|
|
558
|
+
await git.fetch()
|
|
559
|
+
.setRemote("origin")
|
|
560
|
+
.setHeaders({
|
|
561
|
+
"X-Custom-Header": "value",
|
|
562
|
+
})
|
|
563
|
+
.call();
|
|
564
|
+
|
|
565
|
+
// Progress tracking
|
|
566
|
+
await git.clone()
|
|
567
|
+
.setUri("https://github.com/user/repo.git")
|
|
568
|
+
.setProgressCallback((progress) => {
|
|
569
|
+
// Structured progress
|
|
570
|
+
console.log(progress.phase, progress.completed, progress.total);
|
|
571
|
+
})
|
|
572
|
+
.setMessageCallback((message) => {
|
|
573
|
+
// Raw server messages
|
|
574
|
+
console.log("Server:", message);
|
|
575
|
+
})
|
|
576
|
+
.call();
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
## Related Packages
|
|
580
|
+
|
|
581
|
+
| Package | Description |
|
|
582
|
+
|---------|-------------|
|
|
583
|
+
| `@statewalker/vcs-core` | Core types, store interfaces, and repository factories |
|
|
584
|
+
| `@statewalker/vcs-transport` | Git protocol implementation |
|
|
585
|
+
| `@statewalker/vcs-store-sql` | SQLite storage backend |
|
|
586
|
+
| `@statewalker/vcs-store-mem` | In-memory storage for testing |
|
|
587
|
+
| `@statewalker/vcs-store-kv` | Key-value storage abstraction |
|
|
588
|
+
|
|
589
|
+
## License
|
|
590
|
+
|
|
591
|
+
MIT
|