Commit 11c5888
Changed files (1)
cmd
cmd/init.go
@@ -72,7 +72,34 @@ func initRunE(cmd *cobra.Command, args []string, setupWorktree bool) error {
return fmt.Errorf("failed to get worktree: %w", err)
}
- // Clear the working directory for orphan branch
+ // Clear the index and working directory for orphan branch
+ // This is essential to create a true orphan branch with no parent commits
+ fmt.Println("Clearing working directory for orphan branch...")
+
+ // Get the status to find all tracked files
+ status, err := worktree.Status()
+ if err != nil {
+ return fmt.Errorf("failed to get worktree status: %w", err)
+ }
+
+ // Remove all files from both the index and working directory
+ for filepath := range status {
+ _, err := worktree.Remove(filepath)
+ if err != nil {
+ // Continue even if some files fail to be removed
+ fmt.Printf("Warning: could not remove %s: %v\n", filepath, err)
+ }
+ // Also physically delete the file from disk
+ os.Remove(filepath)
+ }
+
+ // Use RemoveGlob as a fallback to ensure everything is cleared
+ err = worktree.RemoveGlob("*")
+ if err != nil && err != git.ErrGlobNoMatches {
+ fmt.Printf("Warning: RemoveGlob failed: %v\n", err)
+ }
+
+ // Now we have a clean slate for the orphan branch
fs := osfs.New(".")
// Create README.md