@vibe-validate/git 0.17.0-rc.5 → 0.17.0-rc.6

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.
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Git Command Utilities
3
+ *
4
+ * Standardized git command execution with consistent options and error handling.
5
+ * Consolidates scattered git rev-parse usage across packages.
6
+ */
7
+ /**
8
+ * Check if the current directory is inside a git repository
9
+ * @returns true if inside a git repository, false otherwise
10
+ */
11
+ export declare function isGitRepository(): boolean;
12
+ /**
13
+ * Get the path to the .git directory
14
+ * @returns The absolute path to the .git directory
15
+ * @throws Error if not in a git repository
16
+ */
17
+ export declare function getGitDir(): string;
18
+ /**
19
+ * Get the root directory of the git repository
20
+ * @returns The absolute path to the repository root
21
+ * @throws Error if not in a git repository
22
+ */
23
+ export declare function getRepositoryRoot(): string;
24
+ /**
25
+ * Get the current branch name
26
+ * @returns The name of the current branch
27
+ * @throws Error if not on a branch (detached HEAD)
28
+ */
29
+ export declare function getCurrentBranch(): string;
30
+ /**
31
+ * Get the commit SHA of HEAD
32
+ * @returns The full SHA of the current commit
33
+ * @throws Error if not in a git repository or HEAD is invalid
34
+ */
35
+ export declare function getHeadCommitSha(): string;
36
+ /**
37
+ * Get the tree hash of the current HEAD commit
38
+ * @returns The tree hash of HEAD
39
+ * @throws Error if not in a git repository or HEAD is invalid
40
+ */
41
+ export declare function getHeadTreeSha(): string;
42
+ /**
43
+ * Verify that a git reference exists
44
+ * @param ref - The reference to verify (branch, tag, commit SHA, etc.)
45
+ * @returns true if the reference exists, false otherwise
46
+ */
47
+ export declare function verifyRef(ref: string): boolean;
48
+ /**
49
+ * Verify that a git reference exists (alternate form for backwards compatibility)
50
+ * @param ref - The reference to verify
51
+ * @returns The SHA of the reference if it exists
52
+ * @throws Error if the reference doesn't exist
53
+ */
54
+ export declare function verifyRefOrThrow(ref: string): string;
55
+ /**
56
+ * Check if git notes exist for a specific ref
57
+ * @param notesRef - The notes reference to check (e.g., 'refs/notes/vibe-validate/validate')
58
+ * @returns true if the notes ref exists, false otherwise
59
+ */
60
+ export declare function hasNotesRef(notesRef: string): boolean;
61
+ //# sourceMappingURL=git-commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-commands.d.ts","sourceRoot":"","sources":["../src/git-commands.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6BH;;;GAGG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAOzC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO9C;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAWrD"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Git Command Utilities
3
+ *
4
+ * Standardized git command execution with consistent options and error handling.
5
+ * Consolidates scattered git rev-parse usage across packages.
6
+ */
7
+ import { execSync } from 'node:child_process';
8
+ /**
9
+ * Standard options for git command execution
10
+ */
11
+ const GIT_OPTIONS = {
12
+ encoding: 'utf8',
13
+ timeout: 30000, // 30 seconds
14
+ stdio: 'pipe',
15
+ };
16
+ /**
17
+ * Execute a git command with standard options
18
+ * @param command - The git command to execute
19
+ * @param options - Optional overrides for execution options
20
+ * @returns The command output, trimmed of whitespace
21
+ * @throws Error if the command fails
22
+ */
23
+ function execGitCommand(command, options) {
24
+ try {
25
+ const result = execSync(command, { ...GIT_OPTIONS, ...options });
26
+ return result.trim();
27
+ }
28
+ catch (error) {
29
+ throw new Error(`Git command failed: ${command}`, { cause: error });
30
+ }
31
+ }
32
+ /**
33
+ * Check if the current directory is inside a git repository
34
+ * @returns true if inside a git repository, false otherwise
35
+ */
36
+ export function isGitRepository() {
37
+ try {
38
+ execGitCommand('git rev-parse --is-inside-work-tree');
39
+ return true;
40
+ }
41
+ catch {
42
+ return false;
43
+ }
44
+ }
45
+ /**
46
+ * Get the path to the .git directory
47
+ * @returns The absolute path to the .git directory
48
+ * @throws Error if not in a git repository
49
+ */
50
+ export function getGitDir() {
51
+ return execGitCommand('git rev-parse --git-dir');
52
+ }
53
+ /**
54
+ * Get the root directory of the git repository
55
+ * @returns The absolute path to the repository root
56
+ * @throws Error if not in a git repository
57
+ */
58
+ export function getRepositoryRoot() {
59
+ return execGitCommand('git rev-parse --show-toplevel');
60
+ }
61
+ /**
62
+ * Get the current branch name
63
+ * @returns The name of the current branch
64
+ * @throws Error if not on a branch (detached HEAD)
65
+ */
66
+ export function getCurrentBranch() {
67
+ return execGitCommand('git rev-parse --abbrev-ref HEAD');
68
+ }
69
+ /**
70
+ * Get the commit SHA of HEAD
71
+ * @returns The full SHA of the current commit
72
+ * @throws Error if not in a git repository or HEAD is invalid
73
+ */
74
+ export function getHeadCommitSha() {
75
+ return execGitCommand('git rev-parse HEAD');
76
+ }
77
+ /**
78
+ * Get the tree hash of the current HEAD commit
79
+ * @returns The tree hash of HEAD
80
+ * @throws Error if not in a git repository or HEAD is invalid
81
+ */
82
+ export function getHeadTreeSha() {
83
+ return execGitCommand('git rev-parse HEAD^{tree}');
84
+ }
85
+ /**
86
+ * Verify that a git reference exists
87
+ * @param ref - The reference to verify (branch, tag, commit SHA, etc.)
88
+ * @returns true if the reference exists, false otherwise
89
+ */
90
+ export function verifyRef(ref) {
91
+ try {
92
+ execGitCommand(`git rev-parse --verify ${ref}`);
93
+ return true;
94
+ }
95
+ catch {
96
+ return false;
97
+ }
98
+ }
99
+ /**
100
+ * Verify that a git reference exists (alternate form for backwards compatibility)
101
+ * @param ref - The reference to verify
102
+ * @returns The SHA of the reference if it exists
103
+ * @throws Error if the reference doesn't exist
104
+ */
105
+ export function verifyRefOrThrow(ref) {
106
+ return execGitCommand(`git rev-parse --verify ${ref}`);
107
+ }
108
+ /**
109
+ * Check if git notes exist for a specific ref
110
+ * @param notesRef - The notes reference to check (e.g., 'refs/notes/vibe-validate/validate')
111
+ * @returns true if the notes ref exists, false otherwise
112
+ */
113
+ export function hasNotesRef(notesRef) {
114
+ try {
115
+ // Use || true to prevent error when notes don't exist
116
+ const result = execSync(`git rev-parse --verify ${notesRef} 2>/dev/null || true`, {
117
+ encoding: 'utf8',
118
+ timeout: GIT_OPTIONS.timeout,
119
+ }).trim();
120
+ return result.length > 0;
121
+ }
122
+ catch {
123
+ return false;
124
+ }
125
+ }
126
+ //# sourceMappingURL=git-commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-commands.js","sourceRoot":"","sources":["../src/git-commands.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,GAAG;IAClB,QAAQ,EAAE,MAAe;IACzB,OAAO,EAAE,KAAK,EAAE,aAAa;IAC7B,KAAK,EAAE,MAAe;CACd,CAAC;AAEX;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,OAAe,EAAE,OAAqC;IAC5E,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;QACjE,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,uBAAuB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CA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AAW,CAAC,OAAO;SAC7B,CAAC,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -11,4 +11,5 @@ export { BranchSyncChecker, checkBranchSync, type SyncCheckResult, type SyncChec
11
11
  export { PostPRMergeCleanup, cleanupMergedBranches, type CleanupResult, type CleanupOptions } from './post-merge-cleanup.js';
12
12
  export { encodeRunCacheKey } from './cache-key.js';
13
13
  export { extractYamlContent, extractYamlWithPreamble } from './yaml-detection.js';
14
+ export { isGitRepository, getGitDir, getRepositoryRoot, getCurrentBranch, getHeadCommitSha, getHeadTreeSha, verifyRef, verifyRefOrThrow, hasNotesRef } from './git-commands.js';
14
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,cAAc,EACd,eAAe,EACf,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,cAAc,EACd,eAAe,EACf,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,eAAe,EACf,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,WAAW,EACZ,MAAM,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -16,4 +16,6 @@ export { PostPRMergeCleanup, cleanupMergedBranches } from './post-merge-cleanup.
16
16
  export { encodeRunCacheKey } from './cache-key.js';
17
17
  // YAML output detection
18
18
  export { extractYamlContent, extractYamlWithPreamble } from './yaml-detection.js';
19
+ // Git command utilities (standardized rev-parse operations)
20
+ export { isGitRepository, getGitDir, getRepositoryRoot, getCurrentBranch, getHeadCommitSha, getHeadTreeSha, verifyRef, verifyRefOrThrow, hasNotesRef } from './git-commands.js';
19
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,uDAAuD;AACvD,OAAO,EACL,cAAc,EACd,eAAe,EACf,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,6CAA6C;AAC7C,OAAO,EACL,iBAAiB,EACjB,eAAe,EAGhB,MAAM,kBAAkB,CAAC;AAE1B,8CAA8C;AAC9C,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EAGtB,MAAM,yBAAyB,CAAC;AAEjC,qCAAqC;AACrC,OAAO,EACL,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAExB,wBAAwB;AACxB,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,uDAAuD;AACvD,OAAO,EACL,cAAc,EACd,eAAe,EACf,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,6CAA6C;AAC7C,OAAO,EACL,iBAAiB,EACjB,eAAe,EAGhB,MAAM,kBAAkB,CAAC;AAE1B,8CAA8C;AAC9C,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EAGtB,MAAM,yBAAyB,CAAC;AAEjC,qCAAqC;AACrC,OAAO,EACL,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAExB,wBAAwB;AACxB,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,qBAAqB,CAAC;AAE7B,4DAA4D;AAC5D,OAAO,EACL,eAAe,EACf,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,WAAW,EACZ,MAAM,mBAAmB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-validate/git",
3
- "version": "0.17.0-rc.5",
3
+ "version": "0.17.0-rc.6",
4
4
  "description": "Git utilities for vibe-validate - tree hash calculation, branch sync, and post-merge cleanup",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",