github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/genny/vcs/vcs.go (about)

     1  package vcs
     2  
     3  import (
     4  	"fmt"
     5  	"os/exec"
     6  
     7  	"github.com/gobuffalo/genny/v2"
     8  	"github.com/gobuffalo/packr/v2"
     9  )
    10  
    11  // New generator for adding VCS to an application
    12  func New(opts *Options) (*genny.Generator, error) {
    13  	g := genny.New()
    14  
    15  	if err := opts.Validate(); err != nil {
    16  		return g, err
    17  	}
    18  
    19  	if opts.Provider == "none" {
    20  		return g, nil
    21  	}
    22  
    23  	box := packr.New("buffalo:genny:vcs", "../vcs/templates")
    24  	s, err := box.FindString("ignore.tmpl")
    25  	if err != nil {
    26  		return g, err
    27  	}
    28  
    29  	p := opts.Provider
    30  	n := fmt.Sprintf(".%signore", p)
    31  	g.File(genny.NewFileS(n, s))
    32  	g.Command(exec.Command(p, "init"))
    33  
    34  	args := []string{"add", "."}
    35  	if p == "bzr" {
    36  		// Ensure Bazaar is as quiet as Git
    37  		args = append(args, "-q")
    38  	}
    39  	g.Command(exec.Command(p, args...))
    40  	g.Command(exec.Command(p, "commit", "-q", "-m", "Initial Commit"))
    41  	return g, nil
    42  }