From cbc2a87c7378b728dc33c231185cc9b70868f80a Mon Sep 17 00:00:00 2001 From: morganamilo Date: Tue, 9 Oct 2018 01:12:10 +0100 Subject: [PATCH 1/2] Use correct source protocol for VCS checks Previously it was assumed that "git+https" means: use git and if that fails fall back to https. What this actually means is just: use git over https. Similary "git" just means use git and "git+http" means use git over http. Thus there is only ever one protocol to use. The current protocols array has been kept for backwards compatibility with the vcs.json file. The difference being now it will only ever place one protocol into the array. Also when reading the array, the last protocol is always used. This is so that entries that have not been regenerated will use the correct protocol. --- vcs.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/vcs.go b/vcs.go index aba8c0cf..d8cad5a3 100644 --- a/vcs.go +++ b/vcs.go @@ -62,7 +62,7 @@ func parseSource(source string) (url string, branch string, protocols []string) if len(split) != 2 { return "", "", nil } - protocols = strings.Split(split[0], "+") + protocols = strings.SplitN(split[0], "+", 2) git := false for _, protocol := range protocols { @@ -72,6 +72,8 @@ func parseSource(source string) (url string, branch string, protocols []string) } } + protocols = protocols[len(protocols)-1:] + if !git { return "", "", nil } @@ -142,7 +144,8 @@ func updateVCSData(pkgName string, sources []gosrc.ArchString, mux *sync.Mutex, } func getCommit(url string, branch string, protocols []string) string { - for _, protocol := range protocols { + if len(protocols) > 0 { + protocol := protocols[len(protocols)-1] var outbuf bytes.Buffer cmd := passToGit("", "ls-remote", protocol+"://"+url, branch) @@ -151,7 +154,7 @@ func getCommit(url string, branch string, protocols []string) string { err := cmd.Start() if err != nil { - continue + return "" } //for some reason @@ -165,14 +168,14 @@ func getCommit(url string, branch string, protocols []string) string { err = cmd.Wait() timer.Stop() if err != nil { - continue + return "" } stdout := outbuf.String() split := strings.Fields(stdout) if len(split) < 2 { - continue + return "" } commit := split[0] From f26f36d45943444ef5bde09ac35dd61acfbe7319 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Tue, 9 Oct 2018 01:21:31 +0100 Subject: [PATCH 2/2] Update tests --- vcs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcs_test.go b/vcs_test.go index 6fdee82a..d5a6d2c7 100644 --- a/vcs_test.go +++ b/vcs_test.go @@ -44,7 +44,7 @@ func TestParsing(t *testing.T) { } sources := []source{ - {"github.com/neovim/neovim.git", "HEAD", []string{"git", "https"}}, + {"github.com/neovim/neovim.git", "HEAD", []string{"https"}}, {"github.com/jguer/yay.git", "master", []string{"git"}}, {"github.com/davidgiven/ack", "HEAD", []string{"git"}}, {"", "", nil},