0

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"

PseudoAj
  • 5,234
  • 2
  • 17
  • 37
elz
  • 5,338
  • 3
  • 28
  • 30
  • Have you tried creating a git repository in `/my/local/folder`? You shouldn't have to push it anywhere. – Michael Mior Jul 20 '17 at 18:43
  • I think so, that is what I was trying to do with the `git init` command above. I can run `git status` successfully in the directory but cookiecutter still doesn't seem to recognize it. – elz Jul 20 '17 at 18:50
  • Ah, you're right. Sorry I missed that. You should also try commiting all the files in `/my/local/folder`. If cookiecutter is trying to pull from the repository, there will be nothing to pull if you don't commit. – Michael Mior Jul 20 '17 at 19:04
  • I left it empty initially, and just committed a sample text file. Still getting the same error message. – elz Jul 20 '17 at 19:13
  • On inspecting the cookiecutter source code, a repository is not considered valid unless it contains a `cookiecutter.json` file. It doesn't appear as though a git repo is necessary at all. – Michael Mior Jul 20 '17 at 20:34

2 Answers2

0

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.

Carel
  • 3,289
  • 2
  • 27
  • 44
0

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

MrRobot
  • 483
  • 1
  • 7
  • 18