feat: include home directory as git repo option

This commit is contained in:
Paul Gauthier (aider) 2024-08-28 10:37:17 -07:00
parent c9458e461f
commit 048c468f27

View file

@ -24,12 +24,15 @@ from .dump import dump # noqa: F401
def setup_git_home(io):
home = Path.home()
git_repos = list(home.glob("*/.git"))
home_git = home / ".git"
git_repos = [home_git] if home_git.exists() else []
git_repos.extend(home.glob("*/.git"))
if git_repos:
io.tool_output("Found existing Git repositories in folders in your home directory:")
io.tool_output("Found existing Git repositories in your home directory:")
for i, repo in enumerate(git_repos, 1):
io.tool_output(f"{i}. {repo.parent.name}")
repo_name = "Home directory" if repo == home_git else repo.parent.name
io.tool_output(f"{i}. {repo_name}")
while True:
choice = io.prompt_ask(
@ -42,11 +45,12 @@ def setup_git_home(io):
try:
choice_num = int(choice)
if 1 <= choice_num <= len(git_repos):
return str(git_repos[choice_num - 1].parent)
chosen_repo = git_repos[choice_num - 1]
return str(home if chosen_repo == home_git else chosen_repo.parent)
else:
io.tool_error(f"Please enter a number between 1 and {len(git_repos)}")
except ValueError:
io.tool_error("Please enter a valid number or 'n'")
io.tool_error("Please enter a valid number")
project_name = io.user_input("Enter a name for your new project directory: ")
new_dir = home / project_name