Commit 74e68a6
Changed files (1)
cmd
cmd/init.go
@@ -15,25 +15,25 @@ import (
)
func NewInitCmd() *cobra.Command {
- var setupWorktree bool
+ var issuesDir string
var cmd = &cobra.Command{
Use: "init",
Short: "Initialize tissue issue tracking in the current repo",
Long: `Initialize tissue issue tracking by creating an orphan 'issues' branch
-with proper structure and optionally setting up a git worktree for easy access.`,
+with proper structure and setting up a git worktree for easy access.`,
RunE: func(cmd *cobra.Command, args []string) error {
- return initRunE(cmd, args, setupWorktree)
+ return initRunE(cmd, args, issuesDir)
},
}
// flags
- cmd.Flags().BoolVar(&setupWorktree, "setup-worktree", false, "Create a git worktree for the issues branch")
+ cmd.Flags().StringVar(&issuesDir, "issues-dir", "issues", "Directory name for the issues worktree (git worktree)")
return cmd
}
-func initRunE(cmd *cobra.Command, args []string, setupWorktree bool) error {
+func initRunE(cmd *cobra.Command, args []string, issuesDir string) error {
// Step 1: Open and validate repository
fmt.Println("Initializing tissue issue tracking...")
@@ -213,72 +213,68 @@ Use the tissue CLI to manage issues:
}
fmt.Printf("Returned to branch: %s\n", originalBranch.Short())
- // Step 6: Setup worktree if requested
- if setupWorktree {
- fmt.Println("Setting up git worktree...")
+ // Step 6: Setup worktree (always done)
+ fmt.Printf("Setting up git worktree at %s...\n", issuesDir)
- // TODO: Remove dependency on git CLI when go-git supports worktrees
- // Track progress: https://github.com/go-git/go-git/pull/396
- cmd := exec.Command("git", "worktree", "add", "issues", "issues")
- cmd.Stdout = os.Stdout
- cmd.Stderr = os.Stderr
- err := cmd.Run()
- if err != nil {
- return fmt.Errorf("failed to create worktree: %w\nYou can manually run: git worktree add issues issues", err)
- }
+ // TODO: Remove dependency on git CLI when go-git supports worktrees
+ // Track progress: https://github.com/go-git/go-git/pull/396
+ worktreeCmd := exec.Command("git", "worktree", "add", issuesDir, "issues")
+ worktreeCmd.Stdout = os.Stdout
+ worktreeCmd.Stderr = os.Stderr
+ err = worktreeCmd.Run()
+ if err != nil {
+ return fmt.Errorf("failed to create worktree: %w\nYou can manually run: git worktree add %s issues", err, issuesDir)
+ }
- // Add issues/ to .gitignore in main branch
- gitignoreMainPath := ".gitignore"
- var gitignoreContent []byte
+ // Add issuesDir/ to .gitignore in main branch
+ gitignoreMainPath := ".gitignore"
+ var gitignoreMainContent []byte
- // Check if .gitignore exists
- if file, err := os.Open(gitignoreMainPath); err == nil {
- defer file.Close()
- info, _ := file.Stat()
- gitignoreContent = make([]byte, info.Size())
- file.Read(gitignoreContent)
- }
+ // Check if .gitignore exists
+ if file, err := os.Open(gitignoreMainPath); err == nil {
+ defer file.Close()
+ info, _ := file.Stat()
+ gitignoreMainContent = make([]byte, info.Size())
+ file.Read(gitignoreMainContent)
+ }
- // Append issues/ if not already present
- gitignoreStr := string(gitignoreContent)
- if !contains(gitignoreStr, "issues/") {
- if len(gitignoreStr) > 0 && gitignoreStr[len(gitignoreStr)-1] != '\n' {
- gitignoreStr += "\n"
- }
- gitignoreStr += "issues/\n"
+ // Append issuesDir/ if not already present
+ gitignoreStr := string(gitignoreMainContent)
+ gitignoreEntry := issuesDir + "/"
+ if !contains(gitignoreStr, gitignoreEntry) {
+ if len(gitignoreStr) > 0 && gitignoreStr[len(gitignoreStr)-1] != '\n' {
+ gitignoreStr += "\n"
+ }
+ gitignoreStr += gitignoreEntry + "\n"
- err = os.WriteFile(gitignoreMainPath, []byte(gitignoreStr), 0644)
- if err != nil {
- return fmt.Errorf("failed to update .gitignore: %w", err)
- }
+ err = os.WriteFile(gitignoreMainPath, []byte(gitignoreStr), 0644)
+ if err != nil {
+ return fmt.Errorf("failed to update .gitignore: %w", err)
+ }
- // Stage and commit .gitignore update
- _, err = worktree.Add(gitignoreMainPath)
+ // Stage and commit .gitignore update
+ _, err = worktree.Add(gitignoreMainPath)
+ if err != nil {
+ fmt.Printf("Warning: Could not stage .gitignore: %v\n", err)
+ } else {
+ _, err = worktree.Commit(fmt.Sprintf("Add %s worktree to gitignore", issuesDir), &git.CommitOptions{
+ Author: &object.Signature{
+ Name: "Tissue CLI",
+ Email: "tissue@example.com",
+ When: time.Now(),
+ },
+ })
if err != nil {
- fmt.Printf("Warning: Could not stage .gitignore: %v\n", err)
- } else {
- _, err = worktree.Commit("Add issues worktree to gitignore", &git.CommitOptions{
- Author: &object.Signature{
- Name: "Tissue CLI",
- Email: "tissue@example.com",
- When: time.Now(),
- },
- })
- if err != nil {
- fmt.Printf("Warning: Could not commit .gitignore update: %v\n", err)
- }
+ fmt.Printf("Warning: Could not commit .gitignore update: %v\n", err)
}
}
-
- fmt.Println("Git worktree created at ./issues")
}
+ fmt.Printf("Git worktree created at ./%s\n", issuesDir)
+
fmt.Println("\n✓ Tissue initialized successfully!")
+ fmt.Printf("\nIssues directory: ./%s\n", issuesDir)
fmt.Println("\nNext steps:")
- if !setupWorktree {
- fmt.Println(" - Run 'tissue init --setup-worktree' to create a worktree")
- fmt.Println(" - Or manually: git worktree add issues issues")
- }
fmt.Println(" - Create your first issue: tissue new")
fmt.Println(" - List issues: tissue list")
fmt.Println(" - Check status: tissue status")