mirror of
https://github.com/x-motemen/ghq.git
synced 2026-09-10 07:26:27 -04:00
Merge pull request #257 from motemen/vcs-detection
detect VCS backend from URL scheme
This commit is contained in:
commit
8fcf23784b
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/Songmu/gitconfig"
|
||||
|
|
@ -113,6 +114,15 @@ func (repo *OtherRepository) IsValid() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
var (
|
||||
vcsSchemeReg = regexp.MustCompile(`^(git|svn|bzr)(?:\+|$)`)
|
||||
scheme2vcs = map[string]*VCSBackend{
|
||||
"git": GitBackend,
|
||||
"svn": SubversionBackend,
|
||||
"bzr": BazaarBackend,
|
||||
}
|
||||
)
|
||||
|
||||
// VCS detects VCSBackend of the OtherRepository
|
||||
func (repo *OtherRepository) VCS() (*VCSBackend, *url.URL) {
|
||||
// Respect 'ghq.url.https://ghe.example.com/.vcs' config variable
|
||||
|
|
@ -127,6 +137,10 @@ func (repo *OtherRepository) VCS() (*VCSBackend, *url.URL) {
|
|||
return backend, repo.URL()
|
||||
}
|
||||
|
||||
if m := vcsSchemeReg.FindStringSubmatch(repo.url.Scheme); len(m) > 1 {
|
||||
return scheme2vcs[m[1]], repo.URL()
|
||||
}
|
||||
|
||||
mayBeSvn := strings.HasPrefix(repo.url.Host, "svn.")
|
||||
if mayBeSvn && cmdutil.RunSilently("svn", "info", repo.url.String()) == nil {
|
||||
return SubversionBackend, repo.URL()
|
||||
|
|
|
|||
|
|
@ -35,6 +35,10 @@ func TestNewRemoteRepository(t *testing.T) {
|
|||
url: "http://hub.darcs.net/foo/bar",
|
||||
valid: true,
|
||||
vcsBackend: DarcsBackend,
|
||||
}, {
|
||||
url: "svn+ssh://example.com/proj/repo",
|
||||
valid: true,
|
||||
vcsBackend: SubversionBackend,
|
||||
}}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
|
|
|||
Loading…
Reference in a new issue