@@ -199,7 +199,7 @@ export class Utils {
199199 for ( const rule of opt . rules ) {
200200 if ( ! Utils . evaluateRuleIf ( rule . if , opt . variables ) ) continue ;
201201 if ( ! Utils . evaluateRuleExist ( opt . cwd , rule . exists ) ) continue ;
202- if ( evaluateRuleChanges && ! Utils . evaluateRuleChanges ( gitData . branches . default , rule . changes ) ) continue ;
202+ if ( evaluateRuleChanges && ! Utils . evaluateRuleChanges ( gitData . branches . default , rule . changes , opt . cwd ) ) continue ;
203203
204204 when = rule . when ? rule . when : jobWhen ;
205205 allowFailure = rule . allow_failure ?? allowFailure ;
@@ -337,7 +337,7 @@ export class Utils {
337337 return false ;
338338 }
339339
340- static evaluateRuleChanges ( defaultBranch : string , ruleChanges : string [ ] | { paths : string [ ] } | undefined ) : boolean {
340+ static evaluateRuleChanges ( defaultBranch : string , ruleChanges : string [ ] | { paths : string [ ] } | undefined , cwd : string ) : boolean {
341341 if ( ruleChanges === undefined ) return true ;
342342
343343 // Normalize rules:changes:paths to rules:changes
@@ -346,7 +346,7 @@ export class Utils {
346346 // NOTE: https://docs.gitlab.com/ee/ci/yaml/#ruleschanges
347347 // Glob patterns are interpreted with Ruby's [File.fnmatch](https://docs.ruby-lang.org/en/master/File.html#method-c-fnmatch)
348348 // with the flags File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB.
349- return micromatch . some ( GitData . changedFiles ( `origin/${ defaultBranch } ` ) , ruleChanges , {
349+ return micromatch . some ( GitData . changedFiles ( `origin/${ defaultBranch } ` , cwd ) , ruleChanges , {
350350 nonegate : true ,
351351 noextglob : true ,
352352 posix : false ,
@@ -510,5 +510,12 @@ export class Utils {
510510
511511 static async stopDockerRegistry ( containerExecutable : string ) : Promise < void > {
512512 await Utils . spawn ( [ containerExecutable , "rm" , "-f" , this . gclRegistryPrefix ] ) ;
513+
514+ static async getTrackedFiles ( cwd : string ) : Promise < string [ ] > {
515+ const lsFilesRes = await Utils . bash ( "git ls-files --deduplicate" , cwd ) ;
516+ if ( lsFilesRes . exitCode != 0 ) {
517+ throw new Error ( `Failed to list tracked files in ${ cwd } : ${ lsFilesRes . stderr } ` ) ;
518+ }
519+ return lsFilesRes . stdout . split ( "\n" ) ;
513520 }
514521}
0 commit comments