gitfs icon indicating copy to clipboard operation
gitfs copied to clipboard

Feature request: support SSH-style git URLs

Open krokicki opened this issue 5 years ago • 4 comments

When the git repo is configured with SSH (i.e. the remote starts with "[email protected]:krokicki/myproject.git") then binary packing fails as follows (gitfs.New fails the same way):

$ gitfs ./...
panic: failed parsing URL: [email protected]:krokicki/myproject.git

goroutine 1 [running]:
github.com/posener/gitfs/internal/localfs.urlProjectName(0xc0001a2c60, 0x26, 0x1, 0x1)
        /Users/tester/go/pkg/mod/github.com/posener/[email protected]/internal/localfs/localfs.go:99 +0x1fb
github.com/posener/gitfs/internal/localfs.computeSubdir(0x189fe74, 0x28, 0xc0001b9540, 0x18, 0x0, 0x0, 0x20, 0x18)
        /Users/tester/go/pkg/mod/github.com/posener/[email protected]/internal/localfs/localfs.go:45 +0x14b
github.com/posener/gitfs/internal/localfs.New(0x189fe74, 0x28, 0xc00003600c, 0x1, 0xc00019a040, 0x1e7c801, 0x2, 0xc00024fb38)
        /Users/tester/go/pkg/mod/github.com/posener/[email protected]/internal/localfs/localfs.go:24 +0x84
github.com/posener/gitfs.New(0x19a95e0, 0xc0001a4000, 0x189fe74, 0x28, 0xc00024fbf0, 0x1, 0x1, 0x30, 0xc000275170, 0x0, ...)
        /Users/tester/go/pkg/mod/github.com/posener/[email protected]/gitfs.go:199 +0x136
project/cmd.generateDockerfile(0x1891c4c, 0x18, 0x17e6760, 0xc000275170)
        /Users/tester/dev/project/cmd/init.go:207 +0xf8
project/cmd.initProjectJavaMaven()
        /Users/tester/dev/project/cmd/init.go:161 +0x17f
project/cmd.glob..func1(0x1ecaf40, 0xc000241110, 0x1, 0x1)
        /Users/tester/dev/project/cmd/init.go:59 +0x1f8
github.com/spf13/cobra.(*Command).execute(0x1ecaf40, 0xc0002410d0, 0x1, 0x1, 0x1ecaf40, 0xc0002410d0)
        /Users/tester/go/pkg/mod/github.com/spf13/[email protected]/command.go:846 +0x29d
github.com/spf13/cobra.(*Command).ExecuteC(0x1ecb1e0, 0x10437aa, 0x1e87fe0, 0xc000000180)
        /Users/tester/go/pkg/mod/github.com/spf13/[email protected]/command.go:950 +0x349
github.com/spf13/cobra.(*Command).Execute(...)
        /Users/tester/go/pkg/mod/github.com/spf13/[email protected]/command.go:887
project/cmd.Execute()
        /Users/tester/dev/project/cmd/root.go:24 +0x31
main.main()
        /Users/tester/dev/project/main.go:6 +0x20

It worked after switching to HTTPS style remote ("https://github.com/krokicki/myproject.git") It would be nice if the SSH style was also supported.

krokicki avatar Aug 14 '20 02:08 krokicki

Hey, Yes, this is currently not supported. This is the [switch]( https://github.com/posener/gitfs/blob/ea4e48d73ab9a07f817860bdd5fb0bddff1f68b0/gitfs.go#L196) where the URL is being matched to any of the supported.

What prevents you from using the HTTP URL?

posener avatar Aug 15 '20 05:08 posener

That switch statement just determines that this is a local repo, which is correct. The issue is that localfs.go doesn't do that kind of validation, it just takes the repo's remote URL and passes it to url.Parse which results in this somewhat cryptic error.

HTTPS is absolutely fine to use, but I do wish there was a way to use it for gitfs without changing the remote URL on my git repo. I wonder if it would be safe to just have gitfs transform the SSH URL. It seems like it would be a fairly trivial transform, e.g. strings.Replace(url,"[email protected]:","https://github.com/",1)

krokicki avatar Aug 15 '20 15:08 krokicki

It seems like it would be a fairly trivial transform, e.g. strings.Replace(url,"[email protected]:","https://github.com/",1)

I wouldn't do that. If a user provides ssh credentials URL it means that the user wants to use a different protocol than github APIs.

posener avatar Aug 16 '20 07:08 posener

Yes, it would be less than ideal. I don't have any other workaround ideas, besides actually implementing SSH support. Thanks for considering.

krokicki avatar Aug 17 '20 20:08 krokicki