diff --git a/cecli/coders/base_coder.py b/cecli/coders/base_coder.py index 0b7f847d436..7653c80426f 100755 --- a/cecli/coders/base_coder.py +++ b/cecli/coders/base_coder.py @@ -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 @@ -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() @@ -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() diff --git a/cecli/repo.py b/cecli/repo.py index f9f6f7467a2..07ce806d0bd 100644 --- a/cecli/repo.py +++ b/cecli/repo.py @@ -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"] @@ -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