@vibe-validate/git 0.17.0-rc.11 → 0.17.0-rc.13
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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/staging.d.ts +43 -0
- package/dist/staging.d.ts.map +1 -0
- package/dist/staging.js +77 -0
- package/dist/staging.js.map +1 -0
- package/dist/tracking-branch.d.ts +34 -0
- package/dist/tracking-branch.d.ts.map +1 -0
- package/dist/tracking-branch.js +66 -0
- package/dist/tracking-branch.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -14,4 +14,6 @@ export { extractYamlContent, extractYamlWithPreamble } from './yaml-detection.js
|
|
|
14
14
|
export { isGitRepository, getGitDir, getRepositoryRoot, getCurrentBranch, getHeadCommitSha, getHeadTreeSha, verifyRef, verifyRefOrThrow, hasNotesRef } from './git-commands.js';
|
|
15
15
|
export { executeGitCommand, execGitCommand, tryGitCommand, validateGitRef, validateNotesRef, validateTreeHash, type GitExecutionOptions, type GitExecutionResult } from './git-executor.js';
|
|
16
16
|
export { addNote, readNote, removeNote, listNotes, hasNote, listNotesRefs, removeNotesRefs, getNotesRefSha } from './git-notes.js';
|
|
17
|
+
export { getPartiallyStagedFiles } from './staging.js';
|
|
18
|
+
export { isCurrentBranchBehindTracking } from './tracking-branch.js';
|
|
17
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;AAG7B,OAAO,EACL,eAAe,EACf,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACxB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,OAAO,EACP,QAAQ,EACR,UAAU,EACV,SAAS,EACT,OAAO,EACP,aAAa,EACb,eAAe,EACf,cAAc,EACf,MAAM,gBAAgB,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;AAG3B,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACxB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,OAAO,EACP,QAAQ,EACR,UAAU,EACV,SAAS,EACT,OAAO,EACP,aAAa,EACb,eAAe,EACf,cAAc,EACf,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,uBAAuB,EACxB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,6BAA6B,EAC9B,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -22,4 +22,8 @@ export { isGitRepository, getGitDir, getRepositoryRoot, getCurrentBranch, getHea
|
|
|
22
22
|
export { executeGitCommand, execGitCommand, tryGitCommand, validateGitRef, validateNotesRef, validateTreeHash } from './git-executor.js';
|
|
23
23
|
// Git notes operations (high-level abstraction)
|
|
24
24
|
export { addNote, readNote, removeNote, listNotes, hasNote, listNotesRefs, removeNotesRefs, getNotesRefSha } from './git-notes.js';
|
|
25
|
+
// Git staging detection (prevent partially staged files in pre-commit)
|
|
26
|
+
export { getPartiallyStagedFiles } from './staging.js';
|
|
27
|
+
// Git tracking branch detection (check if current branch is behind remote)
|
|
28
|
+
export { isCurrentBranchBehindTracking } from './tracking-branch.js';
|
|
25
29
|
//# 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;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;AAE3B,+EAA+E;AAC/E,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAGjB,MAAM,mBAAmB,CAAC;AAE3B,gDAAgD;AAChD,OAAO,EACL,OAAO,EACP,QAAQ,EACR,UAAU,EACV,SAAS,EACT,OAAO,EACP,aAAa,EACb,eAAe,EACf,cAAc,EACf,MAAM,gBAAgB,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;AAE3B,+EAA+E;AAC/E,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAGjB,MAAM,mBAAmB,CAAC;AAE3B,gDAAgD;AAChD,OAAO,EACL,OAAO,EACP,QAAQ,EACR,UAAU,EACV,SAAS,EACT,OAAO,EACP,aAAa,EACb,eAAe,EACf,cAAc,EACf,MAAM,gBAAgB,CAAC;AAExB,uEAAuE;AACvE,OAAO,EACL,uBAAuB,EACxB,MAAM,cAAc,CAAC;AAEtB,2EAA2E;AAC3E,OAAO,EACL,6BAA6B,EAC9B,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git Staging Detection
|
|
3
|
+
*
|
|
4
|
+
* Detects partially staged files to prevent validation mismatches.
|
|
5
|
+
*
|
|
6
|
+
* ## The Problem
|
|
7
|
+
*
|
|
8
|
+
* If a file has BOTH staged and unstaged changes:
|
|
9
|
+
* 1. vibe-validate validates the FULL working tree state (staged + unstaged)
|
|
10
|
+
* 2. git commit only commits the STAGED portion
|
|
11
|
+
* 3. Result: Validated code != committed code
|
|
12
|
+
*
|
|
13
|
+
* ## Solution
|
|
14
|
+
*
|
|
15
|
+
* Pre-commit hook must detect and block partially staged files.
|
|
16
|
+
* Users can:
|
|
17
|
+
* - Stage all changes: `git add <file>`
|
|
18
|
+
* - Unstage all changes: `git restore --staged <file>`
|
|
19
|
+
* - Skip validation: `git commit --no-verify` (not recommended)
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Get list of files with partially staged changes
|
|
23
|
+
*
|
|
24
|
+
* A file is "partially staged" if it has BOTH:
|
|
25
|
+
* - Changes in the staging area (git diff --cached)
|
|
26
|
+
* - Changes in the working tree (git diff)
|
|
27
|
+
*
|
|
28
|
+
* This indicates the user staged some changes but not others,
|
|
29
|
+
* which is incompatible with validation.
|
|
30
|
+
*
|
|
31
|
+
* @returns Array of file paths with partially staged changes, empty if none
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const files = getPartiallyStagedFiles();
|
|
36
|
+
* if (files.length > 0) {
|
|
37
|
+
* console.error('Partially staged files detected:', files);
|
|
38
|
+
* console.error('Stage all changes with: git add ' + files.join(' '));
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function getPartiallyStagedFiles(): string[];
|
|
43
|
+
//# sourceMappingURL=staging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staging.d.ts","sourceRoot":"","sources":["../src/staging.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAWH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,EAAE,CAkClD"}
|
package/dist/staging.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git Staging Detection
|
|
3
|
+
*
|
|
4
|
+
* Detects partially staged files to prevent validation mismatches.
|
|
5
|
+
*
|
|
6
|
+
* ## The Problem
|
|
7
|
+
*
|
|
8
|
+
* If a file has BOTH staged and unstaged changes:
|
|
9
|
+
* 1. vibe-validate validates the FULL working tree state (staged + unstaged)
|
|
10
|
+
* 2. git commit only commits the STAGED portion
|
|
11
|
+
* 3. Result: Validated code != committed code
|
|
12
|
+
*
|
|
13
|
+
* ## Solution
|
|
14
|
+
*
|
|
15
|
+
* Pre-commit hook must detect and block partially staged files.
|
|
16
|
+
* Users can:
|
|
17
|
+
* - Stage all changes: `git add <file>`
|
|
18
|
+
* - Unstage all changes: `git restore --staged <file>`
|
|
19
|
+
* - Skip validation: `git commit --no-verify` (not recommended)
|
|
20
|
+
*/
|
|
21
|
+
import { execSync } from 'node:child_process';
|
|
22
|
+
const GIT_TIMEOUT = 30000;
|
|
23
|
+
const GIT_OPTIONS = {
|
|
24
|
+
encoding: 'utf8',
|
|
25
|
+
timeout: GIT_TIMEOUT,
|
|
26
|
+
stdio: ['pipe', 'pipe', 'ignore'],
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Get list of files with partially staged changes
|
|
30
|
+
*
|
|
31
|
+
* A file is "partially staged" if it has BOTH:
|
|
32
|
+
* - Changes in the staging area (git diff --cached)
|
|
33
|
+
* - Changes in the working tree (git diff)
|
|
34
|
+
*
|
|
35
|
+
* This indicates the user staged some changes but not others,
|
|
36
|
+
* which is incompatible with validation.
|
|
37
|
+
*
|
|
38
|
+
* @returns Array of file paths with partially staged changes, empty if none
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const files = getPartiallyStagedFiles();
|
|
43
|
+
* if (files.length > 0) {
|
|
44
|
+
* console.error('Partially staged files detected:', files);
|
|
45
|
+
* console.error('Stage all changes with: git add ' + files.join(' '));
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function getPartiallyStagedFiles() {
|
|
50
|
+
try {
|
|
51
|
+
// Get list of files with staged changes
|
|
52
|
+
const stagedOutput = execSync('git diff --name-only --cached', GIT_OPTIONS);
|
|
53
|
+
const stagedFiles = stagedOutput
|
|
54
|
+
.trim()
|
|
55
|
+
.split('\n')
|
|
56
|
+
.filter(Boolean);
|
|
57
|
+
// No staged files = no partially staged files
|
|
58
|
+
if (stagedFiles.length === 0) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
// Get list of files with unstaged changes
|
|
62
|
+
const unstagedOutput = execSync('git diff --name-only', GIT_OPTIONS);
|
|
63
|
+
const unstagedFiles = new Set(unstagedOutput
|
|
64
|
+
.trim()
|
|
65
|
+
.split('\n')
|
|
66
|
+
.filter(Boolean));
|
|
67
|
+
// Find intersection: files that appear in BOTH staged and unstaged
|
|
68
|
+
const partiallyStagedFiles = stagedFiles.filter((file) => unstagedFiles.has(file));
|
|
69
|
+
return partiallyStagedFiles;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Not a git repository, or git command failed
|
|
73
|
+
// Return empty array - let pre-commit continue and fail elsewhere if needed
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=staging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staging.js","sourceRoot":"","sources":["../src/staging.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,WAAW,GAAG,KAAK,CAAC;AAC1B,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;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,uBAAuB;IACrC,IAAI,CAAC;QACH,wCAAwC;QACxC,MAAM,YAAY,GAAG,QAAQ,CAAC,+BAA+B,EAAE,WAAW,CAAC,CAAC;QAC5E,MAAM,WAAW,GAAG,YAAY;aAC7B,IAAI,EAAE;aACN,KAAK,CAAC,IAAI,CAAC;aACX,MAAM,CAAC,OAAO,CAAC,CAAC;QAEnB,8CAA8C;QAC9C,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,0CAA0C;QAC1C,MAAM,cAAc,GAAG,QAAQ,CAAC,sBAAsB,EAAE,WAAW,CAAC,CAAC;QACrE,MAAM,aAAa,GAAG,IAAI,GAAG,CAC3B,cAAc;aACX,IAAI,EAAE;aACN,KAAK,CAAC,IAAI,CAAC;aACX,MAAM,CAAC,OAAO,CAAC,CACnB,CAAC;QAEF,mEAAmE;QACnE,MAAM,oBAAoB,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CACvD,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CACxB,CAAC;QAEF,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,8CAA8C;QAC9C,4EAA4E;QAC5E,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git Tracking Branch Detection
|
|
3
|
+
*
|
|
4
|
+
* Detects if current branch is behind its remote tracking branch.
|
|
5
|
+
*
|
|
6
|
+
* ## The Problem
|
|
7
|
+
*
|
|
8
|
+
* If you're working on local `fix-issue-X` and someone else pushes to `origin/fix-issue-X`:
|
|
9
|
+
* 1. Your local branch is now behind the remote tracking branch
|
|
10
|
+
* 2. If you commit and push, you may create conflicts or lose their changes
|
|
11
|
+
* 3. You should pull/merge before committing
|
|
12
|
+
*
|
|
13
|
+
* ## Solution
|
|
14
|
+
*
|
|
15
|
+
* Pre-commit hook should detect and warn when current branch is behind its tracking branch.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Check if current branch is behind its remote tracking branch
|
|
19
|
+
*
|
|
20
|
+
* @returns Number of commits behind (0 = up to date), or null if no tracking branch
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const behindBy = isCurrentBranchBehindTracking();
|
|
25
|
+
* if (behindBy === null) {
|
|
26
|
+
* console.log('No remote tracking branch');
|
|
27
|
+
* } else if (behindBy > 0) {
|
|
28
|
+
* console.error(`Behind by ${behindBy} commit(s)`);
|
|
29
|
+
* console.error('Pull changes with: git pull');
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function isCurrentBranchBehindTracking(): number | null;
|
|
34
|
+
//# sourceMappingURL=tracking-branch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracking-branch.d.ts","sourceRoot":"","sources":["../src/tracking-branch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAWH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,6BAA6B,IAAI,MAAM,GAAG,IAAI,CAmC7D"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git Tracking Branch Detection
|
|
3
|
+
*
|
|
4
|
+
* Detects if current branch is behind its remote tracking branch.
|
|
5
|
+
*
|
|
6
|
+
* ## The Problem
|
|
7
|
+
*
|
|
8
|
+
* If you're working on local `fix-issue-X` and someone else pushes to `origin/fix-issue-X`:
|
|
9
|
+
* 1. Your local branch is now behind the remote tracking branch
|
|
10
|
+
* 2. If you commit and push, you may create conflicts or lose their changes
|
|
11
|
+
* 3. You should pull/merge before committing
|
|
12
|
+
*
|
|
13
|
+
* ## Solution
|
|
14
|
+
*
|
|
15
|
+
* Pre-commit hook should detect and warn when current branch is behind its tracking branch.
|
|
16
|
+
*/
|
|
17
|
+
import { execSync } from 'node:child_process';
|
|
18
|
+
const GIT_TIMEOUT = 30000;
|
|
19
|
+
const GIT_OPTIONS = {
|
|
20
|
+
encoding: 'utf8',
|
|
21
|
+
timeout: GIT_TIMEOUT,
|
|
22
|
+
stdio: ['pipe', 'pipe', 'ignore'],
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Check if current branch is behind its remote tracking branch
|
|
26
|
+
*
|
|
27
|
+
* @returns Number of commits behind (0 = up to date), or null if no tracking branch
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const behindBy = isCurrentBranchBehindTracking();
|
|
32
|
+
* if (behindBy === null) {
|
|
33
|
+
* console.log('No remote tracking branch');
|
|
34
|
+
* } else if (behindBy > 0) {
|
|
35
|
+
* console.error(`Behind by ${behindBy} commit(s)`);
|
|
36
|
+
* console.error('Pull changes with: git pull');
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function isCurrentBranchBehindTracking() {
|
|
41
|
+
try {
|
|
42
|
+
// Get the upstream tracking branch for current branch
|
|
43
|
+
// Example output: "origin/fix-issue-X"
|
|
44
|
+
// Throws error if no upstream configured
|
|
45
|
+
const trackingBranch = execSync('git rev-parse --abbrev-ref --symbolic-full-name @{u}', GIT_OPTIONS).trim();
|
|
46
|
+
if (!trackingBranch) {
|
|
47
|
+
// No tracking branch
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
// Count commits behind: HEAD..@{u}
|
|
51
|
+
// This shows commits in tracking branch that are not in HEAD
|
|
52
|
+
const behindOutput = execSync('git rev-list --count HEAD..@{u}', GIT_OPTIONS).trim();
|
|
53
|
+
const behindCount = Number.parseInt(behindOutput, 10);
|
|
54
|
+
// Return 0 if parsing failed (defensive)
|
|
55
|
+
return Number.isNaN(behindCount) ? 0 : behindCount;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
// Check if error is "no upstream configured" (expected for new branches)
|
|
59
|
+
if (error instanceof Error && error.message.includes('no upstream')) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
// Other errors (not in git repo, etc.) - return null
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=tracking-branch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracking-branch.js","sourceRoot":"","sources":["../src/tracking-branch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,WAAW,GAAG,KAAK,CAAC;AAC1B,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;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,6BAA6B;IAC3C,IAAI,CAAC;QACH,sDAAsD;QACtD,uCAAuC;QACvC,yCAAyC;QACzC,MAAM,cAAc,GAAG,QAAQ,CAC7B,sDAAsD,EACtD,WAAW,CACZ,CAAC,IAAI,EAAE,CAAC;QAET,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,qBAAqB;YACrB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,mCAAmC;QACnC,6DAA6D;QAC7D,MAAM,YAAY,GAAG,QAAQ,CAC3B,iCAAiC,EACjC,WAAW,CACZ,CAAC,IAAI,EAAE,CAAC;QAET,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAEtD,yCAAyC;QACzC,OAAO,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;IACrD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,yEAAyE;QACzE,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;YACpE,OAAO,IAAI,CAAC;QACd,CAAC;QAED,qDAAqD;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED