mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 17:24:59 +00:00
aider: Added code to check if name
and email
are set in git configuration and set example values if not.
# Context: USER: can i pass email and name to repo.init ? ASSISTANT: Yes, you can pass the `name` and `email` to `git.Repo.init()`, but not directly. The `git.Repo.init()` function initializes a new repository, but it doesn't handle the configuration of user details. To set the `name` and `email`, you need to modify the configuration of the repository after it has been initialized. This can be done using the `git.config_writer()` function. Here's how you can do it: ```python repo = git.Repo.init(path) with repo.config_writer() as git_config: git_config.set_value("user", "name", "Your Name") git_config.set_value("user", "email", "your.email@example.com") ``` In the context of your `aider/main.py` file, you can add these changes after the repository initialization. Here's the modification: ```python aider/main.py <<<<<<< ORIGINAL if not git_root and args.git: if io.confirm_ask(" ^C KeyboardInterrupt USER: can up check if they are set first, and if not put in example values? ASSISTANT: Sure, you can check if the `name` and `email` are already set in the git configuration before setting the example values. Here's how you can do it: ```python repo = git.Repo.init(path) with repo.config_writer() as git_config: if not git_config.has_option("user", "name"): git_config.set_value("user", "name", "Example Name") if not git_config.has_option("user", "email"): git_config.set_value("user", "email", "example.email@example.com") ``` In the context of your `aider/main.py` file, you can add these changes after the repository initialization. Here's the modification: ```python aider/main.py <<<<<<< ORIGINAL if not git_root and args.git: if io.confirm_ask("No git repo found, create one to track GPT's changes (recommended)?"): git.Repo.init(os.getcwd()) io.tool_output("Git repository created in the current working directory.") ======= if not git_root and args.git: if io.confirm_ask("No git repo found, create one to track GPT's changes (recommended)?"): repo = git.Repo.init(os.getcwd()) with repo.config_writer() as git_config: if not git_config.has_option("user", "name"): git_config.set_value("user", "name", "Example Name") if not git_config.has_option("user", "email"): git_config.set_value("user", "email", "example.email@example.com") io.tool_output("Git repository created in the current working directory.") >>>>>>> UPDATED ``` This code will check if the `name` and `email` are already set in the git configuration. If they are not set, it will set them to "Example Name" and "example.email@example.com" respectively.
This commit is contained in:
parent
5eacee375c
commit
451929f2ca
1 changed files with 6 additions and 1 deletions
|
@ -262,7 +262,12 @@ def main(args=None, input=None, output=None):
|
|||
|
||||
if not git_root and args.git:
|
||||
if io.confirm_ask("No git repo found, create one to track GPT's changes (recommended)?"):
|
||||
git.Repo.init(os.getcwd())
|
||||
repo = git.Repo.init(os.getcwd())
|
||||
with repo.config_writer() as git_config:
|
||||
if not git_config.has_option("user", "name"):
|
||||
git_config.set_value("user", "name", "Example Name")
|
||||
if not git_config.has_option("user", "email"):
|
||||
git_config.set_value("user", "email", "example.email@example.com")
|
||||
io.tool_output("Git repository created in the current working directory.")
|
||||
|
||||
if args.verbose:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue