I'm trying to use https://github.com/libgit2/git2go for cloning repository from GCP Source repository
But, I'm getting failed to resolve path '/tmp/repo/.git/': No such file or directory"
By using gcloud source repo clone, it works.
func initRepo(url, path, auth string) (*git.Repository, error) {
var repo *git.Repository
var err error
osPath := "/tmp/" + path
repo, err = git.OpenRepository(osPath)
if err != nil {
repo, err = git.Clone(url, osPath, &git.CloneOptions{
FetchOptions: &git.FetchOptions{
Headers: []string{auth},
},
})
}
return repo, err
}
func main() {
ctx := context.Background()
ts, err := google.DefaultTokenSource(ctx, sourcerepo.SourceFullControlScope)
if err != nil {
panic(err)
}
token, err := ts.Token()
if err != nil {
panic(err)
}
auth := "Authorization: " + token.Type() + " " + token.AccessToken
gitRepo, err := initRepo("https://source.developers.google.com/p/project/r/repo", "repo", auth)
if err != nil {
panic(err)
}
What can cause this error? Running on local machine it works, even in my docker container.
I'm betting my buck on the git2go library you're using not being capable of creating a directory at
/tmp/repo/.git/
. Make sure to mkdir the/tmp/repo
first yourself maybe? Maybe/tmp
doesn't exist?