func (v VcsHandle) DebugCommits() commitlater.List {
	return *v.toCommit
}
DebugCommits dumps the list of future commits.
package git
import (
	"fmt"
	"path/filepath"
	"strings"
	"github.com/StackExchange/blackbox/v2/pkg/bbutil"
	"github.com/StackExchange/blackbox/v2/pkg/commitlater"
	"github.com/StackExchange/blackbox/v2/pkg/makesafe"
	"github.com/StackExchange/blackbox/v2/pkg/vcs"
)
var pluginName = "GIT"
func init() {
	vcs.Register(pluginName, 100, newGit)
}
type VcsHandle struct {
	commitTitle         string
	commitHeaderPrinted bool               
	toCommit            *commitlater.List  
}
func newGit() (vcs.Vcs, error) {
	l := &commitlater.List{}
	return &VcsHandle{toCommit: l}, nil
}
func (v VcsHandle) Name() string {
	return pluginName
}
func ultimate(s string) int { return len(s) - 1 }
func (v VcsHandle) Discover() (bool, string) {
	out, err := bbutil.RunBashOutputSilent("git", "rev-parse", "--show-toplevel")
	if err != nil {
		return false, ""
	}
	if out == "" {
		fmt.Printf("WARNING: git rev-parse --show-toplevel has NO output??.  Seems broken.")
		return false, ""
	}
	if out[ultimate(out)] == '\n' {
		out = out[0:ultimate(out)]
	}
	return err == nil, out
}
func (v VcsHandle) SetFileTypeUnix(repobasedir string, files ...string) error {
	seen := make(map[string]bool)
	for _, file := range files {
		d, n := filepath.Split(file)
		af := filepath.Join(repobasedir, d, ".gitattributes")
		err := bbutil.Touch(af)
		if err != nil {
			return err
		}
		err = bbutil.AddLinesToFile(af, fmt.Sprintf("%q text eol=lf", n))
		if err != nil {
			return err
		}
		seen[af] = true
	}
	var changedfiles []string
	for k := range seen {
		changedfiles = append(changedfiles, k)
	}
	v.NeedsCommit(
		"set gitattr=UNIX "+strings.Join(makesafe.RedactMany(files), " "),
		repobasedir,
		changedfiles,
	)
	return nil
}
func (v VcsHandle) IgnoreAnywhere(repobasedir string, files []string) error {
	ignore := filepath.Join(repobasedir, ".gitignore")
	err := bbutil.Touch(ignore)
	if err != nil {
		return err
	}
	err = bbutil.AddLinesToFile(ignore, files...)
	if err != nil {
		return err
	}
	v.NeedsCommit(
		"gitignore "+strings.Join(makesafe.RedactMany(files), " "),
		repobasedir,
		[]string{".gitignore"},
	)
	return nil
}
func gitSafeFilename(name string) string {
	if name == "" {
		return "ERROR"
	}
	var b strings.Builder
	b.Grow(len(name) + 2)
	for _, r := range name {
		if r == ' ' || r == '*' || r == '?' || r == '[' || r == ']' {
			b.WriteRune('\\')
			b.WriteRune(r)
		} else {
			b.WriteRune(r)
		}
	}
	if name[0] == '!' || name[0] == '#' {
		return `\` + b.String()
	}
	return b.String()
}
func (v VcsHandle) IgnoreFiles(repobasedir string, files []string) error {
	var lines []string
	for _, f := range files {
		lines = append(lines, "/"+gitSafeFilename(f))
	}
	ignore := filepath.Join(repobasedir, ".gitignore")
	err := bbutil.Touch(ignore)
	if err != nil {
		return err
	}
	err = bbutil.AddLinesToFile(ignore, lines...)
	if err != nil {
		return err
	}
	v.NeedsCommit(
		"gitignore "+strings.Join(makesafe.RedactMany(files), " "),
		repobasedir,
		[]string{".gitignore"},
	)
	return nil
}
func (v VcsHandle) Add(repobasedir string, files []string) error {
	if len(files) == 0 {
		return nil
	}
	var gpgnames []string
	for _, n := range files {
		gpgnames = append(gpgnames, n+".gpg")
	}
	return bbutil.RunBash("git", append([]string{"add"}, gpgnames...)...)
}
func (v *VcsHandle) CommitTitle(title string) {
	v.commitTitle = title
}
func (v *VcsHandle) NeedsCommit(message string, repobasedir string, names []string) {
	v.toCommit.Add(message, repobasedir, names)
}