fix(cli): warn about untracked files when publishing with --allow-dirty

`git stash create` only captures tracked content, so a developer using
--allow-dirty after creating new files (but forgetting to `git add`)
would ship a tarball missing them with no indication. Now publish lists
the untracked, non-ignored files to stderr and suggests `git add` when
--allow-dirty is in play.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Alex Dunmow 2026-06-03 08:56:43 +08:00
parent 4c0104619e
commit c3cfa18ae0

View File

@ -303,6 +303,17 @@ func newPluginPublishCmd() *cobra.Command {
if len(strings.TrimSpace(string(out))) > 0 { if len(strings.TrimSpace(string(out))) > 0 {
return fmt.Errorf("working tree dirty; commit or pass --allow-dirty") return fmt.Errorf("working tree dirty; commit or pass --allow-dirty")
} }
} else {
// `git stash create` only captures tracked content, so untracked
// files would be silently dropped from the archive. Warn loudly.
out, _ := exec.Command("git", "ls-files", "--others", "--exclude-standard").Output()
if names := strings.TrimSpace(string(out)); names != "" {
fmt.Fprintln(os.Stderr, "warning: --allow-dirty: these untracked files will NOT be in the archive:")
for _, n := range strings.Split(names, "\n") {
fmt.Fprintln(os.Stderr, " "+n)
}
fmt.Fprintln(os.Stderr, " (run `git add <file>` if they should be shipped)")
}
} }
out, _ := exec.Command("git", "ls-files", "--cached", "--ignored", "--exclude-standard").Output() out, _ := exec.Command("git", "ls-files", "--cached", "--ignored", "--exclude-standard").Output()