1- import { REPO_ROOT } from "./paths" ;
1+ import { getRepoRoot , REPO_ROOT } from "./paths" ;
22import { exec } from "./shell" ;
33
44export async function isGitRepo ( ) : Promise < boolean > {
5+ const repoRoot = getRepoRoot ( ) ;
56 const result = await exec (
6- `git -C "${ REPO_ROOT } " rev-parse --is-inside-work-tree` ,
7+ `git -C "${ repoRoot } " rev-parse --is-inside-work-tree` ,
78 ) ;
89 return result . success ;
910}
1011
1112export async function getGitStatus ( ) : Promise < string > {
12- const result = await exec ( `git -C "${ REPO_ROOT } " status --short` ) ;
13+ const repoRoot = getRepoRoot ( ) ;
14+ const result = await exec ( `git -C "${ repoRoot } " status --short` ) ;
1315 return result . stdout ;
1416}
1517
@@ -19,68 +21,79 @@ export async function hasChanges(): Promise<boolean> {
1921}
2022
2123export async function getUntrackedFiles ( ) : Promise < string [ ] > {
24+ const repoRoot = getRepoRoot ( ) ;
2225 const result = await exec (
23- `git -C "${ REPO_ROOT } " ls-files --others --exclude-standard` ,
26+ `git -C "${ repoRoot } " ls-files --others --exclude-standard` ,
2427 ) ;
2528 if ( ! result . success || ! result . stdout ) return [ ] ;
2629 return result . stdout . split ( "\n" ) . filter ( Boolean ) ;
2730}
2831
2932export async function getModifiedFiles ( ) : Promise < string [ ] > {
30- const result = await exec ( `git -C "${ REPO_ROOT } " diff --name-only` ) ;
33+ const repoRoot = getRepoRoot ( ) ;
34+ const result = await exec ( `git -C "${ repoRoot } " diff --name-only` ) ;
3135 if ( ! result . success || ! result . stdout ) return [ ] ;
3236 return result . stdout . split ( "\n" ) . filter ( Boolean ) ;
3337}
3438
3539export async function getStagedFiles ( ) : Promise < string [ ] > {
36- const result = await exec ( `git -C "${ REPO_ROOT } " diff --cached --name-only` ) ;
40+ const repoRoot = getRepoRoot ( ) ;
41+ const result = await exec ( `git -C "${ repoRoot } " diff --cached --name-only` ) ;
3742 if ( ! result . success || ! result . stdout ) return [ ] ;
3843 return result . stdout . split ( "\n" ) . filter ( Boolean ) ;
3944}
4045
4146export async function stageAll ( ) : Promise < boolean > {
42- const result = await exec ( `git -C "${ REPO_ROOT } " add -A` ) ;
47+ const repoRoot = getRepoRoot ( ) ;
48+ const result = await exec ( `git -C "${ repoRoot } " add -A` ) ;
4349 return result . success ;
4450}
4551
4652export async function stageFiles ( files : string [ ] ) : Promise < boolean > {
4753 if ( files . length === 0 ) return true ;
54+ const repoRoot = getRepoRoot ( ) ;
4855 const fileList = files . map ( ( f ) => `"${ f } "` ) . join ( " " ) ;
49- const result = await exec ( `git -C "${ REPO_ROOT } " add ${ fileList } ` ) ;
56+ const result = await exec ( `git -C "${ repoRoot } " add ${ fileList } ` ) ;
5057 return result . success ;
5158}
5259
5360export async function commit ( message : string ) : Promise < boolean > {
54- const result = await exec ( `git -C "${ REPO_ROOT } " commit -m "${ message } "` ) ;
61+ const repoRoot = getRepoRoot ( ) ;
62+ const result = await exec ( `git -C "${ repoRoot } " commit -m "${ message } "` ) ;
5563 return result . success ;
5664}
5765
5866export async function push ( ) : Promise < { success : boolean ; message : string } > {
59- const result = await exec ( `git -C "${ REPO_ROOT } " push` ) ;
67+ const repoRoot = getRepoRoot ( ) ;
68+ const result = await exec ( `git -C "${ repoRoot } " push` ) ;
6069 if ( result . success ) {
6170 return { success : true , message : "Pushed to remote" } ;
6271 }
6372 return { success : false , message : result . stderr || "Push failed" } ;
6473}
6574
6675export async function getCurrentBranch ( ) : Promise < string > {
67- const result = await exec ( `git -C "${ REPO_ROOT } " branch --show-current` ) ;
76+ const repoRoot = getRepoRoot ( ) ;
77+ const result = await exec ( `git -C "${ repoRoot } " branch --show-current` ) ;
6878 return result . stdout || "unknown" ;
6979}
7080
7181export async function getRemoteUrl ( ) : Promise < string | null > {
72- const result = await exec ( `git -C "${ REPO_ROOT } " remote get-url origin` ) ;
82+ const repoRoot = getRepoRoot ( ) ;
83+ const result = await exec ( `git -C "${ repoRoot } " remote get-url origin` ) ;
7384 return result . success ? result . stdout : null ;
7485}
7586
7687export async function getDiff ( file ?: string ) : Promise < string > {
88+ const repoRoot = getRepoRoot ( ) ;
7789 const fileArg = file ? ` -- "${ file } "` : "" ;
78- const result = await exec ( `git -C "${ REPO_ROOT } " diff${ fileArg } ` ) ;
90+ const result = await exec ( `git -C "${ repoRoot } " diff${ fileArg } ` ) ;
7991 return result . stdout ;
8092}
8193
8294export async function getDiffCached ( file ?: string ) : Promise < string > {
95+ const repoRoot = getRepoRoot ( ) ;
8396 const fileArg = file ? ` -- "${ file } "` : "" ;
84- const result = await exec ( `git -C "${ REPO_ROOT } " diff --cached${ fileArg } ` ) ;
97+ const result = await exec ( `git -C "${ repoRoot } " diff --cached${ fileArg } ` ) ;
8598 return result . stdout ;
8699}
0 commit comments