@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,101 @@
|
|
|
1
|
+
import { GitCommand } from "../git-command.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Result of packing refs
|
|
5
|
+
*/
|
|
6
|
+
export interface PackRefsResult {
|
|
7
|
+
/** Number of refs packed */
|
|
8
|
+
refsPacked: number;
|
|
9
|
+
/** Whether operation succeeded */
|
|
10
|
+
success: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Pack loose references into packed-refs.
|
|
15
|
+
*
|
|
16
|
+
* Equivalent to `git pack-refs`.
|
|
17
|
+
*
|
|
18
|
+
* This command packs loose reference files (.git/refs/*) into the
|
|
19
|
+
* single .git/packed-refs file for efficiency.
|
|
20
|
+
*
|
|
21
|
+
* Based on JGit's PackRefsCommand.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // Pack all refs
|
|
26
|
+
* const result = await git.packRefs()
|
|
27
|
+
* .setAll(true)
|
|
28
|
+
* .call();
|
|
29
|
+
*
|
|
30
|
+
* // Pack specific refs
|
|
31
|
+
* const result = await git.packRefs()
|
|
32
|
+
* .addRef("refs/heads/main")
|
|
33
|
+
* .addRef("refs/heads/feature")
|
|
34
|
+
* .call();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export class PackRefsCommand extends GitCommand<PackRefsResult> {
|
|
38
|
+
private all = false;
|
|
39
|
+
private refs: string[] = [];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Pack all loose refs.
|
|
43
|
+
*
|
|
44
|
+
* @param all Whether to pack all refs
|
|
45
|
+
*/
|
|
46
|
+
setAll(all: boolean): this {
|
|
47
|
+
this.checkCallable();
|
|
48
|
+
this.all = all;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Add a specific ref to pack.
|
|
54
|
+
*
|
|
55
|
+
* @param refName The ref name to pack
|
|
56
|
+
*/
|
|
57
|
+
addRef(refName: string): this {
|
|
58
|
+
this.checkCallable();
|
|
59
|
+
this.refs.push(refName);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Execute the pack-refs command.
|
|
65
|
+
*
|
|
66
|
+
* @returns PackRefsResult
|
|
67
|
+
*/
|
|
68
|
+
async call(): Promise<PackRefsResult> {
|
|
69
|
+
this.checkCallable();
|
|
70
|
+
this.setCallable(false);
|
|
71
|
+
|
|
72
|
+
// Check if RefStore supports packRefs
|
|
73
|
+
if (!this.refsStore.packRefs) {
|
|
74
|
+
throw new Error("RefStore does not support packRefs");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let refsPacked = 0;
|
|
78
|
+
|
|
79
|
+
if (this.all) {
|
|
80
|
+
// Pack all refs - collect all ref names first
|
|
81
|
+
const allRefs: string[] = [];
|
|
82
|
+
for await (const ref of this.refsStore.list("refs/")) {
|
|
83
|
+
allRefs.push(ref.name);
|
|
84
|
+
}
|
|
85
|
+
refsPacked = allRefs.length;
|
|
86
|
+
|
|
87
|
+
if (allRefs.length > 0) {
|
|
88
|
+
await this.refsStore.packRefs(allRefs, { all: true, deleteLoose: true });
|
|
89
|
+
}
|
|
90
|
+
} else if (this.refs.length > 0) {
|
|
91
|
+
// Pack specific refs
|
|
92
|
+
refsPacked = this.refs.length;
|
|
93
|
+
await this.refsStore.packRefs(this.refs, { deleteLoose: true });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
refsPacked,
|
|
98
|
+
success: true,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { NoHeadError, NotImplementedError } from "../errors/index.js";
|
|
2
|
+
import {
|
|
3
|
+
type FastForwardMode,
|
|
4
|
+
isMergeSuccessful,
|
|
5
|
+
type MergeStrategy,
|
|
6
|
+
} from "../results/merge-result.js";
|
|
7
|
+
import type { PullResult } from "../results/pull-result.js";
|
|
8
|
+
import { TransportCommand } from "../transport-command.js";
|
|
9
|
+
import { FetchCommand, type TagOption } from "./fetch-command.js";
|
|
10
|
+
import { MergeCommand } from "./merge-command.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Pull changes from a remote repository.
|
|
14
|
+
*
|
|
15
|
+
* Equivalent to `git pull` (fetch + merge).
|
|
16
|
+
*
|
|
17
|
+
* Based on JGit's PullCommand.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Pull from default remote/branch
|
|
22
|
+
* const result = await git.pull().call();
|
|
23
|
+
*
|
|
24
|
+
* // Pull from specific remote
|
|
25
|
+
* const result = await git.pull()
|
|
26
|
+
* .setRemote("upstream")
|
|
27
|
+
* .call();
|
|
28
|
+
*
|
|
29
|
+
* // Pull specific branch
|
|
30
|
+
* const result = await git.pull()
|
|
31
|
+
* .setRemoteBranchName("develop")
|
|
32
|
+
* .call();
|
|
33
|
+
*
|
|
34
|
+
* // Pull with rebase (not yet implemented)
|
|
35
|
+
* const result = await git.pull()
|
|
36
|
+
* .setRebase(true)
|
|
37
|
+
* .call();
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export class PullCommand extends TransportCommand<PullResult> {
|
|
41
|
+
private remote = "origin";
|
|
42
|
+
private remoteBranchName?: string;
|
|
43
|
+
private rebase = false;
|
|
44
|
+
private strategy?: MergeStrategy;
|
|
45
|
+
private fastForwardMode?: FastForwardMode;
|
|
46
|
+
private tagOption?: TagOption;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Set the remote to pull from.
|
|
50
|
+
*
|
|
51
|
+
* Default is "origin".
|
|
52
|
+
*
|
|
53
|
+
* @param remote Remote name
|
|
54
|
+
*/
|
|
55
|
+
setRemote(remote: string): this {
|
|
56
|
+
this.checkCallable();
|
|
57
|
+
this.remote = remote;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get the remote being pulled from.
|
|
63
|
+
*/
|
|
64
|
+
getRemote(): string {
|
|
65
|
+
return this.remote;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Set the remote branch to pull.
|
|
70
|
+
*
|
|
71
|
+
* If not set, uses the tracking branch for the current local branch.
|
|
72
|
+
*
|
|
73
|
+
* @param branch Remote branch name
|
|
74
|
+
*/
|
|
75
|
+
setRemoteBranchName(branch: string): this {
|
|
76
|
+
this.checkCallable();
|
|
77
|
+
this.remoteBranchName = branch;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get the remote branch name.
|
|
83
|
+
*/
|
|
84
|
+
getRemoteBranchName(): string | undefined {
|
|
85
|
+
return this.remoteBranchName;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Set whether to use rebase instead of merge.
|
|
90
|
+
*
|
|
91
|
+
* Note: Rebase is not yet implemented.
|
|
92
|
+
*
|
|
93
|
+
* @param rebase Whether to use rebase
|
|
94
|
+
*/
|
|
95
|
+
setRebase(rebase: boolean): this {
|
|
96
|
+
this.checkCallable();
|
|
97
|
+
this.rebase = rebase;
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether rebase mode is enabled.
|
|
103
|
+
*/
|
|
104
|
+
isRebase(): boolean {
|
|
105
|
+
return this.rebase;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Set the merge strategy.
|
|
110
|
+
*
|
|
111
|
+
* @param strategy Merge strategy
|
|
112
|
+
*/
|
|
113
|
+
setStrategy(strategy: MergeStrategy): this {
|
|
114
|
+
this.checkCallable();
|
|
115
|
+
this.strategy = strategy;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Set the fast-forward mode.
|
|
121
|
+
*
|
|
122
|
+
* @param mode Fast-forward mode
|
|
123
|
+
*/
|
|
124
|
+
setFastForwardMode(mode: FastForwardMode): this {
|
|
125
|
+
this.checkCallable();
|
|
126
|
+
this.fastForwardMode = mode;
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Get the fast-forward mode.
|
|
132
|
+
*/
|
|
133
|
+
getFastForwardMode(): FastForwardMode | undefined {
|
|
134
|
+
return this.fastForwardMode;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Set the specification of annotated tag behavior during fetch.
|
|
139
|
+
*
|
|
140
|
+
* @param tagOption Tag option
|
|
141
|
+
*/
|
|
142
|
+
setTagOpt(tagOption: TagOption): this {
|
|
143
|
+
this.checkCallable();
|
|
144
|
+
this.tagOption = tagOption;
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get the tag option.
|
|
150
|
+
*/
|
|
151
|
+
getTagOpt(): TagOption | undefined {
|
|
152
|
+
return this.tagOption;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Execute the pull operation.
|
|
157
|
+
*
|
|
158
|
+
* @returns Pull result with fetch and merge results
|
|
159
|
+
* @throws NoHeadError if HEAD is not set
|
|
160
|
+
* @throws InvalidRemoteError if remote cannot be resolved
|
|
161
|
+
*/
|
|
162
|
+
async call(): Promise<PullResult> {
|
|
163
|
+
this.checkCallable();
|
|
164
|
+
this.setCallable(false);
|
|
165
|
+
|
|
166
|
+
// Get current branch
|
|
167
|
+
const currentBranch = await this.getCurrentBranch();
|
|
168
|
+
if (!currentBranch) {
|
|
169
|
+
throw new NoHeadError("Cannot pull with detached HEAD");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Extract branch name from full ref
|
|
173
|
+
const localBranchName = currentBranch.replace("refs/heads/", "");
|
|
174
|
+
|
|
175
|
+
// Determine remote branch
|
|
176
|
+
const remoteBranch = this.remoteBranchName || localBranchName;
|
|
177
|
+
|
|
178
|
+
// Build refspec
|
|
179
|
+
const refspec = `refs/heads/${remoteBranch}:refs/remotes/${this.remote}/${remoteBranch}`;
|
|
180
|
+
|
|
181
|
+
// Execute fetch
|
|
182
|
+
const fetchCommand = new FetchCommand(this._workingCopy);
|
|
183
|
+
fetchCommand.setRemote(this.remote);
|
|
184
|
+
fetchCommand.setRefSpecs(refspec);
|
|
185
|
+
|
|
186
|
+
if (this.credentials) {
|
|
187
|
+
fetchCommand.setCredentials(this.credentials);
|
|
188
|
+
}
|
|
189
|
+
if (this.headers) {
|
|
190
|
+
fetchCommand.setHeaders(this.headers);
|
|
191
|
+
}
|
|
192
|
+
if (this.timeout) {
|
|
193
|
+
fetchCommand.setTimeout(this.timeout);
|
|
194
|
+
}
|
|
195
|
+
if (this.progressCallback) {
|
|
196
|
+
fetchCommand.setProgressMonitor(this.progressCallback);
|
|
197
|
+
}
|
|
198
|
+
if (this.progressMessageCallback) {
|
|
199
|
+
fetchCommand.setProgressMessageCallback(this.progressMessageCallback);
|
|
200
|
+
}
|
|
201
|
+
if (this.tagOption) {
|
|
202
|
+
fetchCommand.setTagOpt(this.tagOption);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const fetchResult = await fetchCommand.call();
|
|
206
|
+
|
|
207
|
+
// If repository is empty or nothing fetched, we're done
|
|
208
|
+
if (fetchResult.isEmpty || fetchResult.trackingRefUpdates.length === 0) {
|
|
209
|
+
return {
|
|
210
|
+
fetchResult,
|
|
211
|
+
successful: true,
|
|
212
|
+
rebaseUsed: false,
|
|
213
|
+
fetchedFrom: this.remote,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Get the remote tracking ref to merge
|
|
218
|
+
const trackingRef = `refs/remotes/${this.remote}/${remoteBranch}`;
|
|
219
|
+
const trackingRefResolved = await this.refsStore.resolve(trackingRef);
|
|
220
|
+
|
|
221
|
+
if (!trackingRefResolved?.objectId) {
|
|
222
|
+
// Nothing to merge
|
|
223
|
+
return {
|
|
224
|
+
fetchResult,
|
|
225
|
+
successful: true,
|
|
226
|
+
rebaseUsed: false,
|
|
227
|
+
fetchedFrom: this.remote,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Check if rebase was requested
|
|
232
|
+
if (this.rebase) {
|
|
233
|
+
// Rebase is not yet implemented
|
|
234
|
+
throw new NotImplementedError("Pull with rebase");
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Execute merge
|
|
238
|
+
const mergeCommand = new MergeCommand(this._workingCopy);
|
|
239
|
+
mergeCommand.include(trackingRefResolved.objectId);
|
|
240
|
+
|
|
241
|
+
if (this.strategy) {
|
|
242
|
+
mergeCommand.setStrategy(this.strategy);
|
|
243
|
+
}
|
|
244
|
+
if (this.fastForwardMode) {
|
|
245
|
+
mergeCommand.setFastForwardMode(this.fastForwardMode);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const mergeResult = await mergeCommand.call();
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
fetchResult,
|
|
252
|
+
mergeResult,
|
|
253
|
+
successful: isMergeSuccessful(mergeResult.status),
|
|
254
|
+
rebaseUsed: false,
|
|
255
|
+
fetchedFrom: this.remote,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|