Create a git versioned project with cookiecutter
Asked Answered
J

2

7

I have a nested git repository structure, as below:

outer_repository/
|-- outer_dummy_file
|-- .git 
`-- inner_repository
    |-- .git
    `-- inner_dummy_file

Is it possible to make inner_repository/.git versioned with the outer repository?

Motivation:

I'm making a structure for new projects with cookiecutter. Every newly started project will have a predefined set of files and tools to begin with. One of the requirements for the automated versioning system if for the new project to be versioned with git and having an initial commit. The inner_repository is a structure for the new projects.

Jujutsu answered 24/7, 2016 at 20:47 Comment(1)
have you looked at git submodule or git subtree?Hirza
J
12

It is possible to achieve this without the need to do the git acrobatics. Cookiecutter provides an option to run post generation hooks. This allows creation of the git repository to happen on project creation.

I've added the following in my cookiecutter repository:

hooks/
`-- post_gen_project.py

where post_gen_project.py is:

import subprocess

subprocess.call(['git', 'init'])
subprocess.call(['git', 'add', '*'])
subprocess.call(['git', 'commit', '-m', 'Initial commit'])
Jujutsu answered 24/7, 2016 at 23:23 Comment(0)
K
0

Just create a versioned template project (with initial files etc.), and let new projects be a fork of the template project? Versioning the .git content sounds like a bad idea.

Kampmann answered 24/7, 2016 at 21:37 Comment(1)
In general it is. This is a specific question on generating a cookiecutter project that is already a git repo. As to your suggestion, if I would to clone a project, all the directory naming would remain the same while with cookiecutter I can define project name and other project specific attributes that will be automatically assigned upon project creation. "Assigned" means that template variables in files and filenames will be replaced with the appropriate strings for that project.Jujutsu

© 2022 - 2024 — McMap. All rights reserved.