@@ -142,38 +142,10 @@ func runWatchAction(ctx context.Context, flags *watchFlags) error {
142142 return nil
143143 }
144144
145- // Fast path: ignore events matching hardcoded glob patterns.
146- shouldIgnore := false
147- for _ , pattern := range globIgnorePaths {
148- matched , _ := doublestar .PathMatch (pattern , event .Name )
149- if matched {
150- shouldIgnore = true
151- break
152- }
153- }
154- if shouldIgnore {
145+ if shouldIgnoreWatchEvent (cwd , event .Name , globIgnorePaths , ignoreMatcher ) {
155146 continue
156147 }
157148
158- // Check user-defined ignore patterns (.azdxignore / .gitignore).
159- // Use os.Stat once to determine if the path is a directory.
160- info , statErr := os .Stat (event .Name )
161- isDir := statErr == nil && info .IsDir ()
162-
163- if relPath , relErr := filepath .Rel (cwd , event .Name ); relErr != nil {
164- log .Printf ("debug: failed to compute relative path for %s: %v" , event .Name , relErr )
165- } else {
166- if ignoreMatcher .IsIgnored (relPath , isDir ) {
167- continue
168- }
169- // When the path no longer exists (e.g. Remove event), os.Stat fails
170- // and isDir defaults to false. Re-check as a directory so that
171- // directory-only patterns (trailing slash) still filter the event.
172- if statErr != nil && ignoreMatcher .IsIgnored (relPath , true ) {
173- continue
174- }
175- }
176-
177149 // Collect unique changes
178150 uniqueChanges [event .Name ] = struct {}{}
179151
@@ -237,6 +209,47 @@ func watchRecursive(
237209 })
238210}
239211
212+ func shouldIgnoreWatchEvent (
213+ root string ,
214+ eventName string ,
215+ globIgnorePaths []string ,
216+ ignoreMatcher * ignore.Matcher ,
217+ ) bool {
218+ relPath := relativeWatchPath (root , eventName )
219+
220+ // Fast path: ignore events matching hardcoded glob patterns.
221+ for _ , pattern := range globIgnorePaths {
222+ matched , _ := doublestar .PathMatch (pattern , relPath )
223+ if matched {
224+ return true
225+ }
226+ }
227+
228+ // Check user-defined ignore patterns (.azdxignore / .gitignore).
229+ // Use os.Stat once to determine if the path is a directory.
230+ info , statErr := os .Stat (eventName )
231+ isDir := statErr == nil && info .IsDir ()
232+
233+ if ignoreMatcher .IsIgnored (relPath , isDir ) {
234+ return true
235+ }
236+
237+ // When the path no longer exists (e.g. Remove event), os.Stat fails
238+ // and isDir defaults to false. Re-check as a directory so that
239+ // directory-only patterns (trailing slash) still filter the event.
240+ return statErr != nil && ignoreMatcher .IsIgnored (relPath , true )
241+ }
242+
243+ func relativeWatchPath (root string , eventName string ) string {
244+ relPath , err := filepath .Rel (root , eventName )
245+ if err != nil {
246+ log .Printf ("debug: failed to compute relative path for %s: %v" , eventName , err )
247+ relPath = eventName
248+ }
249+
250+ return filepath .ToSlash (relPath )
251+ }
252+
240253func rebuild (ctx context.Context , extensionPath string ) {
241254 flags := & buildFlags {}
242255 defaultBuildFlags (flags )
0 commit comments