Skip to content

Commit c3548f0

Browse files
committed
handle case where user makes a mistake with their github username
1 parent 1238421 commit c3548f0

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

apply_configuration.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,29 @@ def _main() -> None:
8585
shutil.rmtree(git_repo)
8686

8787
# Initialize the repo anew.
88-
subprocess.run(["git", "init", "-b", "main"], check=True)
88+
subprocess.run(["git", "init", "-b", "main"], check=True, capture_output=True)
8989
subprocess.run(["git", "add", "."], check=True)
90+
91+
# Check if the remote already exists (if this script is being run twice).
92+
# This can happen if the user makes a mistake in their GitHub username.
93+
ret = subprocess.run(
94+
["git", "remote", "get-url", "origin"],
95+
shell=True,
96+
text=True,
97+
capture_output=True,
98+
check=False,
99+
)
100+
# Remote already exists, so set the URL.
101+
if ret.returncode == 0:
102+
remote_command = "set-url"
103+
# Remote doesn't exist, so add the URL.
104+
else:
105+
remote_command = "add"
90106
subprocess.run(
91107
[
92108
"git",
93109
"remote",
94-
"add",
110+
remote_command,
95111
"origin",
96112
f"[email protected]:{github_username}/{repo_name}.git",
97113
],

0 commit comments

Comments
 (0)