func (env *Environment) Branch() string {
	env.initBranch.Do(func() {
		env.branch = env.Run("git", "rev-parse", "--abbrev-ref", "HEAD")
	})
	return env.branch
}
Branch returns current git branch
package tdglib
import (
	"bytes"
	"log"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"sync"
)
type Environment struct {
	root        string
	branch      string
	author      string
	project     string
	initBranch  sync.Once
	initAuthor  sync.Once
	initProject sync.Once
}
func NewEnvironment(root string) *Environment {
	absolutePath, err := filepath.Abs(root)
	if err != nil {
		log.Printf("Error when setting env root: %v", err)
		absolutePath = root
	}
	env := &Environment{
		root: absolutePath,
	}
	go func() {
		log.Printf("Current root is %v", env.root)
		log.Printf("Current branch is %v", env.Branch())
		log.Printf("Current author is %v", env.Author())
		log.Printf("Current project is %v", env.Project())
	}()
	return env
}
func sliceWithoutGitDir(slice []string) []string {
	newEnv := make([]string, 0, len(slice))
	for _, s := range slice {
		if strings.HasPrefix(strings.ToUpper(s), "GIT_DIR") {
			continue
		}
		newEnv = append(newEnv, s)
	}
	return newEnv
}
func (env *Environment) Run(cmd string, arg ...string) string {
	command := exec.Command(cmd, arg...)
	command.Dir = env.root
	command.Env = sliceWithoutGitDir(os.Environ())
	var stdout, stderr bytes.Buffer
	command.Stdout = &stdout
	command.Stderr = &stderr
	err := command.Run()
	if err != nil {
		log.Printf("Command run error: %s", err)
		log.Printf("Command stderr: %s", string(stderr.Bytes()))
		return ""
	}
	outStr := string(stdout.Bytes())
	return strings.TrimSpace(outStr)
}