From e82e4c0b165cbebdbfe2995d582245900ee5f6fa Mon Sep 17 00:00:00 2001 From: Stanislas Michalak Date: Thu, 15 Feb 2018 21:49:31 +0100 Subject: [PATCH] Fix Bazaar VCS behavior * Normalized keep files like in Rails (empty .gitignore => .keep) * Moved VCS as a meta app info. * Ensure Git & Bazaar are quiet on app creation. * Ensure .gitignore files are properly named for Bazaar (.bzrignore, see #901). --- buffalo/cmd/new.go | 1 - .../{dot-gitignore.tmpl => dot-keep.tmpl} | 0 generators/newapp/generator.go | 1 - generators/newapp/new.go | 28 +++++++++++++++++-- .../newapp/templates/dot-gitignore.tmpl | 14 ---------- meta/app.go | 6 ++++ 6 files changed, 32 insertions(+), 18 deletions(-) rename generators/assets/webpack/templates/public/assets/{dot-gitignore.tmpl => dot-keep.tmpl} (100%) delete mode 100644 generators/newapp/templates/dot-gitignore.tmpl diff --git a/buffalo/cmd/new.go b/buffalo/cmd/new.go index 22dd9e53a..d55e459ee 100644 --- a/buffalo/cmd/new.go +++ b/buffalo/cmd/new.go @@ -28,7 +28,6 @@ var app = newapp.Generator{ CIProvider: "none", AsWeb: true, Docker: "multi", - VCS: "git", Bootstrap: 3, } diff --git a/generators/assets/webpack/templates/public/assets/dot-gitignore.tmpl b/generators/assets/webpack/templates/public/assets/dot-keep.tmpl similarity index 100% rename from generators/assets/webpack/templates/public/assets/dot-gitignore.tmpl rename to generators/assets/webpack/templates/public/assets/dot-keep.tmpl diff --git a/generators/newapp/generator.go b/generators/newapp/generator.go index bd2c56123..dcb8b3419 100644 --- a/generators/newapp/generator.go +++ b/generators/newapp/generator.go @@ -27,7 +27,6 @@ type Generator struct { AsWeb bool `json:"as_web"` AsAPI bool `json:"as_api"` Docker string `json:"docker"` - VCS string `json:"vcs"` SkipPop bool `json:"skip_pop"` SkipWebpack bool `json:"skip_webpack"` SkipYarn bool `json:"skip_yarn"` diff --git a/generators/newapp/new.go b/generators/newapp/new.go index 750663890..18a6f908d 100644 --- a/generators/newapp/new.go +++ b/generators/newapp/new.go @@ -1,6 +1,7 @@ package newapp import ( + "fmt" "os" "os/exec" "path/filepath" @@ -97,9 +98,16 @@ func (a Generator) setupVCS(g *makr.Generator) { return } + // Create .gitignore or .bzrignore + g.Add(makr.NewFile(fmt.Sprintf(".%signore", a.VCS), nVCSIgnore)) g.Add(makr.NewCommand(exec.Command(a.VCS, "init"))) - g.Add(makr.NewCommand(exec.Command(a.VCS, "add", "."))) - g.Add(makr.NewCommand(exec.Command(a.VCS, "commit", "-m", "Initial Commit"))) + args := []string{"add", "."} + if a.VCS == "bzr" { + // Ensure Bazaar is as quiet as Git + args = append(args, "-q") + } + g.Add(makr.NewCommand(exec.Command(a.VCS, args...))) + g.Add(makr.NewCommand(exec.Command(a.VCS, "commit", "-q", "-m", "Initial Commit"))) } func (a Generator) setupDocker(root string, data makr.Data) error { @@ -332,3 +340,19 @@ test:1.8: script: - buffalo test ` + +const nVCSIgnore = `vendor/ +**/*.log +**/*.sqlite +.idea/ +bin/ +tmp/ +node_modules/ +.sass-cache/ +*-packr.go +public/assets/ +{{ .opts.Name.File }} +.vscode/ +.grifter/ +.env +` diff --git a/generators/newapp/templates/dot-gitignore.tmpl b/generators/newapp/templates/dot-gitignore.tmpl deleted file mode 100644 index ef46a1d32..000000000 --- a/generators/newapp/templates/dot-gitignore.tmpl +++ /dev/null @@ -1,14 +0,0 @@ -vendor/ -**/*.log -**/*.sqlite -.idea/ -bin/ -tmp/ -node_modules/ -.sass-cache/ -*-packr.go -public/assets/ -{{ .opts.Name.File }} -.vscode/ -.grifter/ -.env diff --git a/meta/app.go b/meta/app.go index 967f423a6..28ce18770 100644 --- a/meta/app.go +++ b/meta/app.go @@ -22,6 +22,7 @@ type App struct { ActionsPkg string `json:"actions_path"` ModelsPkg string `json:"models_path"` GriftsPkg string `json:"grifts_path"` + VCS string `json:"vcs"` WithPop bool `json:"with_pop"` WithDep bool `json:"with_dep"` WithWebpack bool `json:"with_webpack"` @@ -77,6 +78,11 @@ func New(root string) App { if _, err := os.Stat(filepath.Join(root, "grifts")); err == nil { app.WithGrifts = true } + if _, err := os.Stat(filepath.Join(root, ".git")); err == nil { + app.VCS = "git" + } else if _, err := os.Stat(filepath.Join(root, ".bzr")); err == nil { + app.VCS = "bzr" + } return app }