@@ -19,6 +19,8 @@ import {
1919 getUnstagedDiff ,
2020 fetch as gitFetch ,
2121 isGitRepository ,
22+ stageFiles ,
23+ unstageFiles ,
2224} from "@posthog/git/queries" ;
2325import { CreateBranchSaga , SwitchBranchSaga } from "@posthog/git/sagas/branch" ;
2426import { CloneSaga } from "@posthog/git/sagas/clone" ;
@@ -266,6 +268,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
266268 originalPath : f . originalPath ,
267269 linesAdded : f . linesAdded ,
268270 linesRemoved : f . linesRemoved ,
271+ staged : f . staged ,
269272 } ) ) ;
270273 }
271274
@@ -283,6 +286,36 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
283286 return getDiffHead ( directoryPath , { ignoreWhitespace } ) ;
284287 }
285288
289+ public async getDiffCached (
290+ directoryPath : string ,
291+ ignoreWhitespace ?: boolean ,
292+ ) : Promise < string > {
293+ return getStagedDiff ( directoryPath , { ignoreWhitespace } ) ;
294+ }
295+
296+ public async getDiffUnstaged (
297+ directoryPath : string ,
298+ ignoreWhitespace ?: boolean ,
299+ ) : Promise < string > {
300+ return getUnstagedDiff ( directoryPath , { ignoreWhitespace } ) ;
301+ }
302+
303+ public async stageFiles (
304+ directoryPath : string ,
305+ paths : string [ ] ,
306+ ) : Promise < GitStateSnapshot > {
307+ await stageFiles ( directoryPath , paths ) ;
308+ return this . getStateSnapshot ( directoryPath ) ;
309+ }
310+
311+ public async unstageFiles (
312+ directoryPath : string ,
313+ paths : string [ ] ,
314+ ) : Promise < GitStateSnapshot > {
315+ await unstageFiles ( directoryPath , paths ) ;
316+ return this . getStateSnapshot ( directoryPath ) ;
317+ }
318+
286319 public async getDiffStats ( directoryPath : string ) : Promise < DiffStats > {
287320 const stats = await getDiffStats ( directoryPath , {
288321 excludePatterns : [ ".claude" , "CLAUDE.local.md" ] ,
@@ -479,6 +512,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
479512 prTitle ?: string ;
480513 prBody ?: string ;
481514 draft ?: boolean ;
515+ stagedOnly ?: boolean ;
482516 } ) : Promise < CreatePrOutput > {
483517 const { directoryPath, flowId } = input ;
484518
@@ -502,7 +536,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
502536 checkoutBranch : ( dir , name ) => this . checkoutBranch ( dir , name ) ,
503537 getChangedFilesHead : ( dir ) => this . getChangedFilesHead ( dir ) ,
504538 generateCommitMessage : ( dir ) => this . generateCommitMessage ( dir ) ,
505- commit : ( dir , msg ) => this . commit ( dir , msg ) ,
539+ commit : ( dir , msg , stagedOnly ) => this . commit ( dir , msg , { stagedOnly } ) ,
506540 getSyncStatus : ( dir ) => this . getGitSyncStatus ( dir ) ,
507541 push : ( dir ) => this . push ( dir ) ,
508542 publish : ( dir ) => this . publish ( dir ) ,
@@ -521,6 +555,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
521555 prTitle : input . prTitle ,
522556 prBody : input . prBody ,
523557 draft : input . draft ,
558+ stagedOnly : input . stagedOnly ,
524559 } ) ;
525560
526561 if ( ! result . success ) {
@@ -584,8 +619,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
584619 public async commit (
585620 directoryPath : string ,
586621 message : string ,
587- paths ?: string [ ] ,
588- allowEmpty ?: boolean ,
622+ options ?: { paths ?: string [ ] ; allowEmpty ?: boolean ; stagedOnly ?: boolean } ,
589623 ) : Promise < CommitOutput > {
590624 const fail = ( msg : string ) : CommitOutput => ( {
591625 success : false ,
@@ -600,8 +634,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
600634 const result = await saga . run ( {
601635 baseDir : directoryPath ,
602636 message : message . trim ( ) ,
603- paths,
604- allowEmpty,
637+ ...options ,
605638 } ) ;
606639
607640 if ( ! result . success ) return fail ( result . error ) ;
0 commit comments