@statewalker/vcs-commands 0.1.1 → 0.3.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/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 +19 -14
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit-command.d.ts","sourceRoot":"","sources":["../../src/commands/commit-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,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AIG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAI7B;IAED;;;;OAIG;IACH,aAAa,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAIvC;IAED;;;;;;;OAOG;IACH,YAAY,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,GAAG,IAAI,CAIzC;IAED;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAQhC;IAED;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAQzB;IAED;;OAEG;IACH,KAAK,IAAI,OAAO,CAEf;IAED;;;;;;;;OAQG;IACH,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAIpC;IAED;;;;;;;OAOG;IACG,IAAI,IAAI,OAAO,CAAC,YAAY,CAAC,CAkIlC;IAED;;;;;;;OAOG;YACW,aAAa;IA0C3B;;OAEG;YACW,eAAe;IA8B7B;;;;;OAKG;YACW,mBAAmB;IAmBjC;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAQ5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-command.d.ts","sourceRoot":"","sources":["../../src/commands/init-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+C,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"init-command.d.ts","sourceRoot":"","sources":["../../src/commands/init-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+C,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGnG,OAAO,EAEL,KAAK,OAAO,EAEZ,KAAK,QAAQ,EACd,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,WAAW;IACtB,OAAO,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AEhB;IAED;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAI/B;IAED;;OAEG;IACH,QAAQ,IAAI,OAAO,CAElB;IAED;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAIjC;IAED;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAInC;IAED;;;;;;OAMG;IACH,aAAa,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAIvC;IAED;;OAEG;IACH,YAAY,IAAI,OAAO,CAEtB;IAED;;;;;;;OAOG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAItC;IAED;;OAEG;IACH,cAAc,IAAI,MAAM,EAAE,CAEzB;IAED;;;;OAIG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAIxC;IAED;;OAEG;IACH,cAAc,IAAI,MAAM,GAAG,SAAS,CAEnC;IAED;;;;;;OAMG;IACG,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC,CAgHhC;IAED;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,UAAU,CAAC,CAiBvC;IAED;;;;;;OAMG;YACW,gBAAgB;IAS9B;;OAEG;YACW,aAAa;IAwC3B;;;;OAIG;YACY,gBAAgB;IA4C/B;;OAEG;YACW,uBAAuB;IA0BrC;;OAEG;YACY,gBAAgB;IA6B/B;;;;;;;OAOG;YACW,iBAAiB;CAyChC"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Reference: jgit/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java
|
|
11
11
|
*/
|
|
12
12
|
import { type Blobs, type Commits, type FilesApi, type RefStore, type Trees } from "@statewalker/vcs-core";
|
|
13
|
-
import {
|
|
13
|
+
import type { Staging } from "@statewalker/vcs-working-tree";
|
|
14
14
|
import type { Checkout, CheckoutOptions, CheckoutResult } from "./checkout.command.js";
|
|
15
15
|
/**
|
|
16
16
|
* Options for creating a CheckoutCommand.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.command.impl.d.ts","sourceRoot":"","sources":["../../src/core-commands/checkout.command.impl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,KAAK,KAAK,EACV,KAAK,OAAO,EAEZ,KAAK,QAAQ,EAGb,KAAK,QAAQ,EAEb,KAAK,KAAK,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"checkout.command.impl.d.ts","sourceRoot":"","sources":["../../src/core-commands/checkout.command.impl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,KAAK,KAAK,EACV,KAAK,OAAO,EAEZ,KAAK,QAAQ,EAGb,KAAK,QAAQ,EAEb,KAAK,KAAK,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAUvF;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,yCAAyC;IACzC,KAAK,EAAE,QAAQ,CAAC;IAEhB,6BAA6B;IAC7B,YAAY,EAAE,MAAM,CAAC;IAErB,4CAA4C;IAC5C,KAAK,EAAE,KAAK,CAAC;IAEb,4CAA4C;IAC5C,KAAK,EAAE,KAAK,CAAC;IAEb,2CAA2C;IAC3C,OAAO,EAAE,OAAO,CAAC;IAEjB,6DAA6D;IAC7D,IAAI,EAAE,QAAQ,CAAC;IAEf,uDAAuD;IACvD,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,eAAgB,YAAW,QAAQ;IAC9C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAW;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,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package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statewalker/vcs-commands",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Git-like VCS commands (commit, checkout, merge, diff, log)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -17,41 +17,46 @@
|
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
+
"source": "./src/index.ts",
|
|
20
21
|
"types": "./dist/index.d.ts",
|
|
21
22
|
"import": "./dist/index.js"
|
|
22
23
|
},
|
|
23
24
|
"./commands": {
|
|
25
|
+
"source": "./src/commands/index.ts",
|
|
24
26
|
"types": "./dist/commands/index.d.ts",
|
|
25
27
|
"import": "./dist/commands/index.js"
|
|
26
28
|
},
|
|
27
29
|
"./errors": {
|
|
30
|
+
"source": "./src/errors/index.ts",
|
|
28
31
|
"types": "./dist/errors/index.d.ts",
|
|
29
32
|
"import": "./dist/errors/index.js"
|
|
30
33
|
},
|
|
31
34
|
"./results": {
|
|
35
|
+
"source": "./src/results/index.ts",
|
|
32
36
|
"types": "./dist/results/index.d.ts",
|
|
33
37
|
"import": "./dist/results/index.js"
|
|
34
38
|
}
|
|
35
39
|
},
|
|
36
40
|
"files": [
|
|
37
|
-
"dist"
|
|
41
|
+
"dist",
|
|
42
|
+
"src"
|
|
38
43
|
],
|
|
39
44
|
"dependencies": {
|
|
40
|
-
"@statewalker/vcs-core": "0.
|
|
41
|
-
"@statewalker/vcs-store-
|
|
42
|
-
"@statewalker/vcs-store-
|
|
43
|
-
"@statewalker/vcs-transport": "0.
|
|
44
|
-
"@statewalker/vcs-utils": "0.
|
|
45
|
-
"@statewalker/vcs-working-tree": "0.
|
|
45
|
+
"@statewalker/vcs-core": "^0.3.1",
|
|
46
|
+
"@statewalker/vcs-store-files": "^0.3.1",
|
|
47
|
+
"@statewalker/vcs-store-mem": "^0.3.1",
|
|
48
|
+
"@statewalker/vcs-transport": "^0.3.1",
|
|
49
|
+
"@statewalker/vcs-utils": "^0.3.1",
|
|
50
|
+
"@statewalker/vcs-working-tree": "^0.3.1"
|
|
46
51
|
},
|
|
47
52
|
"devDependencies": {
|
|
48
|
-
"@types/node": "^26.
|
|
49
|
-
"rolldown": "^1.2.
|
|
53
|
+
"@types/node": "^26.6.4",
|
|
54
|
+
"rolldown": "^1.2.12",
|
|
50
55
|
"typescript": "^7.0.2",
|
|
51
|
-
"vitest": "^
|
|
52
|
-
"@statewalker/vcs-transport-adapters": "0.
|
|
53
|
-
"@statewalker/vcs-utils-node": "0.
|
|
54
|
-
"@statewalker/vcs-store-sql": "0.
|
|
56
|
+
"vitest": "^5.0.3",
|
|
57
|
+
"@statewalker/vcs-transport-adapters": "^0.3.1",
|
|
58
|
+
"@statewalker/vcs-utils-node": "^0.3.1",
|
|
59
|
+
"@statewalker/vcs-store-sql": "^0.3.1"
|
|
55
60
|
},
|
|
56
61
|
"scripts": {
|
|
57
62
|
"build": "rm -rf dist && rolldown -c && tsc --emitDeclarationOnly --declaration",
|
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AddCommand - Stage files from working tree to index.
|
|
3
|
+
*
|
|
4
|
+
* Implements JGit-compatible fluent API for `git add` command:
|
|
5
|
+
* - Add new files to index
|
|
6
|
+
* - Update modified files in index
|
|
7
|
+
* - Optionally remove deleted files (--all mode)
|
|
8
|
+
* - Support for update-only mode (-u flag)
|
|
9
|
+
*
|
|
10
|
+
* Reference: jgit/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Add specific files
|
|
15
|
+
* await git.add()
|
|
16
|
+
* .addFilepattern("src/")
|
|
17
|
+
* .addFilepattern("lib/")
|
|
18
|
+
* .call();
|
|
19
|
+
*
|
|
20
|
+
* // Update only tracked files (git add -u)
|
|
21
|
+
* await git.add()
|
|
22
|
+
* .addFilepattern(".")
|
|
23
|
+
* .setUpdate(true)
|
|
24
|
+
* .call();
|
|
25
|
+
*
|
|
26
|
+
* // Add all changes including deletions (git add -A)
|
|
27
|
+
* await git.add()
|
|
28
|
+
* .addFilepattern(".")
|
|
29
|
+
* .setAll(true)
|
|
30
|
+
* .call();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import { FileMode } from "@statewalker/vcs-core";
|
|
35
|
+
import {
|
|
36
|
+
DeleteStagingEntry,
|
|
37
|
+
UpdateStagingEntry,
|
|
38
|
+
type Worktree,
|
|
39
|
+
} from "@statewalker/vcs-working-tree";
|
|
40
|
+
|
|
41
|
+
import {
|
|
42
|
+
IncompatibleOptionsError,
|
|
43
|
+
NoFilepatternError,
|
|
44
|
+
StoreNotAvailableError,
|
|
45
|
+
} from "../errors/index.js";
|
|
46
|
+
import { GitCommand } from "../git-command.js";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Result of AddCommand execution.
|
|
50
|
+
*
|
|
51
|
+
* Contains lists of affected paths.
|
|
52
|
+
*/
|
|
53
|
+
export interface AddResult {
|
|
54
|
+
/** Paths that were added or updated in the index */
|
|
55
|
+
readonly added: string[];
|
|
56
|
+
|
|
57
|
+
/** Paths that were skipped (ignored files) */
|
|
58
|
+
readonly skipped: string[];
|
|
59
|
+
|
|
60
|
+
/** Paths that were removed from index (deleted files in --all mode) */
|
|
61
|
+
readonly removed: string[];
|
|
62
|
+
|
|
63
|
+
/** Total number of files processed */
|
|
64
|
+
readonly totalProcessed: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Check if a path matches any pattern.
|
|
69
|
+
*
|
|
70
|
+
* Supports glob patterns:
|
|
71
|
+
* - "." matches all files
|
|
72
|
+
* - "*" matches within a single path component
|
|
73
|
+
* - "**" matches across path separators
|
|
74
|
+
* - Exact directory prefix matches (e.g., "src" matches "src/file.ts")
|
|
75
|
+
*/
|
|
76
|
+
function matchesPattern(path: string, patterns: string[]): boolean {
|
|
77
|
+
for (const pattern of patterns) {
|
|
78
|
+
if (matchGlob(path, pattern)) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Simple glob matching.
|
|
87
|
+
*/
|
|
88
|
+
function matchGlob(path: string, pattern: string): boolean {
|
|
89
|
+
// "." matches everything
|
|
90
|
+
if (pattern === ".") {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Exact match
|
|
95
|
+
if (path === pattern) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Directory prefix (e.g., "src" matches "src/file")
|
|
100
|
+
if (path.startsWith(`${pattern}/`)) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Extension patterns like "*.ts"
|
|
105
|
+
if (pattern.startsWith("*.") && !pattern.includes("/")) {
|
|
106
|
+
const extension = pattern.slice(1);
|
|
107
|
+
return path.endsWith(extension);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Handle **/* pattern (matches all files)
|
|
111
|
+
if (pattern === "**/*") {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Glob patterns with * or **
|
|
116
|
+
if (pattern.includes("*")) {
|
|
117
|
+
// Escape regex special chars except * and ?
|
|
118
|
+
const escapedPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
119
|
+
|
|
120
|
+
// ** matches anything including path separators
|
|
121
|
+
// * matches anything except path separators
|
|
122
|
+
const regexPattern = escapedPattern
|
|
123
|
+
.replace(/\*\*/g, "<<<DOUBLESTAR>>>")
|
|
124
|
+
.replace(/\*/g, "[^/]*")
|
|
125
|
+
.replace(/<<<DOUBLESTAR>>>/g, ".*")
|
|
126
|
+
.replace(/\?/g, ".");
|
|
127
|
+
|
|
128
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
129
|
+
return regex.test(path);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Command to stage files from working tree to index.
|
|
137
|
+
*
|
|
138
|
+
* Based on JGit's AddCommand. Provides fluent builder API
|
|
139
|
+
* for staging files with various options.
|
|
140
|
+
*/
|
|
141
|
+
export class AddCommand extends GitCommand<AddResult> {
|
|
142
|
+
private filepatterns: string[] = [];
|
|
143
|
+
private update = false;
|
|
144
|
+
private all: boolean | undefined;
|
|
145
|
+
private force = false;
|
|
146
|
+
private intentToAdd = false;
|
|
147
|
+
private worktreeIterator: Worktree | undefined;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Add a path to a file/directory whose content should be added.
|
|
151
|
+
*
|
|
152
|
+
* A directory name (e.g., "src" to add "src/file1" and "src/file2")
|
|
153
|
+
* can also be given to add all files in the directory recursively.
|
|
154
|
+
*
|
|
155
|
+
* If pattern "." is added, all changes in the repository will be added.
|
|
156
|
+
*
|
|
157
|
+
* @param filepattern Repository-relative path (with "/" as separator)
|
|
158
|
+
* @returns this for chaining
|
|
159
|
+
*/
|
|
160
|
+
addFilepattern(filepattern: string): this {
|
|
161
|
+
this.checkCallable();
|
|
162
|
+
this.filepatterns.push(filepattern);
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Set whether to only match against already tracked files.
|
|
168
|
+
*
|
|
169
|
+
* If true, stages modified tracked files and removes deleted
|
|
170
|
+
* tracked files from index, but never adds new files.
|
|
171
|
+
*
|
|
172
|
+
* Equivalent to `git add -u`.
|
|
173
|
+
*
|
|
174
|
+
* @param update Whether to only update tracked files
|
|
175
|
+
* @returns this for chaining
|
|
176
|
+
*/
|
|
177
|
+
setUpdate(update: boolean): this {
|
|
178
|
+
this.checkCallable();
|
|
179
|
+
this.update = update;
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Whether update mode is enabled.
|
|
185
|
+
*/
|
|
186
|
+
isUpdate(): boolean {
|
|
187
|
+
return this.update;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Set whether to also stage deletions.
|
|
192
|
+
*
|
|
193
|
+
* If true, removed files in the working tree will be
|
|
194
|
+
* removed from the index as well.
|
|
195
|
+
*
|
|
196
|
+
* Equivalent to `git add -A` or `git add --all`.
|
|
197
|
+
*
|
|
198
|
+
* @param all Whether to stage deletions
|
|
199
|
+
* @returns this for chaining
|
|
200
|
+
*/
|
|
201
|
+
setAll(all: boolean): this {
|
|
202
|
+
this.checkCallable();
|
|
203
|
+
this.all = all;
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Whether --all mode is enabled.
|
|
209
|
+
*/
|
|
210
|
+
isAll(): boolean {
|
|
211
|
+
return this.all === true;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Set whether to add ignored files.
|
|
216
|
+
*
|
|
217
|
+
* If true, files normally ignored by .gitignore will be added.
|
|
218
|
+
*
|
|
219
|
+
* Equivalent to `git add -f` or `git add --force`.
|
|
220
|
+
*
|
|
221
|
+
* @param force Whether to add ignored files
|
|
222
|
+
* @returns this for chaining
|
|
223
|
+
*/
|
|
224
|
+
setForce(force: boolean): this {
|
|
225
|
+
this.checkCallable();
|
|
226
|
+
this.force = force;
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Whether force mode is enabled.
|
|
232
|
+
*/
|
|
233
|
+
isForce(): boolean {
|
|
234
|
+
return this.force;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Set whether to only record intent to add.
|
|
239
|
+
*
|
|
240
|
+
* If true, files are added as "intent to add" placeholders
|
|
241
|
+
* without staging their content.
|
|
242
|
+
*
|
|
243
|
+
* Equivalent to `git add -N` or `git add --intent-to-add`.
|
|
244
|
+
*
|
|
245
|
+
* @param intentToAdd Whether to only record intent
|
|
246
|
+
* @returns this for chaining
|
|
247
|
+
*/
|
|
248
|
+
setIntentToAdd(intentToAdd: boolean): this {
|
|
249
|
+
this.checkCallable();
|
|
250
|
+
this.intentToAdd = intentToAdd;
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Whether intent-to-add mode is enabled.
|
|
256
|
+
*/
|
|
257
|
+
isIntentToAdd(): boolean {
|
|
258
|
+
return this.intentToAdd;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Set a custom working tree iterator.
|
|
263
|
+
*
|
|
264
|
+
* Allows using a custom implementation for filesystem access.
|
|
265
|
+
*
|
|
266
|
+
* @param iterator Custom working tree iterator
|
|
267
|
+
* @returns this for chaining
|
|
268
|
+
*/
|
|
269
|
+
setWorktreeStore(iterator: Worktree): this {
|
|
270
|
+
this.checkCallable();
|
|
271
|
+
this.worktreeIterator = iterator;
|
|
272
|
+
return this;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Execute the add command.
|
|
277
|
+
*
|
|
278
|
+
* @returns Result with lists of added, skipped, and removed paths
|
|
279
|
+
* @throws NoFilepatternError if no file patterns specified and not in update/all mode
|
|
280
|
+
* @throws Error if working tree iterator not available
|
|
281
|
+
*/
|
|
282
|
+
async call(): Promise<AddResult> {
|
|
283
|
+
this.checkCallable();
|
|
284
|
+
this.setCallable(false);
|
|
285
|
+
|
|
286
|
+
// Validate options - update and all are mutually exclusive
|
|
287
|
+
if (this.update && this.all !== undefined) {
|
|
288
|
+
throw new IncompatibleOptionsError(["--update", "--all/--no-all"]);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Determine if we're adding all files
|
|
292
|
+
let addAll: boolean;
|
|
293
|
+
if (this.filepatterns.length === 0) {
|
|
294
|
+
if (this.update || this.all !== undefined) {
|
|
295
|
+
addAll = true;
|
|
296
|
+
} else {
|
|
297
|
+
throw new NoFilepatternError("At least one file pattern is required");
|
|
298
|
+
}
|
|
299
|
+
} else {
|
|
300
|
+
addAll = this.filepatterns.includes(".");
|
|
301
|
+
if (this.all === undefined && !this.update) {
|
|
302
|
+
this.all = true;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Get working tree iterator
|
|
307
|
+
const worktree = this.getWorktreeIterator();
|
|
308
|
+
if (!worktree) {
|
|
309
|
+
throw new StoreNotAvailableError(
|
|
310
|
+
"Worktree",
|
|
311
|
+
"Working tree iterator not available. " +
|
|
312
|
+
"Ensure WorkingCopy has worktree or call setWorktreeStore().",
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Whether to stage deletions
|
|
317
|
+
const stageDeletions = this.update || (this.all !== undefined && this.all);
|
|
318
|
+
|
|
319
|
+
// Use addAll pattern if needed
|
|
320
|
+
const patterns = addAll ? ["."] : this.filepatterns;
|
|
321
|
+
|
|
322
|
+
// Process files
|
|
323
|
+
return this.processFiles(worktree, patterns, stageDeletions);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Get working tree iterator from store or explicitly set.
|
|
328
|
+
*/
|
|
329
|
+
private getWorktreeIterator(): Worktree | undefined {
|
|
330
|
+
if (this.worktreeIterator) {
|
|
331
|
+
return this.worktreeIterator;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Get worktree from WorkingCopy
|
|
335
|
+
return this.worktreeAccess;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Process files for staging.
|
|
340
|
+
*/
|
|
341
|
+
private async processFiles(
|
|
342
|
+
worktree: Worktree,
|
|
343
|
+
patterns: string[],
|
|
344
|
+
stageDeletions: boolean,
|
|
345
|
+
): Promise<AddResult> {
|
|
346
|
+
const added: string[] = [];
|
|
347
|
+
const skipped: string[] = [];
|
|
348
|
+
const removed: string[] = [];
|
|
349
|
+
|
|
350
|
+
// Collect files to process
|
|
351
|
+
const filesToProcess: Array<{
|
|
352
|
+
path: string;
|
|
353
|
+
exists: boolean;
|
|
354
|
+
isIgnored: boolean;
|
|
355
|
+
}> = [];
|
|
356
|
+
|
|
357
|
+
// Walk worktree to find matching files
|
|
358
|
+
for await (const entry of worktree.walk({ includeIgnored: true })) {
|
|
359
|
+
if (entry.isDirectory) continue;
|
|
360
|
+
|
|
361
|
+
// Check if file matches any pattern
|
|
362
|
+
if (!matchesPattern(entry.path, patterns)) {
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Skip ignored files unless force
|
|
367
|
+
if (entry.isIgnored && !this.force) {
|
|
368
|
+
skipped.push(entry.path);
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
filesToProcess.push({
|
|
373
|
+
path: entry.path,
|
|
374
|
+
exists: true,
|
|
375
|
+
isIgnored: entry.isIgnored,
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// If update or all mode, check for deleted files in index
|
|
380
|
+
if (this.update || stageDeletions) {
|
|
381
|
+
const indexedPaths = new Set<string>();
|
|
382
|
+
for await (const entry of this.staging.entries()) {
|
|
383
|
+
if (entry.stage === 0) {
|
|
384
|
+
indexedPaths.add(entry.path);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Find paths in index that match patterns but not in worktree
|
|
389
|
+
for (const indexPath of indexedPaths) {
|
|
390
|
+
if (!matchesPattern(indexPath, patterns)) {
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const worktreeEntry = await worktree.getEntry(indexPath);
|
|
395
|
+
if (!worktreeEntry) {
|
|
396
|
+
// File was deleted from worktree
|
|
397
|
+
filesToProcess.push({
|
|
398
|
+
path: indexPath,
|
|
399
|
+
exists: false,
|
|
400
|
+
isIgnored: false,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// If update mode, filter to only tracked files
|
|
407
|
+
if (this.update) {
|
|
408
|
+
const trackedPaths = new Set<string>();
|
|
409
|
+
for await (const entry of this.staging.entries()) {
|
|
410
|
+
if (entry.stage === 0) {
|
|
411
|
+
trackedPaths.add(entry.path);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const filtered = filesToProcess.filter((f) => trackedPaths.has(f.path));
|
|
416
|
+
filesToProcess.length = 0;
|
|
417
|
+
filesToProcess.push(...filtered);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Process files
|
|
421
|
+
const editor = this.staging.createEditor();
|
|
422
|
+
|
|
423
|
+
for (const file of filesToProcess) {
|
|
424
|
+
if (!file.exists) {
|
|
425
|
+
// File deleted from worktree - remove from index
|
|
426
|
+
editor.add(new DeleteStagingEntry(file.path));
|
|
427
|
+
removed.push(file.path);
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (this.intentToAdd) {
|
|
432
|
+
// Just mark as intent-to-add (placeholder with empty blob)
|
|
433
|
+
const worktreeEntry = await worktree.getEntry(file.path);
|
|
434
|
+
const mode = worktreeEntry?.mode ?? FileMode.REGULAR_FILE;
|
|
435
|
+
editor.add(
|
|
436
|
+
new UpdateStagingEntry(file.path, "", mode, {
|
|
437
|
+
size: 0,
|
|
438
|
+
mtime: Date.now(),
|
|
439
|
+
}),
|
|
440
|
+
);
|
|
441
|
+
added.push(file.path);
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// Get file info
|
|
446
|
+
const worktreeEntry = await worktree.getEntry(file.path);
|
|
447
|
+
if (!worktreeEntry) {
|
|
448
|
+
// File disappeared during processing
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// Hash and store content
|
|
453
|
+
const objectId = await this.storeFileContent(worktree, file.path);
|
|
454
|
+
|
|
455
|
+
// Add to staging
|
|
456
|
+
editor.add(
|
|
457
|
+
new UpdateStagingEntry(file.path, objectId, worktreeEntry.mode, {
|
|
458
|
+
size: worktreeEntry.size,
|
|
459
|
+
mtime: worktreeEntry.mtime,
|
|
460
|
+
}),
|
|
461
|
+
);
|
|
462
|
+
added.push(file.path);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Apply changes
|
|
466
|
+
await editor.finish();
|
|
467
|
+
|
|
468
|
+
// Persist staging changes (required for FileStagingStore)
|
|
469
|
+
await this.staging.write();
|
|
470
|
+
|
|
471
|
+
return {
|
|
472
|
+
added,
|
|
473
|
+
skipped,
|
|
474
|
+
removed,
|
|
475
|
+
totalProcessed: added.length + removed.length,
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Store file content as blob and return object ID.
|
|
481
|
+
*
|
|
482
|
+
* Note: The object store handles blob header internally.
|
|
483
|
+
*/
|
|
484
|
+
private async storeFileContent(worktree: Worktree, path: string): Promise<string> {
|
|
485
|
+
// Read content from working tree
|
|
486
|
+
const chunks: Uint8Array[] = [];
|
|
487
|
+
for await (const chunk of worktree.readContent(path)) {
|
|
488
|
+
chunks.push(chunk);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// Store raw content - the blob store handles blob formatting
|
|
492
|
+
return this.blobs.store(chunks);
|
|
493
|
+
}
|
|
494
|
+
}
|