Skip to content

Commit

Permalink
🐍🔧 add check if a repo is already created
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseRZapata committed Feb 12, 2024
1 parent e76c4c4 commit 9089678
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,19 @@ def remove_dir(filepath: str) -> None:
if codecov != "y":
remove_file("codecov.yml")

subprocess.run(["echo", "Initializing git"], check=False) # nosec
subprocess.run(["git", "init", "-b", "main"], check=False) # nosec
subprocess.run(["git", "add", "."], check=False) # nosec
subprocess.run(["git", "commit", "-m", "🎉 Initial commit"], check=False) # nosec
subprocess.run(["echo", "🎉 Project Already created!"], check=False) # nosec
# check if repo is already initialized using `git status`
# if not, initialize the repo and make initial commit
try:
subprocess.run(
["git", "rev-parse", "--is-inside-work-tree"],
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
) # nosec
except subprocess.CalledProcessError:
# We are not in a git repo
subprocess.run(["echo", "Initializing git"], check=False) # nosec
subprocess.run(["git", "init", "-b", "main"], check=False) # nosec
subprocess.run(["git", "add", "."], check=False) # nosec
subprocess.run(["git", "commit", "-m", "🎉 Initial commit"], check=False) # nosec
subprocess.run(["echo", "🎉 Project Already created!"], check=False) # nosec

0 comments on commit 9089678

Please sign in to comment.