@@ -19,14 +19,46 @@ const exec = (command, args) => {
19
19
return execFileSync ( command , args , options ) ;
20
20
} ;
21
21
22
+ const isGit = ( ) => {
23
+ try {
24
+ const wt = execGitCmd ( [ 'rev-parse' , '--is-inside-work-tree' ] ) ;
25
+ return wt . length > 0 && wt [ 0 ] === 'true' ;
26
+ } catch ( _e ) {
27
+ return false ;
28
+ }
29
+ } ;
30
+
31
+ const isSl = ( ) => {
32
+ try {
33
+ execSlCmd ( [ 'whereami' ] ) ;
34
+ return true ;
35
+ } catch ( _e ) {
36
+ return false ;
37
+ }
38
+ } ;
39
+
22
40
const execGitCmd = args => exec ( 'git' , args ) . trim ( ) . toString ( ) . split ( '\n' ) ;
41
+ const execSlCmd = args => exec ( 'sl' , args ) . trim ( ) . toString ( ) . split ( '\n' ) ;
23
42
24
43
const listChangedFiles = ( ) => {
25
- const mergeBase = execGitCmd ( [ 'merge-base' , 'HEAD' , 'main' ] ) ;
26
- return new Set ( [
27
- ...execGitCmd ( [ 'diff' , '--name-only' , '--diff-filter=ACMRTUB' , mergeBase ] ) ,
28
- ...execGitCmd ( [ 'ls-files' , '--others' , '--exclude-standard' ] ) ,
29
- ] ) ;
44
+ if ( isGit ( ) ) {
45
+ const mergeBase = execGitCmd ( [ 'merge-base' , 'HEAD' , 'main' ] ) ;
46
+ return new Set ( [
47
+ ...execGitCmd ( [
48
+ 'diff' ,
49
+ '--name-only' ,
50
+ '--diff-filter=ACMRTUB' ,
51
+ mergeBase ,
52
+ ] ) ,
53
+ ...execGitCmd ( [ 'ls-files' , '--others' , '--exclude-standard' ] ) ,
54
+ ] ) ;
55
+ } else if ( isSl ( ) ) {
56
+ const mergeBase = execSlCmd ( [ 'log' , '-r' , 'last(public() & ::.)' ] ) [ 0 ]
57
+ . trim ( )
58
+ . split ( / \s + / ) [ 1 ] ;
59
+ return new Set ( execSlCmd ( [ 'status' , '--no-status' , '--rev' , mergeBase ] ) ) ;
60
+ }
61
+ throw new Error ( 'Not a git or sl repo' ) ;
30
62
} ;
31
63
32
64
module . exports = listChangedFiles ;
0 commit comments