comby-tools / comby

A code rewrite tool for structural search and replace that supports ~every language.
https://comby.dev
Apache License 2.0
2.4k stars 62 forks source link

comby ignores files in current dir or explicitly provided dir when its hidden #352

Open tekumara opened 1 year ago

tekumara commented 1 year ago

Describe the bug

When using templates and the current directory is a hidden directory (or the -d dir is hidden) comby ignores the files.

Reproducing

❯ pwd
/Users/tekumara/code/myapp/.teamcity
❯ ll
total 40
-rw-r--r--  1 tekumara  staff   4.5K 24 Jun 11:06 settings.kts
❯ comby -config ../comby-patch-settings.toml -f .kts -stats
{
  "number_of_files": 0,
  "lines_of_code": 0,
  "number_of_matches": 0,
  "total_time": 40.49396514892578
}
❯ cd ..
❯ pwd
/Users/tekumara/code/myapp
❯ comby -config ../comby-patch-settings.toml -f .kts -stats -d .teamcity
{
  "number_of_files": 0,
  "lines_of_code": 0,
  "number_of_matches": 0,
  "total_time": 40.49396514892578
}

Expected behavior

When using templates, and the current dir is a hidden directory, or a hidden directory is explicitly provided via -d then comby should work on this files.

Additional context

comby 1.8.1

tekumara commented 1 year ago

A work around whilst there's no fix is to provide an empty template and the explicit file names, which produces a warning but will work on the files in the hidden directory:

❯ comby -config comby-patch-teamcity.toml -matcher .txt -f .kts "" "" .teamcity/* -stats
WARNING: Templates specified on the command line AND using -templates. Ignoring match
      and rewrite templates on the command line and only using those in directories.
....      
{
  "number_of_files": 1,
  "lines_of_code": 285,
  "number_of_matches": 0,
  "total_time": 92.39006042480469
}
rvantonder commented 1 year ago

Thanks--looks like this conflicts with --exclude-dir which by default excludes any directories starting with ..

When a flag specifies -d explicitly, I agree it should just work.

In the mean time you can probably use the workaround --exclude-dir "" -d .teamcity (didn't check, but it should work)

tekumara commented 1 year ago

Thanks for looking into this! When I try -exclude-dir "" I get:

Error parsing command line:

  failed to parse -exclude-dir value "".
  (Failure "Command.Spec.Arg_type.comma_separated: empty list not allowed")

For usage information, run

  comby -help