forked from Masterminds/vcs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hg_upd.go
53 lines (49 loc) · 1.76 KB
/
hg_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
package vcs
// HgUpdater implements the Repo interface for the Mercurial source control.
type HgUpdater struct {
Description
Results
mirror bool
rebase RebaseVal
refs map[string]RefOp
}
// NewHgUpdater creates a new instance of HgUpdater. The remote and localPath directories
// need to be passed in. Params:
// remote (string): URL of remote repo
// remoteName (string): If there is a name for the remote repo (hg: use "", not used)
// 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): list of refs to act on w/given operation (or nil)
// Currently ignores mirror, rebase and refs.
func NewHgUpdater(remote, remoteName, localPath string, mirror bool, rebase RebaseVal, refs map[string]RefOp) (Updater, error) {
ltype, err := DetectVcsFromFS(localPath)
// Found a VCS other than Hg. Need to report an error.
if err == nil && ltype != Hg {
return nil, ErrWrongVCS
}
u := &HgUpdater{}
u.mirror = mirror
u.rebase = rebase
if refs != nil { // if refs given, then set up refs to act on w/ops
u.refs = make(map[string]RefOp)
u.refs = refs
}
u.setDescription(remote, remoteName, localPath, defaultHgSchemes, Hg)
if err == nil { // Have a localPath FS repo, try to validate/upd remote
remote, _, err = HgCheckRemote(u, remote)
if err != nil {
return nil, err
}
u.setRemote(remote)
}
return u, nil // note: above 'err' not used on purpose here..
}
// Update support for hg updater
func (u *HgUpdater) Update(rev ...Rev) (Resulter, error) {
return HgUpdate(u, rev...)
}
// Exists support for hg updater
func (u *HgUpdater) Exists(l Location) (string, Resulter, error) {
return HgExists(u, l)
}