forked from Masterminds/vcs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upd.go
72 lines (66 loc) · 3.45 KB
/
upd.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
66
67
68
69
70
71
72
// 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
// Updater provides a small interface to work with different VCS systems with
// respect to bringing in and "merging" remote VCS changes into an existing
// local workspace clone (and any local changes). A Describer interface
// comes in as a parameter to get local repo path and remote location
// info and Exists from the Existence intfc is also needed (sometimes)..
// Note: do not use the interface Existence as it will conflict and result
// in build errors since the Existence itfc also is a Describer
type Updater interface {
// Describer gives access to VCS system details (Remote, LocalRepoPath, ..)
Describer
// Exists will determine if the repo exists (remotely or in localPath)
Exists(Location) (string, Resulter, error)
// Update is used to merge with new central repo changes to local
// workspace, optionally at a given revision (specific single revision)
Update(...Rev) (Resulter, error)
}
// NewUpdater returns a VCS Updater 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
// Params:
// remote (string): URL of remote repo
// remoteName (string): "" or remote repo "name" (eg: "origin" is default for git)
// localPath (string): Directory for the local repo/clone/workspace to update
// mirror (bool): if a full mirroring of all content is desired
// rebase (RebaseVal): if rebase wanted or not, what type
// refs (map[string]RefOp): if specific "refs" to update|delete, list here w/what to do
// - ref is any string references an SCM uses (ops: RefDelete, RefFetch)
// - if refs set, rebase ignored (mirror can be used, see <scm>.go for details)
// vcsType (Type): optional; forcibly tell the pkg what the vcs type is (no auto-determination)
func NewUpdater(remote, remoteName, localPath string, mirror bool, rebase RebaseVal, refs map[string]RefOp, vcsType ...Type) (Updater, error) {
vtype, remote, err := detectVCSType(remote, localPath, vcsType...)
if err != nil {
return nil, err
}
switch vtype {
case Git:
return NewGitUpdater(remote, remoteName, localPath, mirror, rebase, refs)
case Svn:
return NewSvnUpdater(remote, remoteName, localPath, mirror, rebase, refs)
case Hg:
return NewHgUpdater(remote, remoteName, localPath, mirror, rebase, refs)
case Bzr:
return NewBzrUpdater(remote, remoteName, localPath, mirror, rebase, refs)
}
//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)
// Should never fall through to here but just in case.
return nil, ErrCannotDetectVCS
}