func (s *HgRepo) CheckLocal() bool {
	if _, err := os.Stat(s.LocalPath() + "/.hg"); err == nil {
		return true
	}
	return false
}
CheckLocal verifies the local location is a Git repo.
package vcs
import (
	"encoding/xml"
	"os"
	"os/exec"
	"regexp"
	"strings"
	"time"
)
var hgDetectURL = regexp.MustCompile("default = (?P<foo>.+)\n")
func NewHgRepo(remote, local string) (*HgRepo, error) {
	ins := depInstalled("hg")
	if !ins {
		return nil, NewLocalError("hg is not installed", nil, "")
	}
	ltype, err := DetectVcsFromFS(local)
	if err == nil && ltype != Hg {
		return nil, ErrWrongVCS
	}
	r := &HgRepo{}
	r.setRemote(remote)
	r.setLocalPath(local)
	r.Logger = Logger
	if err == nil && r.CheckLocal() == true {
		c := exec.Command("hg", "paths")
		c.Dir = local
		c.Env = envForDir(c.Dir)
		out, err := c.CombinedOutput()
		if err != nil {
			return nil, NewLocalError("Unable to retrieve local repo information", err, string(out))
		}
		m := hgDetectURL.FindStringSubmatch(string(out))
		if m[1] != "" && m[1] != remote {
			return nil, ErrWrongRemote
		}
		if remote == "" && m[1] != "" {
			r.setRemote(m[1])
		}
	}
	return r, nil
}
type HgRepo struct {
	base
}
func (s HgRepo) Vcs() Type {
	return Hg
}
func (s *HgRepo) Get() error {
	out, err := s.run("hg", "clone", s.Remote(), s.LocalPath())
	if err != nil {
		return NewRemoteError("Unable to get repository", err, string(out))
	}
	return nil
}
func (s *HgRepo) Init() error {
	out, err := s.run("hg", "init", s.LocalPath())
	if err != nil {
		return NewLocalError("Unable to initialize repository", err, string(out))
	}
	return nil
}
func (s *HgRepo) Update() error {
	return s.UpdateVersion(``)
}
func (s *HgRepo) UpdateVersion(version string) error {
	out, err := s.RunFromDir("hg", "pull")
	if err != nil {
		return NewLocalError("Unable to update checked out version", err, string(out))
	}
	if len(strings.TrimSpace(version)) > 0 {
		out, err = s.RunFromDir("hg", "update", version)
	} else {
		out, err = s.RunFromDir("hg", "update")
	}
	if err != nil {
		return NewLocalError("Unable to update checked out version", err, string(out))
	}
	return nil
}
func (s *HgRepo) Version() (string, error) {
	out, err := s.RunFromDir("hg", "--debug", "identify")
	if err != nil {
		return "", NewLocalError("Unable to retrieve checked out version", err, string(out))
	}
	parts := strings.SplitN(string(out), " ", 2)
	sha := parts[0]
	return strings.TrimSpace(sha), nil
}
func (s *HgRepo) Current() (string, error) {
	out, err := s.RunFromDir("hg", "branch")
	if err != nil {
		return "", err
	}
	branch := strings.TrimSpace(string(out))
	tip, err := s.CommitInfo("max(branch(" + branch + "))")
	if err != nil {
		return "", err
	}
	curr, err := s.Version()
	if err != nil {
		return "", err
	}
	if tip.Commit == curr {
		return branch, nil
	}
	ts, err := s.TagsFromCommit(curr)
	if err != nil {
		return "", err
	}
	if len(ts) > 0 {
		return ts[0], nil
	}
	return curr, nil
}
func (s *HgRepo) Date() (time.Time, error) {
	version, err := s.Version()
	if err != nil {
		return time.Time{}, NewLocalError("Unable to retrieve revision date", err, "")
	}
	out, err := s.RunFromDir("hg", "log", "-r", version, "--template", "{date|isodatesec}")
	if err != nil {
		return time.Time{}, NewLocalError("Unable to retrieve revision date", err, string(out))
	}
	t, err := time.Parse(longForm, string(out))
	if err != nil {
		return time.Time{}, NewLocalError("Unable to retrieve revision date", err, string(out))
	}
	return t, nil
}