func (s *GitRepo) Current() (string, error) {
	out, err := s.RunFromDir("git", "symbolic-ref", "HEAD")
	if err == nil {
		o := bytes.TrimSpace(bytes.TrimPrefix(out, []byte("refs/heads/")))
		return string(o), nil
	}
	v, err := s.Version()
	if err != nil {
		return "", err
	}
	ts, err := s.TagsFromCommit(v)
	if err != nil {
		return "", err
	}
	if len(ts) > 0 {
		return ts[0], nil
	}
	return v, nil
}
Current returns the current version-ish. This means:
* Branch name if on the tip of the branch
* Tag if on a tag
* Otherwise a revision id
package vcs
import (
	"bytes"
	"encoding/xml"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"time"
)
func NewGitRepo(remote, local string) (*GitRepo, error) {
	ins := depInstalled("git")
	if !ins {
		return nil, NewLocalError("git is not installed", nil, "")
	}
	ltype, err := DetectVcsFromFS(local)
	if err == nil && ltype != Git {
		return nil, ErrWrongVCS
	}
	r := &GitRepo{}
	r.setRemote(remote)
	r.setLocalPath(local)
	r.RemoteLocation = "origin"
	r.Logger = Logger
	if err == nil && r.CheckLocal() == true {
		c := exec.Command("git", "config", "--get", "remote.origin.url")
		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))
		}
		localRemote := strings.TrimSpace(string(out))
		if remote != "" && localRemote != remote {
			return nil, ErrWrongRemote
		}
		if remote == "" && localRemote != "" {
			r.setRemote(localRemote)
		}
	}
	return r, nil
}
type GitRepo struct {
	base
	RemoteLocation string
}
func (s GitRepo) Vcs() Type {
	return Git
}
func (s *GitRepo) Get() error {
	out, err := s.run("git", "clone", s.Remote(), s.LocalPath())
	if err != nil && s.isUnableToCreateDir(err) {
		basePath := filepath.Dir(filepath.FromSlash(s.LocalPath()))
		if _, err := os.Stat(basePath); os.IsNotExist(err) {
			err = os.MkdirAll(basePath, 0755)
			if err != nil {
				return NewLocalError("Unable to create directory", err, "")
			}
			out, err = s.run("git", "clone", s.Remote(), s.LocalPath())
			if err != nil {
				return NewRemoteError("Unable to get repository", err, string(out))
			}
			return err
		}
	} else if err != nil {
		return NewRemoteError("Unable to get repository", err, string(out))
	}
	return nil
}
func (s *GitRepo) Init() error {
	out, err := s.run("git", "init", s.LocalPath())
	if err != nil && s.isUnableToCreateDir(err) {
		basePath := filepath.Dir(filepath.FromSlash(s.LocalPath()))
		if _, err := os.Stat(basePath); os.IsNotExist(err) {
			err = os.MkdirAll(basePath, 0755)
			if err != nil {
				return NewLocalError("Unable to initialize repository", err, "")
			}
			out, err = s.run("git", "init", s.LocalPath())
			if err != nil {
				return NewLocalError("Unable to initialize repository", err, string(out))
			}
			return nil
		}
	} else if err != nil {
		return NewLocalError("Unable to initialize repository", err, string(out))
	}
	return nil
}
func (s *GitRepo) Update() error {
	out, err := s.RunFromDir("git", "fetch", s.RemoteLocation)
	if err != nil {
		return NewRemoteError("Unable to update repository", err, string(out))
	}
	detached, err := isDetachedHead(s.LocalPath())
	if err != nil {
		return NewLocalError("Unable to update repository", err, "")
	}
	if detached == true {
		return nil
	}
	out, err = s.RunFromDir("git", "pull")
	if err != nil {
		return NewRemoteError("Unable to update repository", err, string(out))
	}
	return nil
}
func (s *GitRepo) UpdateVersion(version string) error {
	out, err := s.RunFromDir("git", "checkout", version)
	if err != nil {
		return NewLocalError("Unable to update checked out version", err, string(out))
	}
	return nil
}
func (s *GitRepo) Version() (string, error) {
	out, err := s.RunFromDir("git", "rev-parse", "HEAD")
	if err != nil {
		return "", NewLocalError("Unable to retrieve checked out version", err, string(out))
	}
	return strings.TrimSpace(string(out)), nil
}