@vibe-validate/git 0.9.10 → 0.10.0
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/tree-hash.d.ts +7 -3
- package/dist/tree-hash.d.ts.map +1 -1
- package/dist/tree-hash.js +43 -22
- package/dist/tree-hash.js.map +1 -1
- package/package.json +1 -1
package/dist/tree-hash.d.ts
CHANGED
|
@@ -14,14 +14,18 @@
|
|
|
14
14
|
* Get deterministic git tree hash representing current working tree state
|
|
15
15
|
*
|
|
16
16
|
* Implementation:
|
|
17
|
-
* 1.
|
|
18
|
-
* 2.
|
|
19
|
-
* 3.
|
|
17
|
+
* 1. Create temporary index file (doesn't affect real index)
|
|
18
|
+
* 2. Copy current index to temporary index
|
|
19
|
+
* 3. Mark untracked files with --intent-to-add in temp index
|
|
20
|
+
* 4. Calculate tree hash with git write-tree using temp index
|
|
21
|
+
* 5. Clean up temp index file
|
|
20
22
|
*
|
|
21
23
|
* Why this is better than git stash create:
|
|
22
24
|
* - git stash create: includes timestamps in commit → different hash each time
|
|
23
25
|
* - git write-tree: content-based only → same content = same hash (deterministic)
|
|
24
26
|
*
|
|
27
|
+
* CRITICAL: Uses GIT_INDEX_FILE to avoid corrupting real index during git commit hooks
|
|
28
|
+
*
|
|
25
29
|
* @returns Git tree SHA-1 hash (40 hex characters)
|
|
26
30
|
* @throws Error if not in a git repository or git command fails
|
|
27
31
|
*/
|
package/dist/tree-hash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-hash.d.ts","sourceRoot":"","sources":["../src/tree-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAWH
|
|
1
|
+
{"version":3,"file":"tree-hash.d.ts","sourceRoot":"","sources":["../src/tree-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAWH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CA+DtD;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,CAQvD;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC,CAS9D"}
|
package/dist/tree-hash.js
CHANGED
|
@@ -21,14 +21,18 @@ const GIT_OPTIONS = {
|
|
|
21
21
|
* Get deterministic git tree hash representing current working tree state
|
|
22
22
|
*
|
|
23
23
|
* Implementation:
|
|
24
|
-
* 1.
|
|
25
|
-
* 2.
|
|
26
|
-
* 3.
|
|
24
|
+
* 1. Create temporary index file (doesn't affect real index)
|
|
25
|
+
* 2. Copy current index to temporary index
|
|
26
|
+
* 3. Mark untracked files with --intent-to-add in temp index
|
|
27
|
+
* 4. Calculate tree hash with git write-tree using temp index
|
|
28
|
+
* 5. Clean up temp index file
|
|
27
29
|
*
|
|
28
30
|
* Why this is better than git stash create:
|
|
29
31
|
* - git stash create: includes timestamps in commit → different hash each time
|
|
30
32
|
* - git write-tree: content-based only → same content = same hash (deterministic)
|
|
31
33
|
*
|
|
34
|
+
* CRITICAL: Uses GIT_INDEX_FILE to avoid corrupting real index during git commit hooks
|
|
35
|
+
*
|
|
32
36
|
* @returns Git tree SHA-1 hash (40 hex characters)
|
|
33
37
|
* @throws Error if not in a git repository or git command fails
|
|
34
38
|
*/
|
|
@@ -36,30 +40,47 @@ export async function getGitTreeHash() {
|
|
|
36
40
|
try {
|
|
37
41
|
// Check if we're in a git repository
|
|
38
42
|
execSync('git rev-parse --is-inside-work-tree', GIT_OPTIONS);
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
// Get git directory and create temp index path
|
|
44
|
+
const gitDir = execSync('git rev-parse --git-dir', GIT_OPTIONS).trim();
|
|
45
|
+
const tempIndexFile = `${gitDir}/vibe-validate-temp-index`;
|
|
42
46
|
try {
|
|
43
|
-
|
|
47
|
+
// Step 1: Copy current index to temp index
|
|
48
|
+
const currentIndex = `${gitDir}/index`;
|
|
49
|
+
execSync(`cp "${currentIndex}" "${tempIndexFile}"`, GIT_OPTIONS);
|
|
50
|
+
// Step 2: Use temp index for all operations (doesn't affect real index)
|
|
51
|
+
const tempIndexOptions = {
|
|
44
52
|
...GIT_OPTIONS,
|
|
45
|
-
|
|
46
|
-
}
|
|
53
|
+
env: { ...process.env, GIT_INDEX_FILE: tempIndexFile }
|
|
54
|
+
};
|
|
55
|
+
// Step 3: Mark all untracked files with --intent-to-add in temp index
|
|
56
|
+
try {
|
|
57
|
+
execSync('git add --intent-to-add --all --force', {
|
|
58
|
+
...tempIndexOptions,
|
|
59
|
+
stdio: ['pipe', 'pipe', 'pipe'] // Capture stderr for error handling
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (addError) {
|
|
63
|
+
// If no untracked files, git add fails with "nothing to add"
|
|
64
|
+
// This is fine - just means we only have tracked files
|
|
65
|
+
const errorMessage = addError instanceof Error ? addError.message : String(addError);
|
|
66
|
+
if (!errorMessage.includes('nothing')) {
|
|
67
|
+
// Real error - re-throw
|
|
68
|
+
throw addError;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Step 4: Get tree hash using temp index (content-based, no timestamps)
|
|
72
|
+
const treeHash = execSync('git write-tree', tempIndexOptions).trim();
|
|
73
|
+
return treeHash;
|
|
47
74
|
}
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
75
|
+
finally {
|
|
76
|
+
// Step 5: Always clean up temp index file
|
|
77
|
+
try {
|
|
78
|
+
execSync(`rm -f "${tempIndexFile}"`, GIT_OPTIONS);
|
|
79
|
+
}
|
|
80
|
+
catch (_cleanupError) {
|
|
81
|
+
// Ignore cleanup errors - temp file cleanup is best effort
|
|
55
82
|
}
|
|
56
83
|
}
|
|
57
|
-
// Step 2: Get tree hash (content-based, no timestamps)
|
|
58
|
-
const treeHash = execSync('git write-tree', GIT_OPTIONS).trim();
|
|
59
|
-
// Step 3: Reset index to clean state (remove intent-to-add marks)
|
|
60
|
-
// This ensures no side effects from our hash calculation
|
|
61
|
-
execSync('git reset', GIT_OPTIONS);
|
|
62
|
-
return treeHash;
|
|
63
84
|
}
|
|
64
85
|
catch (error) {
|
|
65
86
|
// Handle not-in-git-repo case
|
package/dist/tree-hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-hash.js","sourceRoot":"","sources":["../src/tree-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,wCAAwC;AACnE,MAAM,WAAW,GAAG;IAClB,QAAQ,EAAE,MAAe;IACzB,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAA+B;CAChE,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"tree-hash.js","sourceRoot":"","sources":["../src/tree-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,wCAAwC;AACnE,MAAM,WAAW,GAAG;IAClB,QAAQ,EAAE,MAAe;IACzB,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAA+B;CAChE,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,IAAI,CAAC;QACH,qCAAqC;QACrC,QAAQ,CAAC,qCAAqC,EAAE,WAAW,CAAC,CAAC;QAE7D,+CAA+C;QAC/C,MAAM,MAAM,GAAG,QAAQ,CAAC,yBAAyB,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE,CAAC;QACvE,MAAM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