@@ -654,10 +654,6 @@ export function parseLsFiles(raw: string): LsFilesElement[] {
654654 . map ( ( [ , mode , object , stage , file ] ) => ( { mode, object, stage, file } ) ) ;
655655}
656656
657- export interface DiffOptions {
658- cached ?: boolean ;
659- }
660-
661657export class Repository {
662658
663659 constructor (
@@ -828,10 +824,10 @@ export class Repository {
828824 }
829825 }
830826
831- async diff ( path : string , options : DiffOptions = { } ) : Promise < string > {
827+ async diff ( path : string , cached = false ) : Promise < string > {
832828 const args = [ 'diff' ] ;
833829
834- if ( options . cached ) {
830+ if ( cached ) {
835831 args . push ( '--cached' ) ;
836832 }
837833
@@ -841,6 +837,20 @@ export class Repository {
841837 return result . stdout ;
842838 }
843839
840+ async diffBetween ( ref1 : string , ref2 : string , path : string ) : Promise < string > {
841+ const args = [ 'diff' , `${ ref1 } ...${ ref2 } ` , '--' , path ] ;
842+ const result = await this . run ( args ) ;
843+
844+ return result . stdout . trim ( ) ;
845+ }
846+
847+ async getMergeBase ( ref1 : string , ref2 : string ) : Promise < string > {
848+ const args = [ 'merge-base' , ref1 , ref2 ] ;
849+ const result = await this . run ( args ) ;
850+
851+ return result . stdout . trim ( ) ;
852+ }
853+
844854 async add ( paths : string [ ] ) : Promise < void > {
845855 const args = [ 'add' , '-A' , '--' ] ;
846856
@@ -961,8 +971,13 @@ export class Repository {
961971 throw commitErr ;
962972 }
963973
964- async branch ( name : string , checkout : boolean ) : Promise < void > {
974+ async branch ( name : string , checkout : boolean , ref ?: string ) : Promise < void > {
965975 const args = checkout ? [ 'checkout' , '-q' , '-b' , name ] : [ 'branch' , '-q' , name ] ;
976+
977+ if ( ref ) {
978+ args . push ( ref ) ;
979+ }
980+
966981 await this . run ( args ) ;
967982 }
968983
@@ -976,6 +991,11 @@ export class Repository {
976991 await this . run ( args ) ;
977992 }
978993
994+ async setBranchUpstream ( name : string , upstream : string ) : Promise < void > {
995+ const args = [ 'branch' , '--set-upstream-to' , upstream , name ] ;
996+ await this . run ( args ) ;
997+ }
998+
979999 async deleteRef ( ref : string ) : Promise < void > {
9801000 const args = [ 'update-ref' , '-d' , ref ] ;
9811001 await this . run ( args ) ;
@@ -1073,7 +1093,22 @@ export class Repository {
10731093 }
10741094 }
10751095
1076- async fetch ( ) : Promise < void > {
1096+ async addRemote ( name : string , url : string ) : Promise < void > {
1097+ const args = [ 'remote' , 'add' , name , url ] ;
1098+ await this . run ( args ) ;
1099+ }
1100+
1101+ async fetch ( remote ?: string , ref ?: string ) : Promise < void > {
1102+ const args = [ 'fetch' ] ;
1103+
1104+ if ( remote ) {
1105+ args . push ( remote ) ;
1106+
1107+ if ( ref ) {
1108+ args . push ( ref ) ;
1109+ }
1110+ }
1111+
10771112 try {
10781113 await this . run ( [ 'fetch' ] ) ;
10791114 } catch ( err ) {
0 commit comments