11import fs from 'fs'
22import path from 'path'
33
4- import execa from 'execa'
54import findUp from 'find-up'
5+ import { Output , exec } from 'tinyexec'
66
77export const name = 'git'
88
@@ -44,26 +44,35 @@ export const detect = (directory: string) => {
4444}
4545
4646const runGit = ( directory : string , args : string [ ] ) =>
47- execa . sync ( 'git' , args , {
48- cwd : directory ,
47+ exec ( 'git' , args , {
48+ nodeOptions : {
49+ cwd : directory ,
50+ } ,
4951 } )
5052
51- const getLines = ( execaResult : execa . ExecaSyncReturnValue ) =>
52- execaResult . stdout . split ( '\n' )
53+ const getLines = ( tinyexecOutput : Output ) => tinyexecOutput . stdout . split ( '\n' )
5354
54- export const getSinceRevision = (
55+ export const getSinceRevision = async (
5556 directory : string ,
5657 { staged, branch } : { staged ?: boolean ; branch ?: string } ,
5758) => {
5859 try {
59- const revision = staged
60- ? 'HEAD'
61- : runGit ( directory , [
62- 'merge-base' ,
63- 'HEAD' ,
64- branch || 'master' ,
65- ] ) . stdout . trim ( )
66- return runGit ( directory , [ 'rev-parse' , '--short' , revision ] ) . stdout . trim ( )
60+ let revision = 'HEAD'
61+ if ( ! staged ) {
62+ const revisionOutput = await runGit ( directory , [
63+ 'merge-base' ,
64+ 'HEAD' ,
65+ branch || 'master' ,
66+ ] )
67+ revision = revisionOutput . stdout . trim ( )
68+ }
69+
70+ const revParseOutput = await runGit ( directory , [
71+ 'rev-parse' ,
72+ '--short' ,
73+ revision ,
74+ ] )
75+ return revParseOutput . stdout . trim ( )
6776 } catch ( err ) {
6877 const error = err as Error
6978 if (
@@ -76,14 +85,14 @@ export const getSinceRevision = (
7685 }
7786}
7887
79- export const getChangedFiles = (
88+ export const getChangedFiles = async (
8089 directory : string ,
8190 revision : string | null ,
8291 staged ?: boolean | undefined ,
8392) =>
8493 [
8594 ...getLines (
86- runGit (
95+ await runGit (
8796 directory ,
8897 [
8998 'diff' ,
@@ -97,14 +106,17 @@ export const getChangedFiles = (
97106 ...( staged
98107 ? [ ]
99108 : getLines (
100- runGit ( directory , [ 'ls-files' , '--others' , '--exclude-standard' ] ) ,
109+ await runGit ( directory , [
110+ 'ls-files' ,
111+ '--others' ,
112+ '--exclude-standard' ,
113+ ] ) ,
101114 ) ) ,
102115 ] . filter ( Boolean )
103116
104117export const getUnstagedChangedFiles = ( directory : string ) => {
105118 return getChangedFiles ( directory , null , false )
106119}
107120
108- export const stageFile = ( directory : string , file : string ) => {
121+ export const stageFile = ( directory : string , file : string ) =>
109122 runGit ( directory , [ 'add' , file ] )
110- }
0 commit comments