forked from Masterminds/vcs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
65 lines (58 loc) · 2.75 KB
/
get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright © 2015,2016 Erik Brady <brady@dvln.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package vcs
// Getter provides a small interface to work with different VCS systems with
// respect to "getting" a VCS and bringing it into a workspace, it requires
// one to pass in a vcs.Describer so it can find the remote VCS and identify
// where to put it locally
type Getter interface {
// Describer access to VCS system details (Remote, LocalRepoPath, ..)
Describer
// RevSet matches the RevSet() interface sig from RevSetter. Due to Go's
// design here can't just make this a RevSetter since the overall Reader
// in repo.go includes RevReader and the Getter interface (and how Go works
// is a compile error indicating duplicate method names)
// see: https://groups.google.com/forum/#!topic/golang-nuts/OKgbtTW-5YQ
RevSet(Rev) (Resulter, error)
// Exists will determine if the repo exists (remotely or in local dir)
Exists(Location) (string, Resulter, error)
// Get is used to perform an initial clone/checkout of a repository.
Get(...Rev) (Resulter, error)
}
// NewGetter returns a VCS Getter based on the given VCS description info about
// the remote (URL typically) and workspace (dir/path) locations. If the VCS info
// is minimal (eg: not a full URL with scheme) then this will try and detect
// VCS type (if unable to determine an ErrCannotDetectVCS will be returned).
// Note: This function can make network calls to try to determine the VCS
func NewGetter(remote, remoteName, localPath string, mirror bool, vcsType ...Type) (Getter, error) {
vtype, remote, err := detectVCSType(remote, localPath, vcsType...)
if err != nil {
return nil, err
}
switch vtype {
case Git:
return NewGitGetter(remote, remoteName, localPath, mirror)
case Svn:
return NewSvnGetter(remote, remoteName, localPath, mirror)
case Hg:
return NewHgGetter(remote, remoteName, localPath, mirror)
case Bzr:
return NewBzrGetter(remote, remoteName, localPath, mirror)
}
// Should never fall through to here but just in case.
//FIXME: I think we need an ErrVCSNotImplemented or
// something like that to indicate the VCS does
// not support the given operation (leading towards
// support for VCS's that only support some ops)
return nil, ErrCannotDetectVCS
}