hashicorp / go-getter

Package for downloading things from a string URL using a variety of protocols.
Mozilla Public License 2.0
1.66k stars 235 forks source link

add support for 'git::' force support on local filepaths, both absolute and relative #268

Open salewski opened 4 years ago

salewski commented 4 years ago

It would be cool if the git:: forcing token could be used on local file system paths, both absolute paths and relative paths. For example:

    git::./some/relative/path/to/a/git-repo//some-subdir?ref=v1.2.3

or:

    git::/some/absolute/path/to/a/git-repo//some-subdir?ref=v4.5.6

Internally, go-getter should transform the provided string into a file:// URI with an absolute filepath, with query string params and subdirectory notation retained.

The rationale for using a file:// URI internally is that the Git clone operation can work with file:// URIs, and using them for this feature would allow us to leverage the existing go-getter URI-handling machinery. That would get us support for query params (to clone a specific git ref (tag, commit hash, ...)) "for free".

The rationale for using an absolute filepath (even when the provided string is a relative filepath) is that (per RFC 1738 and RFC 8089) only absolute filepaths are legitimate in file:// URIs. But more importantly, the Git clone operation only supports file:// URIs with absolute paths.

For projects using Terraform, in particular, this feature would enable the non-fragile use of relative paths in a module "call" block, when combined with Git submodules:

    module "aljunk_parent" {
        source = "git::../git-submodules/tf-modules/some-tf-module?ref=v0.1.0"
        // ...
    }

In the above example "superproject" Git repo (the one "calling" the terraform module) knows the relative path to its own Git submodules because they are embedded in a subdirectory beneath the top-level of the "superproject" repo.

There are at least two downstream Terraform issues open that would require go-getter support for this feature:

I have a branch that implements this feature. I'll open a PR to get feedback on it shortly.

lorengordon commented 6 months ago

Just playing around today, and this syntax actually works already: git::file:///full/path/to/repo/?ref=....