feat(v0.3): run git init and ensure .gitignore for project workspaces

After Create() returns, project mode now:
  1. Runs git init (or prints "git not found; skipped..." if git
     is unavailable)
  2. Calls EnsureGitignore, which is a no-op when a seed already
     supplied .gitignore (preserving the seed-wins rule end-to-end)

Both git unavailability and git init failure are non-fatal: ctask
warns and continues, so a missing/broken git toolchain never blocks
project creation.
This commit is contained in:
2026-04-10 14:42:01 -04:00
parent 6519582de6
commit 84ca6a8d1c
+15
View File
@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/warrenronsiek/ctask/internal/config"
@@ -97,6 +98,20 @@ func runNew(cmd *cobra.Command, args []string) error {
return err
}
if newProject {
if !workspace.GitAvailable() {
fmt.Println("[ctask] git not found; skipped repository initialization")
} else {
if err := workspace.RunGitInit(ws.Path); err != nil {
fmt.Fprintf(os.Stderr, "[ctask] warning: %v\n", err)
}
}
// Seed-wins: EnsureGitignore is a no-op when a seed provided .gitignore.
if err := workspace.EnsureGitignore(ws.Path); err != nil {
fmt.Fprintf(os.Stderr, "[ctask] warning: failed to create .gitignore: %v\n", err)
}
}
relPath := workspace.RelativePath(root, ws.Path)
fmt.Printf("[ctask] created %s\n", relPath)