Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cecli/coders/base_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3723,7 +3723,7 @@ async def allowed_to_edit(self, path):
self.check_for_dirty_commit(path)
return True

if self.repo and self.repo.git_ignored_file(path):
if self.repo and self.repo.git_ignored_file(path) and not self.add_gitignore_files:
self.io.tool_warning(f"Skipping edits to {path} that matches gitignore spec.")
return

Expand All @@ -3742,7 +3742,8 @@ async def allowed_to_edit(self, path):
# actually already part of the repo.
# But let's only add if we need to, just to be safe.
if need_to_add:
self.repo.repo.git.add(full_path)
if not (self.add_gitignore_files and self.repo.git_ignored_file(path)):
self.repo.repo.git.add(full_path)

self.abs_fnames.add(full_path)
self.check_added_files()
Expand All @@ -3756,7 +3757,8 @@ async def allowed_to_edit(self, path):
return

if need_to_add:
self.repo.repo.git.add(full_path)
if not (self.add_gitignore_files and self.repo.git_ignored_file(path)):
self.repo.repo.git.add(full_path)

self.abs_fnames.add(full_path)
self.check_added_files()
Expand Down
24 changes: 23 additions & 1 deletion cecli/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,28 @@ async def commit(self, fnames=None, context=None, message=None, coder_edits=Fals
cmd.append("--no-verify")
if fnames:
fnames = [str(self.abs_root_path(fn)) for fn in fnames]
added_fnames = []
for fname in fnames:
try:
# Check if file is git-ignored before trying to add
if (
coder
and hasattr(coder, "add_gitignore_files")
and coder.add_gitignore_files
):
rel_fname = self.get_rel_fname(fname)
if self.git_ignored_file(rel_fname):
# Skip git-ignored files when add_gitignore_files is enabled
continue
self.repo.git.add(fname)
added_fnames.append(fname)
except ANY_GIT_ERROR as err:
self.io.tool_error(f"Unable to add {fname}: {err}")
cmd += ["--"] + fnames
if added_fnames:
cmd += ["--"] + added_fnames
else:
# No files to commit (all were git-ignored or failed to add)
return
else:
cmd += ["-a"]

Expand Down Expand Up @@ -392,6 +408,12 @@ def get_rel_repo_dir(self):
except (ValueError, OSError):
return self.repo.git_dir

def get_rel_fname(self, fname):
try:
return os.path.relpath(fname, self.root)
except ValueError:
return fname

async def get_commit_message(self, diffs, context, user_language=None):
diffs = "# Diffs:\n" + diffs

Expand Down
Loading