Refactor glob pattern handling, ensure relative globs are resolved against SourceDir
This commit is contained in:
@@ -91,10 +91,10 @@ func SplitPattern(pattern string) (string, string) {
|
|||||||
static, remainingPattern := doublestar.SplitPattern(pattern)
|
static, remainingPattern := doublestar.SplitPattern(pattern)
|
||||||
splitPatternLogger.Trace("After split: static=%q, pattern=%q", static, remainingPattern)
|
splitPatternLogger.Trace("After split: static=%q, pattern=%q", static, remainingPattern)
|
||||||
|
|
||||||
// Resolve the static part to handle ~ expansion and make it absolute
|
// Normalize to forward slashes but DON'T resolve relative to CWD
|
||||||
// ResolvePath already normalizes to forward slashes
|
// Paths should already be resolved by the caller (AggregateGlobs, etc.)
|
||||||
static = ResolvePath(static)
|
static = filepath.ToSlash(static)
|
||||||
splitPatternLogger.Trace("Resolved static part: %q", static)
|
splitPatternLogger.Trace("Normalized static part: %q", static)
|
||||||
|
|
||||||
splitPatternLogger.Trace("Final static path: %q, Remaining pattern: %q", static, remainingPattern)
|
splitPatternLogger.Trace("Final static path: %q, Remaining pattern: %q", static, remainingPattern)
|
||||||
return static, remainingPattern
|
return static, remainingPattern
|
||||||
@@ -126,9 +126,22 @@ func AssociateFilesWithCommands(files []string, commands []ModifyCommand) (map[s
|
|||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
associateFilesLogger.Debug("Checking command %q for file %q", command.Name, file)
|
associateFilesLogger.Debug("Checking command %q for file %q", command.Name, file)
|
||||||
for _, glob := range command.Files {
|
for _, glob := range command.Files {
|
||||||
// SplitPattern now handles tilde expansion and path resolution
|
// Resolve glob relative to SourceDir if it's a relative path
|
||||||
static, pattern := SplitPattern(glob)
|
var resolvedGlob string
|
||||||
associateFilesLogger.Trace("Glob parts for %q → static=%q pattern=%q", glob, static, pattern)
|
if !filepath.IsAbs(glob) && command.SourceDir != "" {
|
||||||
|
resolvedGlob = filepath.Join(command.SourceDir, glob)
|
||||||
|
associateFilesLogger.Trace("Joined relative glob %q to %q using SourceDir %q", glob, resolvedGlob, command.SourceDir)
|
||||||
|
} else {
|
||||||
|
resolvedGlob = glob
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make absolute and normalize
|
||||||
|
resolvedGlob = ResolvePath(resolvedGlob)
|
||||||
|
associateFilesLogger.Trace("Final resolved glob: %q", resolvedGlob)
|
||||||
|
|
||||||
|
// SplitPattern just splits, doesn't resolve
|
||||||
|
static, pattern := SplitPattern(resolvedGlob)
|
||||||
|
associateFilesLogger.Trace("Glob parts for %q → static=%q pattern=%q", resolvedGlob, static, pattern)
|
||||||
|
|
||||||
// Use resolved file for matching (already normalized to forward slashes by ResolvePath)
|
// Use resolved file for matching (already normalized to forward slashes by ResolvePath)
|
||||||
absFile := resolvedFile
|
absFile := resolvedFile
|
||||||
@@ -181,15 +194,23 @@ func AggregateGlobs(commands []ModifyCommand) map[string]struct{} {
|
|||||||
globs := make(map[string]struct{})
|
globs := make(map[string]struct{})
|
||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
aggregateGlobsLogger.Debug("Processing command %q for glob patterns", command.Name)
|
aggregateGlobsLogger.Debug("Processing command %q for glob patterns", command.Name)
|
||||||
|
aggregateGlobsLogger.Trace("Command SourceDir: %q", command.SourceDir)
|
||||||
for _, glob := range command.Files {
|
for _, glob := range command.Files {
|
||||||
// Split the glob into static and pattern parts, then resolve ONLY the static part
|
// If the glob is relative and we have a SourceDir, resolve relative to SourceDir
|
||||||
static, pattern := SplitPattern(glob)
|
var resolvedGlob string
|
||||||
// Reconstruct the glob with resolved static part
|
if !filepath.IsAbs(glob) && command.SourceDir != "" {
|
||||||
resolvedGlob := static
|
// Relative path - resolve relative to the TOML file's directory
|
||||||
if pattern != "" {
|
resolvedGlob = filepath.Join(command.SourceDir, glob)
|
||||||
resolvedGlob += "/" + pattern
|
aggregateGlobsLogger.Trace("Joined relative glob %q to %q using SourceDir %q", glob, resolvedGlob, command.SourceDir)
|
||||||
|
} else {
|
||||||
|
// Absolute path or no SourceDir - use as-is
|
||||||
|
resolvedGlob = glob
|
||||||
}
|
}
|
||||||
aggregateGlobsLogger.Trace("Adding glob: %q (resolved to %q) [static=%s, pattern=%s]", glob, resolvedGlob, static, pattern)
|
|
||||||
|
// Make absolute and normalize (ResolvePath handles both)
|
||||||
|
resolvedGlob = ResolvePath(resolvedGlob)
|
||||||
|
aggregateGlobsLogger.Trace("Final resolved glob: %q", resolvedGlob)
|
||||||
|
|
||||||
globs[resolvedGlob] = struct{}{}
|
globs[resolvedGlob] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user