Skip to content

Commit

Permalink
handle case where user makes a mistake with their github username
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsilver committed Aug 25, 2024
1 parent 1238421 commit c3548f0
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions apply_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,29 @@ def _main() -> None:
shutil.rmtree(git_repo)

# Initialize the repo anew.
subprocess.run(["git", "init", "-b", "main"], check=True)
subprocess.run(["git", "init", "-b", "main"], check=True, capture_output=True)
subprocess.run(["git", "add", "."], check=True)

# Check if the remote already exists (if this script is being run twice).
# This can happen if the user makes a mistake in their GitHub username.
ret = subprocess.run(
["git", "remote", "get-url", "origin"],
shell=True,
text=True,
capture_output=True,
check=False,
)
# Remote already exists, so set the URL.
if ret.returncode == 0:
remote_command = "set-url"
# Remote doesn't exist, so add the URL.
else:
remote_command = "add"
subprocess.run(
[
"git",
"remote",
"add",
remote_command,
"origin",
f"[email protected]:{github_username}/{repo_name}.git",
],
Expand Down

0 comments on commit c3548f0

Please sign in to comment.