feat: Add --add-gitignore-files flag

This commit is contained in:
omarcinkonis 2025-03-23 00:52:41 +02:00
parent 8e5f311708
commit 3447f06208
6 changed files with 135 additions and 2 deletions

View file

@ -395,6 +395,12 @@ def get_parser(default_config_files, git_root):
default=True,
help="Enable/disable adding .aider* to .gitignore (default: True)",
)
group.add_argument(
"--add-gitignore-files",
action=argparse.BooleanOptionalAction,
default=False,
help="Enable/disable the addition of files listed in .gitignore to Aider's editing scope.",
)
default_aiderignore_file = (
os.path.join(git_root, ".aiderignore") if git_root else ".aiderignore"
)

View file

@ -291,6 +291,7 @@ class Coder:
io,
repo=None,
fnames=None,
add_gitignore_files=False,
read_only_fnames=None,
show_diffs=False,
auto_commits=True,
@ -370,6 +371,7 @@ class Coder:
self.verbose = verbose
self.abs_fnames = set()
self.abs_read_only_fnames = set()
self.add_gitignore_files = add_gitignore_files
if cur_messages:
self.cur_messages = cur_messages
@ -427,8 +429,9 @@ class Coder:
for fname in fnames:
fname = Path(fname)
if self.repo and self.repo.git_ignored_file(fname):
if self.repo and self.repo.git_ignored_file(fname) and not self.add_gitignore_files:
self.io.tool_warning(f"Skipping {fname} that matches gitignore spec.")
continue
if self.repo and self.repo.ignored_file(fname):
self.io.tool_warning(f"Skipping {fname} that matches aiderignore spec.")

View file

@ -822,7 +822,11 @@ class Commands:
)
continue
if self.coder.repo and self.coder.repo.git_ignored_file(matched_file):
if (
self.coder.repo
and self.coder.repo.git_ignored_file(matched_file)
and not self.coder.add_gitignore_files
):
self.io.tool_error(f"Can't add {matched_file} which is in gitignore")
continue

View file

@ -951,6 +951,7 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
detect_urls=args.detect_urls,
auto_copy_context=args.copy_paste,
auto_accept_architect=args.auto_accept_architect,
add_gitignore_files=args.add_gitignore_files,
)
except UnknownEditFormat as err:
io.tool_error(str(err))

View file

@ -385,6 +385,11 @@ Aliases:
- `--gitignore`
- `--no-gitignore`
### `--add-gitignore-files`
Enable/disable the addition of files listed in .gitignore to Aider's editing scope.
Default: False
Environment variable: `AIDER_ADD_GITIGNORE_FILES`
### `--aiderignore AIDERIGNORE`
Specify the aider ignore file (default: .aiderignore in git root)
Default: .aiderignore