Skip to content

Add file:// as a suitable protocol (#1)#1184

Merged
pydanny merged 2 commits intocookiecutter:masterfrom
ivanovmg:master
Jul 30, 2019
Merged

Add file:// as a suitable protocol (#1)#1184
pydanny merged 2 commits intocookiecutter:masterfrom
ivanovmg:master

Conversation

@ivanovmg
Copy link
Copy Markdown
Contributor

@ivanovmg ivanovmg commented Jul 4, 2019

Add file:// as a suitable protocol

Required if the repo is stored in Windows server, or other shared folder.

Enables the following:
$ cookiecutter "file://path/to/server/repo.git"

* Add file:// as a suitable protocol

This is required if the repo is stored in Windows server,
or other shared folder.
docs/usage.rst Outdated
$ cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git
$ cookiecutter git+ssh://git@github.com/audreyr/cookiecutter-pypackage.git
$ cookiecutter hg+ssh://hg@bitbucket.org/audreyr/cookiecutter-pypackage
$ cookiecutter file://path/to/server/repo.git
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file:// protocol requires 3 slashes as it works only with full paths (mostly due to security).

I think that the examples should include correct file examples.

Copy link
Copy Markdown
Contributor Author

@ivanovmg ivanovmg Jul 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback!

The problem is that when I try to clone repo using the command with 3 slashes, it leads to an error.

$ git clone file://server/folder/project.git
Cloning into 'project'...
fatal: 'C:/Program Files/Git/server/folder/project.git' does not appear to be a git repository
fatal: Could not read from remote repository.

For some reason it would search under the folder with git executable, rather than in the absolute path. When I use 2 slashes, like in my example, it works.
OS Windows 10, GitBash or cmd.

Technically, I just need to clone from this kind of path //server/folder/project.git. I figured out, that using the current code and simply allowing file:// (with 2 slashes) to be treated as an url, makes it all work.

Maybe, you can suggest how we can tell cookiecutter to treat //server/folder/project.git as a remote location to make it clone from it?

Thank you in advance!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check https://tools.ietf.org/html/rfc8089 and its original rfc. I am unable to see any valid use of file:// because the first part after it would be a server, not a PATH. Pointing something to local machine woudl require 3 slashes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have mentioned that more clearly in the docs example. My intention was to use file://server/folder/project.git as I mentioned in my previous message. And it stays in accordance with what you have just mentioned.

Should I just update the example to file://server/folder/project.git ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that using server is a good compromise. I just wanted to avoid confusing people into using incorrect file URIs, ones that are not portable.

@ssbarnea ssbarnea added needs-merge needs-review PR Only: This PR require review from other developer labels Jul 13, 2019
@pydanny pydanny merged commit 3e3fa36 into cookiecutter:master Jul 30, 2019
@OvalAdmin
Copy link
Copy Markdown

OvalAdmin commented Jul 13, 2020

I'm trying to run cookiecutter against a local, version controlled, repository and the --checkout BRANCH option seems to largely be ignored. Similarly if I invoke cookiecutter with checkout="BRANCH". I suspect it is not picking up that the cookiecutter resides within a repository as I am passing in a local path for the repository argument. As a consequence I have tried a number of variants of the file:///...folder both with forward and backward slashes and double/triple leading slashes, My results are as follows :

e:\Python>cookiecutter file:///e:/python/biscuits --checkout python
A valid repository for "file:///e:/python/biscuits" could not be found in the following locations:
file:///e:/python/biscuits

e:\Python>cookiecutter file:///e:\python\biscuits --checkout python
A valid repository for "file:///e:\python\biscuits" could not be found in the following locations:
file:///e:\python\biscuits

e:\Python>cookiecutter file:///e:\\python\\biscuits --checkout python
A valid repository for "file:///e:\\python\\biscuits" could not be found in the following locations:
file:///e:\\python\\biscuits

e:\Python>cookiecutter file://e:/python/biscuits --checkout python
A valid repository for "file://e:/python/biscuits" could not be found in the following locations:
file://e:/python/biscuits

e:\Python>cookiecutter file://e:\python\biscuits --checkout python
A valid repository for "file://e:\python\biscuits" could not be found in the following locations:
file://e:\python\biscuits

e:\Python>cookiecutter file://e:\\python\\biscuits --checkout python
A valid repository for "file:///e:/python/biscuits" could not be found in the following locations:
file:///e:/python/biscuits

I am also uncertain of where the .git in .../folder.git originates from ? If I create a normal repository the result is .../folder/.git and if I push this into a "bare" repository there isn't a .git folder. Is this some naming convention that you use to identify folders under version control e.g. ../folder.git, ../folder.svn, .../folder.cvs etc. or is there some other format for a git folder that I'm unaware of ? Renaming my repository as ../folder.git has no effect either. My guess is that this is some form of convention that you use and that the documentation does not reflect this or you are actually pointing to a repository hosted on some form of git server, though which one is not clear (I know gitlab/github append .git to their urls for instance but I do not know how one hosts a repository under such a path ending otherwise; If you do this I'd be keen to know how)

@OvalAdmin
Copy link
Copy Markdown

OvalAdmin commented Jul 13, 2020

After a quick skim through cookiecutter/repository.py it seems as though cookiecutter only tests for the presence of a local folder and does not inspect it for any versioning mechanism. If I follow it correctly the code uses REPO_REGEX to distinguish git|svn|cvs+file://some/path, under version control, from /some/path, without version control. I tested REPO_REGEX does match my use cases above yet the "repository" code that should execute in preference to the "folder" does not and I fall through to the raised exception at the end of determine_repo_dir. It seems that cookiecutter should duplicate local paths, that are version controlled repositories, to be duplicated into the users' .cookiecutter folder in the same manner that a remote repository might be checked out yet for me this is failing.

*aside: * I'll fire up a development environment for this when I have time again but for today I'm out of moonlight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review PR Only: This PR require review from other developer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants