Skip to content

Commit

Permalink
Added Git Initialisation Hooks (pybamm-team#32)
Browse files Browse the repository at this point in the history
+ Added `git` initialisation hooks in the template to automatically
initialise a `git repository` when a `generated project` is created by
`cookiecutter`.
+ Added a default `main` branch parameter for git repository
initialisation.

Subtask - pybamm-team#26
  • Loading branch information
santacodes authored Jul 23, 2024
1 parent b6ea4f1 commit db24f92
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
],
"org": "pybamm-team",
"url": "https://{{ cookiecutter.platform }}.com/{{ cookiecutter.org }}/{{ cookiecutter.project_name }}",
"branch": "main",
"full_name": "John Doe",
"email": "[email protected]",
"project_short_description": "A template for creating battery modeling projects based on PyBaMM",
Expand All @@ -31,7 +32,8 @@
"gitlab": "GitLab"
},
"org": "The name of your organisation (or username, if you are not part of an organisation)",
"url": "The URL to your repository",
"url": "The Origin URL to your repository",
"branch": "The default branch of your repository",
"full_name": "Your name",
"email": "Your email",
"project_short_description": "A short description of your project",
Expand Down
24 changes: 24 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import subprocess

from pathlib import Path

def prepare_git() -> None:

git_author_name = "{{cookiecutter.full_name}}"
git_author_email = "{{cookiecutter.email}}"
git_branch = "{{cookiecutter.branch}}"

# Initialise git
subprocess.call(
["git", "init", "-b", git_branch]
)
subprocess.call(
["git", "config", "user.name", git_author_name]
)
subprocess.call(
["git", "config", "user.email", git_author_email]
)

if __name__ == "__main__":
print("Executing script!!")
prepare_git()

0 comments on commit db24f92

Please sign in to comment.