MCPcopy
hub / github.com/Aider-AI/aider / allowed_to_edit

Method allowed_to_edit

aider/coders/base_coder.py:2191–2240  ·  view source on GitHub ↗
(self, path)

Source from the content-addressed store, hash-verified

2189 self.need_commit_before_edits.add(path)
2190
2191 def allowed_to_edit(self, path):
2192 full_path = self.abs_root_path(path)
2193 if self.repo:
2194 need_to_add = not self.repo.path_in_repo(path)
2195 else:
2196 need_to_add = False
2197
2198 if full_path in self.abs_fnames:
2199 self.check_for_dirty_commit(path)
2200 return True
2201
2202 if self.repo and self.repo.git_ignored_file(path):
2203 self.io.tool_warning(f"Skipping edits to {path} that matches gitignore spec.")
2204 return
2205
2206 if not Path(full_path).exists():
2207 if not self.io.confirm_ask("Create new file?", subject=path):
2208 self.io.tool_output(f"Skipping edits to {path}")
2209 return
2210
2211 if not self.dry_run:
2212 if not utils.touch_file(full_path):
2213 self.io.tool_error(f"Unable to create {path}, skipping edits.")
2214 return
2215
2216 # Seems unlikely that we needed to create the file, but it was
2217 # actually already part of the repo.
2218 # But let's only add if we need to, just to be safe.
2219 if need_to_add:
2220 self.repo.repo.git.add(full_path)
2221
2222 self.abs_fnames.add(full_path)
2223 self.check_added_files()
2224 return True
2225
2226 if not self.io.confirm_ask(
2227 "Allow edits to file that has not been added to the chat?",
2228 subject=path,
2229 ):
2230 self.io.tool_output(f"Skipping edits to {path}")
2231 return
2232
2233 if need_to_add:
2234 self.repo.repo.git.add(full_path)
2235
2236 self.abs_fnames.add(full_path)
2237 self.check_added_files()
2238 self.check_for_dirty_commit(path)
2239
2240 return True
2241
2242 warning_given = False
2243

Callers 7

prepare_to_editMethod · 0.95
_update_filesMethod · 0.80
_update_filesMethod · 0.80
test_allowed_to_editMethod · 0.80

Calls 9

abs_root_pathMethod · 0.95
check_added_filesMethod · 0.95
path_in_repoMethod · 0.80
git_ignored_fileMethod · 0.80
tool_warningMethod · 0.45
confirm_askMethod · 0.45
tool_outputMethod · 0.45
tool_errorMethod · 0.45

Tested by 4

test_allowed_to_editMethod · 0.64