diff --git a/commands.go b/commands.go index dd05ccfc..0ce7908c 100644 --- a/commands.go +++ b/commands.go @@ -27,6 +27,7 @@ var cloneFlags = []cli.Flag{ cli.BoolFlag{Name: "update, u", Usage: "Update local repository if cloned already"}, cli.BoolFlag{Name: "p", Usage: "Clone with SSH"}, cli.BoolFlag{Name: "shallow", Usage: "Do a shallow clone"}, + cli.StringFlag{Name: "vcs", Usage: "Specify VCS backend for cloning"}, } var commandGet = cli.Command{ @@ -91,7 +92,7 @@ type commandDoc struct { } var commandDocs = map[string]commandDoc{ - "get": {"", "[-u] | [-u] [-p] /"}, + "get": {"", "[-u] [--vcs ] | [-u] [-p] /"}, "list": {"", "[-p] [-e] []"}, "look": {"", " | / | //"}, "import": {"", "< file"}, @@ -129,6 +130,7 @@ func doGet(c *cli.Context) error { argURL := c.Args().Get(0) doUpdate := c.Bool("update") isShallow := c.Bool("shallow") + vcsBackend := c.String("vcs") if argURL == "" { cli.ShowCommandHelp(c, "get") @@ -176,14 +178,14 @@ func doGet(c *cli.Context) error { os.Exit(1) } - getRemoteRepository(remote, doUpdate, isShallow) + getRemoteRepository(remote, doUpdate, isShallow, vcsBackend) return nil } // getRemoteRepository clones or updates a remote repository remote. // If doUpdate is true, updates the locally cloned repository. Otherwise does nothing. // If isShallow is true, does shallow cloning. (no effect if already cloned or the VCS is Mercurial and git-svn) -func getRemoteRepository(remote RemoteRepository, doUpdate bool, isShallow bool) { +func getRemoteRepository(remote RemoteRepository, doUpdate bool, isShallow bool, vcsBackend string) { remoteURL := remote.URL() local := LocalRepositoryFromURL(remoteURL) @@ -202,10 +204,14 @@ func getRemoteRepository(remote RemoteRepository, doUpdate bool, isShallow bool) if newPath { utils.Log("clone", fmt.Sprintf("%s -> %s", remoteURL, path)) - vcs, repoURL := remote.VCS() + vcs := vcsRegistry[vcsBackend] + repoURL := remoteURL if vcs == nil { - utils.Log("error", fmt.Sprintf("Could not find version control system: %s", remoteURL)) - os.Exit(1) + vcs, repoURL = remote.VCS() + if vcs == nil { + utils.Log("error", fmt.Sprintf("Could not find version control system: %s", remoteURL)) + os.Exit(1) + } } err := vcs.Clone(repoURL, path, isShallow) @@ -364,9 +370,10 @@ func doLook(c *cli.Context) error { func doImport(c *cli.Context) error { var ( - doUpdate = c.Bool("update") - isSSH = c.Bool("p") - isShallow = c.Bool("shallow") + doUpdate = c.Bool("update") + isSSH = c.Bool("p") + isShallow = c.Bool("shallow") + vcsBackend = c.String("vcs") ) var ( @@ -432,7 +439,7 @@ func doImport(c *cli.Context) error { continue } - getRemoteRepository(remote, doUpdate, isShallow) + getRemoteRepository(remote, doUpdate, isShallow, vcsBackend) } if err := scanner.Err(); err != nil { utils.Log("error", fmt.Sprintf("While reading input: %s", err)) diff --git a/remote_repository.go b/remote_repository.go index dbf2415c..05e077e5 100644 --- a/remote_repository.go +++ b/remote_repository.go @@ -175,7 +175,7 @@ func (repo *OtherRepository) VCS() (*VCSBackend, *url.URL) { vcs, repoURL, err := detectGoImport(repo.url) if err == nil { // vcs == "mod" (modproxy) not supported yet - return vcsBackendMap[vcs], repoURL + return vcsRegistry[vcs], repoURL } if utils.RunSilently("hg", "identify", repo.url.String()) == nil { diff --git a/vcs.go b/vcs.go index aa986635..aa8286fa 100644 --- a/vcs.go +++ b/vcs.go @@ -111,8 +111,13 @@ var DarcsBackend = &VCSBackend{ }, } -var vcsBackendMap = map[string]*VCSBackend{ - "git": GitBackend, - "hg": MercurialBackend, - "svn": SubversionBackend, +var vcsRegistry = map[string]*VCSBackend{ + "git": GitBackend, + "github": GitBackend, + "svn": SubversionBackend, + "subversion": SubversionBackend, + "git-svn": GitsvnBackend, + "hg": MercurialBackend, + "mercurial": MercurialBackend, + "darcs": DarcsBackend, }