elz
elz

Reputation: 5718

Python cookiecutter without remote git repository

I have recently discovered cookiecutter and would like to try the structure for some of my work projects, but we can't always push code to a remote repo (even a private one). I often use git locally just to track changes for my own purposes. Is there a way to run cookiecutter /my/local/folder to set everything up without a remote repository?

I have tried

cd /my/local/folder
git init
cookiecutter /my/local/folder

but get the error message:

"A valid repository for for "/my/local/folder" could not be found in the following locations: /my/local/folder"

Upvotes: 0

Views: 3935

Answers (2)

MrRobot
MrRobot

Reputation: 501

If i understand correctly, when you need to render a template, using a local cookiecutter project, here is an example command for how you can do it :

cookiecutter --no-input /path/to/your/local/cookiecutter_project/ --checkout branch_to_use --config-file your_config.yml

When you use a remote, the command will simply reference the url of the remote repo, as follows for a github project for example :

cookiecutter --no-input https://github.com/repo/project.git --checkout branch_to_use --config-file your_config.yml

Hope it helps

Upvotes: 0

Carel
Carel

Reputation: 3397

The comment by @Michael Mior is spot on, that error results when the root of the cookiecutter does not contain a cookiecutter.json file. The check for this is performed by repository_has_cookiecutter_json in repository.py

From the documentation one may point to a path ending in .git, which is weird, but this seems like a convention more then it is a norm. See https://github.com/cookiecutter/cookiecutter/pull/1184 for more the most current information regarding this. In determine_repo_dir in repository.py it appears as though the existence of the directory is checked but that this is never probed for a version control implementation.

Cookiecutter, for the moment, appears to ignore any version controlled local repositories.

Upvotes: 0

Related Questions