@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.
- package/README.md +180 -466
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/core-commands/checkout.command.impl.d.ts +1 -1
- package/dist/core-commands/checkout.command.impl.d.ts.map +1 -1
- package/dist/git-command.d.ts.map +1 -1
- package/package.json +25 -16
- package/src/commands/add-command.ts +494 -0
- package/src/commands/blame-command.ts +1241 -0
- package/src/commands/branch-command.ts +487 -0
- package/src/commands/checkout-command.ts +681 -0
- package/src/commands/cherry-pick-command.ts +544 -0
- package/src/commands/clean-command.ts +218 -0
- package/src/commands/clone-command.ts +532 -0
- package/src/commands/commit-command.ts +529 -0
- package/src/commands/describe-command.ts +454 -0
- package/src/commands/diff-command.ts +257 -0
- package/src/commands/fetch-command.ts +615 -0
- package/src/commands/gc-command.ts +155 -0
- package/src/commands/index.ts +31 -0
- package/src/commands/init-command.ts +365 -0
- package/src/commands/log-command.ts +549 -0
- package/src/commands/ls-remote-command.ts +237 -0
- package/src/commands/merge-command.ts +750 -0
- package/src/commands/pack-refs-command.ts +101 -0
- package/src/commands/pull-command.ts +258 -0
- package/src/commands/push-command.ts +682 -0
- package/src/commands/rebase-command.ts +665 -0
- package/src/commands/reflog-command.ts +68 -0
- package/src/commands/remote-command.ts +385 -0
- package/src/commands/reset-command.ts +292 -0
- package/src/commands/revert-command.ts +552 -0
- package/src/commands/rm-command.ts +178 -0
- package/src/commands/stash-apply-command.ts +402 -0
- package/src/commands/stash-create-command.ts +339 -0
- package/src/commands/stash-drop-command.ts +115 -0
- package/src/commands/stash-list-command.ts +116 -0
- package/src/commands/status-command.ts +173 -0
- package/src/commands/tag-command.ts +378 -0
- package/src/commands/tree-restore.ts +126 -0
- package/src/core-commands/add.command.impl.ts +274 -0
- package/src/core-commands/add.command.ts +81 -0
- package/src/core-commands/checkout.command.impl.ts +586 -0
- package/src/core-commands/checkout.command.ts +125 -0
- package/src/core-commands/index.ts +13 -0
- package/src/errors/add-errors.ts +20 -0
- package/src/errors/checkout-errors.ts +42 -0
- package/src/errors/command-errors.ts +68 -0
- package/src/errors/commit-errors.ts +40 -0
- package/src/errors/git-api-error.ts +11 -0
- package/src/errors/index.ts +12 -0
- package/src/errors/merge-errors.ts +94 -0
- package/src/errors/rebase-errors.ts +34 -0
- package/src/errors/ref-errors.ts +100 -0
- package/src/errors/remote-errors.ts +27 -0
- package/src/errors/stash-errors.ts +42 -0
- package/src/errors/tag-errors.ts +16 -0
- package/src/errors/transport-errors.ts +68 -0
- package/src/git-command.ts +421 -0
- package/src/git.ts +910 -0
- package/src/index.ts +18 -0
- package/src/pack-import/index.ts +8 -0
- package/src/pack-import/pack-import.ts +24 -0
- package/src/remote-config/index.ts +12 -0
- package/src/remote-config/remote-config-store.ts +285 -0
- package/src/rename/index.ts +5 -0
- package/src/rename/similarity-index.ts +185 -0
- package/src/results/cherry-pick-result.ts +35 -0
- package/src/results/clone-result.ts +25 -0
- package/src/results/diff-entry.ts +162 -0
- package/src/results/diff-formatter.ts +416 -0
- package/src/results/fetch-result.ts +91 -0
- package/src/results/index.ts +13 -0
- package/src/results/init-result.ts +29 -0
- package/src/results/merge-result.ts +135 -0
- package/src/results/pull-result.ts +27 -0
- package/src/results/push-result.ts +86 -0
- package/src/results/rebase-result.ts +140 -0
- package/src/results/revert-result.ts +35 -0
- package/src/results/stash-result.ts +60 -0
- package/src/results/status-result.ts +65 -0
- package/src/transport-command.ts +125 -0
- package/src/tree-merge/index.ts +8 -0
- package/src/tree-merge/tree-merge.ts +249 -0
- package/src/types.ts +70 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import type { ObjectId } from "@statewalker/vcs-core";
|
|
2
|
+
import { lsRemote } from "@statewalker/vcs-transport";
|
|
3
|
+
|
|
4
|
+
import { InvalidRemoteError } from "../errors/index.js";
|
|
5
|
+
import { RemoteConfigStore } from "../remote-config/index.js";
|
|
6
|
+
import { TransportCommand } from "../transport-command.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A remote ref entry.
|
|
10
|
+
*
|
|
11
|
+
* Based on JGit's Ref with additional remote context.
|
|
12
|
+
*/
|
|
13
|
+
export interface RemoteRef {
|
|
14
|
+
/** Full ref name (e.g., "refs/heads/main") */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Object ID the ref points to */
|
|
17
|
+
objectId: ObjectId;
|
|
18
|
+
/** Peeled object ID for tags (if applicable) */
|
|
19
|
+
peeledObjectId?: ObjectId;
|
|
20
|
+
/** Whether this is a symbolic ref */
|
|
21
|
+
symbolic?: boolean;
|
|
22
|
+
/** Target of symbolic ref */
|
|
23
|
+
target?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Result of ls-remote operation.
|
|
28
|
+
*/
|
|
29
|
+
export interface LsRemoteResult {
|
|
30
|
+
/** URI that was queried */
|
|
31
|
+
uri: string;
|
|
32
|
+
/** Remote refs */
|
|
33
|
+
refs: RemoteRef[];
|
|
34
|
+
/** Default branch (from HEAD symref) */
|
|
35
|
+
defaultBranch?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* List references in a remote repository.
|
|
40
|
+
*
|
|
41
|
+
* Equivalent to `git ls-remote`.
|
|
42
|
+
*
|
|
43
|
+
* Based on JGit's LsRemoteCommand.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // List all refs
|
|
48
|
+
* const result = await git.lsRemote()
|
|
49
|
+
* .setRemote("https://github.com/user/repo")
|
|
50
|
+
* .call();
|
|
51
|
+
*
|
|
52
|
+
* // List only heads
|
|
53
|
+
* const result = await git.lsRemote()
|
|
54
|
+
* .setRemote("origin")
|
|
55
|
+
* .setHeads(true)
|
|
56
|
+
* .call();
|
|
57
|
+
*
|
|
58
|
+
* // List only tags
|
|
59
|
+
* const result = await git.lsRemote()
|
|
60
|
+
* .setRemote("origin")
|
|
61
|
+
* .setTags(true)
|
|
62
|
+
* .call();
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export class LsRemoteCommand extends TransportCommand<LsRemoteResult> {
|
|
66
|
+
private remote?: string;
|
|
67
|
+
private heads = false;
|
|
68
|
+
private tags = false;
|
|
69
|
+
// biome-ignore lint/correctness/noUnusedPrivateClassMembers: API placeholder for transport layer
|
|
70
|
+
private uploadPack?: string;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Set the remote to query.
|
|
74
|
+
*
|
|
75
|
+
* Can be either a remote name (e.g., "origin") or a URL.
|
|
76
|
+
*
|
|
77
|
+
* @param remote Remote name or URL
|
|
78
|
+
*/
|
|
79
|
+
setRemote(remote: string): this {
|
|
80
|
+
this.checkCallable();
|
|
81
|
+
this.remote = remote;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get the remote being queried.
|
|
87
|
+
*/
|
|
88
|
+
getRemote(): string | undefined {
|
|
89
|
+
return this.remote;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Set whether to show only refs under refs/heads.
|
|
94
|
+
*
|
|
95
|
+
* @param heads Whether to show only heads
|
|
96
|
+
*/
|
|
97
|
+
setHeads(heads: boolean): this {
|
|
98
|
+
this.checkCallable();
|
|
99
|
+
this.heads = heads;
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Whether to show only heads.
|
|
105
|
+
*/
|
|
106
|
+
isHeads(): boolean {
|
|
107
|
+
return this.heads;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Set whether to show only refs under refs/tags.
|
|
112
|
+
*
|
|
113
|
+
* @param tags Whether to show only tags
|
|
114
|
+
*/
|
|
115
|
+
setTags(tags: boolean): this {
|
|
116
|
+
this.checkCallable();
|
|
117
|
+
this.tags = tags;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Whether to show only tags.
|
|
123
|
+
*/
|
|
124
|
+
isTags(): boolean {
|
|
125
|
+
return this.tags;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Set custom upload-pack path for the remote.
|
|
130
|
+
*
|
|
131
|
+
* @param uploadPack Path to git-upload-pack on remote
|
|
132
|
+
*/
|
|
133
|
+
setUploadPack(uploadPack: string): this {
|
|
134
|
+
this.checkCallable();
|
|
135
|
+
this.uploadPack = uploadPack;
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Execute the ls-remote operation.
|
|
141
|
+
*
|
|
142
|
+
* @returns Refs from the remote repository
|
|
143
|
+
* @throws InvalidRemoteError if remote is not specified or cannot be resolved
|
|
144
|
+
*/
|
|
145
|
+
async call(): Promise<LsRemoteResult> {
|
|
146
|
+
this.checkCallable();
|
|
147
|
+
this.setCallable(false);
|
|
148
|
+
|
|
149
|
+
if (!this.remote) {
|
|
150
|
+
throw new InvalidRemoteError("", "Remote must be specified");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Resolve remote URL
|
|
154
|
+
const remoteUrl = await this.resolveRemoteUrl(this.remote);
|
|
155
|
+
if (!remoteUrl) {
|
|
156
|
+
throw new InvalidRemoteError(this.remote);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Execute ls-remote
|
|
160
|
+
const refs = await lsRemote(remoteUrl, {
|
|
161
|
+
auth: this.credentials,
|
|
162
|
+
headers: this.headers,
|
|
163
|
+
timeout: this.timeout,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Filter refs based on heads/tags settings
|
|
167
|
+
const filteredRefs: RemoteRef[] = [];
|
|
168
|
+
let defaultBranch: string | undefined;
|
|
169
|
+
|
|
170
|
+
for (const [refName, objectIdHex] of refs) {
|
|
171
|
+
// Handle HEAD specially
|
|
172
|
+
if (refName === "HEAD") {
|
|
173
|
+
continue; // We'll use it for defaultBranch detection but not include in results
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Apply filters
|
|
177
|
+
if (this.heads && !refName.startsWith("refs/heads/")) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (this.tags && !refName.startsWith("refs/tags/")) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
filteredRefs.push({
|
|
185
|
+
name: refName,
|
|
186
|
+
objectId: objectIdHex,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Try to determine default branch
|
|
191
|
+
const headRef = refs.get("HEAD");
|
|
192
|
+
if (headRef) {
|
|
193
|
+
// Check if HEAD points to a known branch
|
|
194
|
+
for (const [refName, objectIdHex] of refs) {
|
|
195
|
+
if (refName.startsWith("refs/heads/") && objectIdHex === headRef) {
|
|
196
|
+
defaultBranch = refName.slice("refs/heads/".length);
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
uri: remoteUrl,
|
|
204
|
+
refs: filteredRefs,
|
|
205
|
+
defaultBranch,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Call and return just the refs map.
|
|
211
|
+
*
|
|
212
|
+
* Convenience method for simple use cases.
|
|
213
|
+
*/
|
|
214
|
+
async callAsMap(): Promise<Map<string, ObjectId>> {
|
|
215
|
+
const result = await this.call();
|
|
216
|
+
const map = new Map<string, ObjectId>();
|
|
217
|
+
for (const ref of result.refs) {
|
|
218
|
+
map.set(ref.name, ref.objectId);
|
|
219
|
+
}
|
|
220
|
+
return map;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Resolve remote name to URL.
|
|
225
|
+
*
|
|
226
|
+
* A named remote resolves through `remote.<name>.url` in the working copy
|
|
227
|
+
* configuration; an unconfigured name is passed through unchanged.
|
|
228
|
+
*/
|
|
229
|
+
private async resolveRemoteUrl(remote: string): Promise<string | undefined> {
|
|
230
|
+
// If it looks like a URL, use it directly
|
|
231
|
+
if (remote.includes("://") || remote.includes("@")) {
|
|
232
|
+
return remote;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return RemoteConfigStore.from(this.workingCopy).urlFor(remote) ?? remote;
|
|
236
|
+
}
|
|
237
|
+
}
|