From ab465ef07cc93782620901de1009fb732d9916ad Mon Sep 17 00:00:00 2001 From: Alex Dunmow Date: Wed, 3 Jun 2026 08:59:41 +0800 Subject: [PATCH] fix(cli): run gitignore-tracked warning before dirty-check so it fires unconditionally --- cmd/ninja/cmd/plugin.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cmd/ninja/cmd/plugin.go b/cmd/ninja/cmd/plugin.go index 9524cff..222fa42 100644 --- a/cmd/ninja/cmd/plugin.go +++ b/cmd/ninja/cmd/plugin.go @@ -298,6 +298,18 @@ func newPluginPublishCmd() *cobra.Command { return err } + // Run the tracked-yet-gitignored warning BEFORE the dirty check so + // the developer sees it even on the aborted-publish path; the spec + // asks for this warning to be unconditional. + out, _ := exec.Command("git", "ls-files", "--cached", "--ignored", "--exclude-standard").Output() + if names := strings.TrimSpace(string(out)); names != "" { + fmt.Fprintln(os.Stderr, "warning: these tracked files match .gitignore and will still be shipped:") + for _, n := range strings.Split(names, "\n") { + fmt.Fprintln(os.Stderr, " "+n) + } + fmt.Fprintln(os.Stderr, " (run `git rm --cached ` to drop)") + } + if !allowDirty { out, _ := exec.Command("git", "status", "--porcelain").Output() if len(strings.TrimSpace(string(out))) > 0 { @@ -316,15 +328,6 @@ func newPluginPublishCmd() *cobra.Command { } } - out, _ := exec.Command("git", "ls-files", "--cached", "--ignored", "--exclude-standard").Output() - if names := strings.TrimSpace(string(out)); names != "" { - fmt.Fprintln(os.Stderr, "warning: these tracked files match .gitignore and will still be shipped:") - for _, n := range strings.Split(names, "\n") { - fmt.Fprintln(os.Stderr, " "+n) - } - fmt.Fprintln(os.Stderr, " (run `git rm --cached ` to drop)") - } - // `git archive` does not recurse into submodules, so any submodule // paths will appear as empty directories in the tarball. Detect via // .gitmodules so this works even for submodules that haven't been