Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieving a single file from a git repo? #98

Open
lorengordon opened this issue Jan 29, 2018 · 7 comments · May be fixed by #355
Open

Retrieving a single file from a git repo? #98

lorengordon opened this issue Jan 29, 2018 · 7 comments · May be fixed by #355

Comments

@lorengordon
Copy link

lorengordon commented Jan 29, 2018

Is go-getter able to retrieve a single file from a git repo? It appears to work fine when the source is a directory, but not when the source is a file.

It does create the target directory, but does not write the file.

$ ./go-getter github.com/hashicorp/go-getter//helper/url/url.go url
2018/01/29 16:12:51 Success!
$ cat url/url.go
cat: url/url.go: No such file or directory
$ ls -al url/url.go
ls: cannot access url/url.go: No such file or directory
$ ls -al url
total 0
drwxr-xr-x 2 ec2-user ec2-user   6 Jan 29 16:12 .
drwx------ 5 ec2-user ec2-user 124 Jan 29 16:12 ..

Also tried specifying the destination as a filename, but that just creates a directory named for the file:

$ ./go-getter github.com/hashicorp/go-getter//helper/url/url.go url/url.go
2018/01/29 16:21:36 Success!
$ ls -al url
total 0
drwxr-xr-x 3 ec2-user ec2-user  20 Jan 29 16:21 .
drwx------ 5 ec2-user ec2-user 124 Jan 29 16:12 ..
drwxr-xr-x 2 ec2-user ec2-user   6 Jan 29 16:21 url.go
$ ls -al url/url.go
total 0
drwxr-xr-x 2 ec2-user ec2-user  6 Jan 29 16:21 .
drwxr-xr-x 3 ec2-user ec2-user 20 Jan 29 16:21 ..
@mumoshu
Copy link

mumoshu commented Jan 31, 2019

It didn't work for me either, but there's a workaround in a case where your source is GitHub:

go-getter -mode=file https://raw.githubusercontent.com/hashicorp/go-getter/master/helper/url/url.go url.go

Or omitting -mode=file results in downloading the single file into a directory:

$ go-getter https://raw.githubusercontent.com/hashicorp/go-getter/master/helper/url/url.go test
2019/01/31 15:32:37 success!
$ tree test
test
└── url.go

0 directories, 1 file

@marshallford
Copy link

I'm curious, is there a technical limitation that is preventing this?

@caitlinelfring
Copy link

I found that you can use go-getter to download a file from a github repo as long as the file is in the root and you force it to use ssh. Subdirectories don't seem to work (I think it might be a bug in the code).

The downside of this is go-getter clones the entire repo into a temp directory and only copies the file to the destination

$ go-getter -mode=file git@github.com:hashicorp/go-getter.git/README.md test/README.md
2021/07/11 15:42:56 success!

$ file test/README.md
test/README.md: ASCII text, with very long lines

Subdirectory...

$ go-getter -mode=file git@github.com:hashicorp/go-getter.git/helper/url/url.go test/url.go
2021/07/11 15:44:56 Error downloading: /usr/local/bin/git exited with 128: Cloning into '/var/folders/hw/6rsc6cbj5nddyhgfbwpdc5z80000gn/T/getter238570144/temp'...
fatal: remote error:
  hashicorp/go-getter.git/helper/url is not a valid repository name
  Visit https://support.github.com/ for help

# let's try with the subdirectory syntax
$ go-getter -mode=file git@github.com:hashicorp/go-getter.git//helper/url/url.go test/url.go
2021/07/11 15:45:05 Error downloading: /usr/local/bin/git exited with 128: Cloning into '/var/folders/hw/6rsc6cbj5nddyhgfbwpdc5z80000gn/T/getter520566758/temp'...
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Hope this helps

@arikkfir
Copy link

Created a fork that fixes this issue at arikkfir/go-getter (see branches support_getfile_from_github and support_getfile_from_github_v2)
Opened two corresponding PRs in this repo with the fix & tests; see #355 and #356

@marcoferrer
Copy link

I've run into this issue and was curious if we can expect fix being merged upstream at some point. The only difference is that this issue isnt isolated to the github getter for us.

@arikkfir
Copy link

arikkfir commented Aug 3, 2022

For anyone who needs a stable release that incorporates this, I've created releases in my fork arikkfir/go-getter, based on the current releases v2.0.2 and v2.1.0:

The release notes include instructions on how to use them (single-liner to your go.mod file).

For the go-getter team - would be great to get #355 and #356 merged so the main releases provide this capability.

@JuryA
Copy link

JuryA commented Nov 19, 2022

Any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants