mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 22:34:59 +00:00
Added --attribute-author/committer options #698
This commit is contained in:
parent
8c5c2d27a4
commit
c207c7839a
4 changed files with 60 additions and 19 deletions
|
@ -344,6 +344,18 @@ def get_parser(default_config_files, git_root):
|
|||
default=True,
|
||||
help="Enable/disable commits when repo is found dirty (default: True)",
|
||||
)
|
||||
group.add_argument(
|
||||
"--attribute-author",
|
||||
action=argparse.BooleanOptionalAction,
|
||||
default=True,
|
||||
help="Attribute aider code changes in the git author name (default: True)",
|
||||
)
|
||||
group.add_argument(
|
||||
"--attribute-committer",
|
||||
action=argparse.BooleanOptionalAction,
|
||||
default=True,
|
||||
help="Attribute aider commits in the git committer name (default: True)",
|
||||
)
|
||||
group.add_argument(
|
||||
"--dry-run",
|
||||
action=argparse.BooleanOptionalAction,
|
||||
|
|
|
@ -218,6 +218,8 @@ class Coder:
|
|||
auto_test=False,
|
||||
lint_cmds=None,
|
||||
test_cmd=None,
|
||||
attribute_author=True,
|
||||
attribute_committer=True,
|
||||
):
|
||||
if not fnames:
|
||||
fnames = []
|
||||
|
@ -275,6 +277,8 @@ class Coder:
|
|||
git_dname,
|
||||
aider_ignore_file,
|
||||
models=main_model.commit_message_models(),
|
||||
attribute_author=attribute_author,
|
||||
attribute_committer=attribute_committer,
|
||||
)
|
||||
self.root = self.repo.root
|
||||
except FileNotFoundError:
|
||||
|
|
|
@ -212,6 +212,7 @@ def parse_lint_cmds(lint_cmds, io):
|
|||
return
|
||||
return res
|
||||
|
||||
|
||||
def generate_search_path_list(default_fname, git_root, command_line_file):
|
||||
files = []
|
||||
default_file = Path(default_fname)
|
||||
|
@ -226,8 +227,11 @@ def generate_search_path_list(default_fname, git_root, command_line_file):
|
|||
|
||||
return files
|
||||
|
||||
|
||||
def register_models(git_root, model_settings_fname, io):
|
||||
model_settings_files = generate_search_path_list(".aider.models.yml", git_root, model_settings_fname)
|
||||
model_settings_files = generate_search_path_list(
|
||||
".aider.models.yml", git_root, model_settings_fname
|
||||
)
|
||||
|
||||
try:
|
||||
files_loaded = models.register_models(model_settings_files)
|
||||
|
@ -241,8 +245,11 @@ def register_models(git_root, model_settings_fname, io):
|
|||
|
||||
return None
|
||||
|
||||
|
||||
def register_litellm_models(git_root, model_metadata_fname, io):
|
||||
model_metatdata_files = generate_search_path_list(".aider.litellm.models.json", git_root, model_metadata_fname)
|
||||
model_metatdata_files = generate_search_path_list(
|
||||
".aider.litellm.models.json", git_root, model_metadata_fname
|
||||
)
|
||||
|
||||
try:
|
||||
model_metadata_files_loaded = models.register_litellm_models(model_metatdata_files)
|
||||
|
@ -254,6 +261,7 @@ def register_litellm_models(git_root, model_metadata_fname, io):
|
|||
io.tool_error(f"Error loading litellm models: {e}")
|
||||
return 1
|
||||
|
||||
|
||||
def main(argv=None, input=None, output=None, force_git_root=None, return_coder=False):
|
||||
if argv is None:
|
||||
argv = sys.argv[1:]
|
||||
|
@ -430,6 +438,8 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
|||
auto_test=args.auto_test,
|
||||
lint_cmds=lint_cmds,
|
||||
test_cmd=args.test_cmd,
|
||||
attribute_author=args.attribute_author,
|
||||
attribute_committer=args.attribute_committer,
|
||||
)
|
||||
|
||||
except ValueError as err:
|
||||
|
|
|
@ -16,10 +16,22 @@ class GitRepo:
|
|||
aider_ignore_spec = None
|
||||
aider_ignore_ts = 0
|
||||
|
||||
def __init__(self, io, fnames, git_dname, aider_ignore_file=None, models=None):
|
||||
def __init__(
|
||||
self,
|
||||
io,
|
||||
fnames,
|
||||
git_dname,
|
||||
aider_ignore_file=None,
|
||||
models=None,
|
||||
attribute_author=True,
|
||||
attribute_committer=True,
|
||||
):
|
||||
self.io = io
|
||||
self.models = models
|
||||
|
||||
self.attribute_author = attribute_author
|
||||
self.attribute_committer = attribute_committer
|
||||
|
||||
if git_dname:
|
||||
check_fnames = [git_dname]
|
||||
elif fnames:
|
||||
|
@ -90,11 +102,12 @@ class GitRepo:
|
|||
|
||||
original_user_name = self.repo.config_reader().get_value("user", "name")
|
||||
original_committer_name_env = os.environ.get("GIT_COMMITTER_NAME")
|
||||
|
||||
committer_name = f"{original_user_name} (aider)"
|
||||
os.environ["GIT_COMMITTER_NAME"] = committer_name
|
||||
|
||||
if aider_edits:
|
||||
if self.attribute_committer:
|
||||
os.environ["GIT_COMMITTER_NAME"] = committer_name
|
||||
|
||||
if aider_edits and self.attribute_author:
|
||||
original_auther_name_env = os.environ.get("GIT_AUTHOR_NAME")
|
||||
os.environ["GIT_AUTHOR_NAME"] = committer_name
|
||||
|
||||
|
@ -102,18 +115,20 @@ class GitRepo:
|
|||
commit_hash = self.repo.head.commit.hexsha[:7]
|
||||
self.io.tool_output(f"Commit {commit_hash} {commit_message}")
|
||||
|
||||
# Restore the original GIT_COMMITTER_NAME
|
||||
if aider_edits:
|
||||
# Restore the env
|
||||
|
||||
if self.attribute_committer:
|
||||
if original_committer_name_env is not None:
|
||||
os.environ["GIT_COMMITTER_NAME"] = original_committer_name_env
|
||||
else:
|
||||
del os.environ["GIT_COMMITTER_NAME"]
|
||||
|
||||
if aider_edits and self.attribute_author:
|
||||
if original_auther_name_env is not None:
|
||||
os.environ["GIT_AUTHOR_NAME"] = original_auther_name_env
|
||||
else:
|
||||
del os.environ["GIT_AUTHOR_NAME"]
|
||||
|
||||
if original_committer_name_env is not None:
|
||||
os.environ["GIT_COMMITTER_NAME"] = original_committer_name_env
|
||||
else:
|
||||
del os.environ["GIT_COMMITTER_NAME"]
|
||||
|
||||
return commit_hash, commit_message
|
||||
|
||||
def get_rel_repo_dir(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue