Skip to content

Commit

Permalink
feat: Support filenames containing # in ignore and remove files
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jan 14, 2025
1 parent 785f012 commit 8b42ee8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/chezmoi/sourcestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
)

var (
commentRx = regexp.MustCompile(`(?:\A|\s+)#.*$`)
lineEndingRx = regexp.MustCompile(`(?m)(?:\r\n|\r|\n)`)
modifyTemplateRx = regexp.MustCompile(`(?m)^.*chezmoi:modify-template.*$(?:\r?\n)?`)
templateDirectiveRx = regexp.MustCompile(`(?m)^.*?chezmoi:template:(.*)$(?:\r?\n)?`)
Expand Down Expand Up @@ -1426,7 +1427,7 @@ func (s *SourceState) addPatterns(patternSet *patternSet, sourceAbsPath AbsPath,
for scanner.Scan() {
lineNumber++
text := scanner.Text()
text, _, _ = strings.Cut(text, "#")
text = commentRx.ReplaceAllString(text, "")
text = strings.TrimSpace(text)
if text == "" {
continue
Expand Down
19 changes: 19 additions & 0 deletions internal/chezmoi/sourcestate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,25 @@ func TestSourceStateRead(t *testing.T) {
),
),
},
{
name: "chezmoiignore_ignore_file_with_hash",
root: map[string]any{
"/home/user/.local/share/chezmoi": map[string]any{
".chezmoiignore": "README.md#\n",
"README.md#": "",
},
},
expectedSourceState: NewSourceState(
withIgnore(
mustNewPatternSet(t, map[string]patternSetIncludeType{
"README.md#": patternSetInclude,
}),
),
withIgnoredRelPathStrs(
"README.md#",
),
),
},
{
name: "chezmoiignore_exact_dir",
root: map[string]any{
Expand Down

0 comments on commit 8b42ee8

Please sign in to comment.