@@ -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,30 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
283286 return getDiffHead ( directoryPath , { ignoreWhitespace } ) ;
284287 }
285288
289+ public async getDiffCached ( directoryPath : string ) : Promise < string > {
290+ return getStagedDiff ( directoryPath ) ;
291+ }
292+
293+ public async getDiffUnstaged ( directoryPath : string ) : Promise < string > {
294+ return getUnstagedDiff ( directoryPath ) ;
295+ }
296+
297+ public async stageFiles (
298+ directoryPath : string ,
299+ paths : string [ ] ,
300+ ) : Promise < GitStateSnapshot > {
301+ await stageFiles ( directoryPath , paths ) ;
302+ return this . getStateSnapshot ( directoryPath ) ;
303+ }
304+
305+ public async unstageFiles (
306+ directoryPath : string ,
307+ paths : string [ ] ,
308+ ) : Promise < GitStateSnapshot > {
309+ await unstageFiles ( directoryPath , paths ) ;
310+ return this . getStateSnapshot ( directoryPath ) ;
311+ }
312+
286313 public async getDiffStats ( directoryPath : string ) : Promise < DiffStats > {
287314 const stats = await getDiffStats ( directoryPath , {
288315 excludePatterns : [ ".claude" , "CLAUDE.local.md" ] ,
@@ -479,6 +506,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
479506 prTitle ?: string ;
480507 prBody ?: string ;
481508 draft ?: boolean ;
509+ stagedOnly ?: boolean ;
482510 } ) : Promise < CreatePrOutput > {
483511 const { directoryPath, flowId } = input ;
484512
@@ -502,7 +530,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
502530 checkoutBranch : ( dir , name ) => this . checkoutBranch ( dir , name ) ,
503531 getChangedFilesHead : ( dir ) => this . getChangedFilesHead ( dir ) ,
504532 generateCommitMessage : ( dir ) => this . generateCommitMessage ( dir ) ,
505- commit : ( dir , msg ) => this . commit ( dir , msg ) ,
533+ commit : ( dir , msg , stagedOnly ) => this . commit ( dir , msg , { stagedOnly } ) ,
506534 getSyncStatus : ( dir ) => this . getGitSyncStatus ( dir ) ,
507535 push : ( dir ) => this . push ( dir ) ,
508536 publish : ( dir ) => this . publish ( dir ) ,
@@ -521,6 +549,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
521549 prTitle : input . prTitle ,
522550 prBody : input . prBody ,
523551 draft : input . draft ,
552+ stagedOnly : input . stagedOnly ,
524553 } ) ;
525554
526555 if ( ! result . success ) {
@@ -584,8 +613,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
584613 public async commit (
585614 directoryPath : string ,
586615 message : string ,
587- paths ?: string [ ] ,
588- allowEmpty ?: boolean ,
616+ options ?: { paths ?: string [ ] ; allowEmpty ?: boolean ; stagedOnly ?: boolean } ,
589617 ) : Promise < CommitOutput > {
590618 const fail = ( msg : string ) : CommitOutput => ( {
591619 success : false ,
@@ -600,8 +628,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
600628 const result = await saga . run ( {
601629 baseDir : directoryPath ,
602630 message : message . trim ( ) ,
603- paths,
604- allowEmpty,
631+ ...options ,
605632 } ) ;
606633
607634 if ( ! result . success ) return fail ( result . error ) ;
0 commit comments