55 */
66import util = require( "util" ) ;
77import childProcess = require( "child_process" ) ;
8-
8+ import { Repository } from "../api/git" ;
99import { getWorkspaceFolder } from "../workspace" ;
10-
1110const exec = util . promisify ( childProcess . exec ) ;
1211
1312/**
14- * Run a `git` subcommand with options and return output.
13+ * Run a `git` subcommand and return output.
1514 */
1615function _execute ( cwd : string , subcommand : string , options : string [ ] = [ ] ) {
1716 const command = `git ${ subcommand } ${ options . join ( " " ) } ` ;
1817
19- const result = exec ( command , { cwd } ) ;
18+ console . debug ( `Running command: ${ command } , cwd: ${ cwd } ` ) ;
2019
21- return result ;
20+ return exec ( command , { cwd } ) ;
2221}
2322
2423/**
@@ -33,9 +32,12 @@ function _execute(cwd: string, subcommand: string, options: string[] = []) {
3332 * The output already seems to never have color info, from my testing, but the
3433 * no-color flagged is added still to be safe.
3534 */
36- async function _diffIndex ( options : string [ ] = [ ] ) : Promise < Array < string > > {
35+ async function _diffIndex (
36+ repository : Repository ,
37+ options : string [ ] = [ ]
38+ ) : Promise < Array < string > > {
39+ const cwd = repository . rootUri . path ;
3740 const cmd = "diff-index" ;
38-
3941 const fullOptions = [
4042 "--name-status" ,
4143 "--find-renames" ,
@@ -44,11 +46,8 @@ async function _diffIndex(options: string[] = []): Promise<Array<string>> {
4446 ...options ,
4547 "HEAD" ,
4648 ] ;
47- const { stdout, stderr } = await _execute (
48- getWorkspaceFolder ( ) ,
49- cmd ,
50- fullOptions
51- ) ;
49+
50+ const { stdout, stderr } = await _execute ( cwd , cmd , fullOptions ) ;
5251
5352 if ( stderr ) {
5453 console . debug ( `stderr for 'git ${ cmd } ' command:` , stderr ) ;
@@ -68,8 +67,8 @@ async function _diffIndex(options: string[] = []): Promise<Array<string>> {
6867 *
6968 * Returns an array of strings.
7069 */
71- export async function getChanges ( ) {
72- const stagedChanges = await _diffIndex ( [ "--cached" ] ) ;
70+ export async function getChanges ( repository : Repository ) {
71+ const stagedChanges = await _diffIndex ( repository , [ "--cached" ] ) ;
7372
7473 if ( stagedChanges . length ) {
7574 console . debug ( "Found staged changes" ) ;
@@ -81,7 +80,7 @@ export async function getChanges() {
8180 "Staging area is empty. Using unstaged files (tracked files only still)."
8281 ) ;
8382
84- const allChanges = await _diffIndex ( ) ;
83+ const allChanges = await _diffIndex ( repository ) ;
8584
8685 if ( ! allChanges . length ) {
8786 console . debug ( "No changes found" ) ;
0 commit comments