issues
Raw Download raw file

id: 001 title: Implement init command status: completed type: feature created: 2025-09-24

Implement init command

Description

Implement the tissue init command to initialize issue tracking in a git repository. This command creates an orphan “issues” branch, sets up the proper directory structure, and optionally configures a git worktree for easy access.

Implementation Tasks

  • Update go.mod with go-git dependencies

    • Add github.com/go-git/go-git/v5
    • Add github.com/go-git/go-billy/v5
  • Implement repository validation

    • Open repository with git.PlainOpen(".")
    • Verify it’s a valid git repository
    • Check if issues branch already exists
  • Create orphan “issues” branch

    • Store current branch reference to return later
    • Create orphan branch using plumbing.NewSymbolicReference
    • Set HEAD to point to new orphan branch
    • FIXED: Clear index and working directory to ensure true orphan
  • Initialize branch structure

    • Create README.md with issue tracker description
    • Create .gitignore (ignore everything except markdown files)
    • Stage files with worktree.Add()
    • Commit as first commit on orphan branch
  • Handle remote operations

    • Check for origin remote
    • Push issues branch if remote exists
    • Handle push failures gracefully
  • Return to original branch

    • Checkout back to the branch stored at start
  • UPDATED: Implement automatic worktree setup with –issues-dir flag

    • Always create worktree (no longer optional)
    • Replace --setup-worktree with --issues-dir <dir> flag
    • Default to ./issues if flag not provided
    • Use os/exec to run git worktree add <dir> issues
    • Add <dir>/ to main branch .gitignore
    • Commit .gitignore update
  • ADDED: Support custom branch name with –issues-branch flag

    • Added --issues-branch flag for custom branch name
    • Default to issues branch
    • Use constants _issuesBranchDefault and _issuesDirDefault
    • All branch references use the variable
  • Error handling

    • Clear error messages for each failure case
    • Handle bare repositories appropriately
    • Validate operations at each step
    • UPDATED: Refactored to follow Go error style guide
  • User feedback

    • Progress messages for each operation
    • Success confirmation
    • Instructions for next steps
  • TODO: Use git-configured user for commits

    • Read user.name and user.email from git config
    • If not configured, prompt user (like git does)
    • Don’t hardcode “Tissue CLI” as author

Technical Notes

Acceptance Criteria

  1. Command creates orphan “issues” branch successfully
  2. Branch contains README.md and .gitignore
  3. UPDATED: Worktree is automatically created (no longer optional)
  4. UPDATED: –issues-dir flag allows custom directory name (defaults to ./issues)
  5. Proper error handling for edge cases
  6. Clear user feedback throughout process
  7. Returns to original branch after completion

Problems Encountered

Problem 1: Orphan branch not truly orphan

Fixed: The created “issues” branch was not truly orphan - it had parent commits and shared history with the main branch. Solution was to clear the index and working directory before committing.

Status

Completed:

  • ✅ Creates a truly orphan branch (no parent commits)
  • ✅ Initializes branch with README.md and .gitignore
  • ✅ Automatically sets up git worktree
  • --issues-dir flag allows custom directory (defaults to ./issues)
  • --issues-branch flag allows custom branch name (defaults to issues)
  • ✅ Pushes to remote if available
  • ✅ Returns to original branch after completion
  • ✅ Clear error messages and user feedback

Remaining:

  • None - see issue #003 for git user config enhancement