In previous article, after project created it can execute custom python script to customize template. In this example, it will extend the project to integrate with git.It will execute git command directly as it will be more prefer on getting environment settings.
Steps
- Add method for calling git commands.
In filehook/post_gen_project.py
, update line as below.import os; def init_git(): commands = [ 'git init', 'git add .', 'git commit -m "Initial commit"' ] try: for command in commands: os.system(command) except: print("Error occurred when init git") exit(1) def main(): init_git() if __name__ == "__main__": main()
You can alter command in array
commands
to customize action such as create feature branch or set remote repository. - Test and verify result
In command prompt, execute command below to test, expect git commit message will be show.cookiecutter java-project-template
Leave a Reply