Skip to content

Conversation

webjunkie
Copy link
Contributor

@webjunkie webjunkie commented Oct 14, 2025

Summary

  • Adds optional --dir <dirname> parameter to create, checkout, and pr commands
  • Decouples worktree directory names from branch names
  • Enables theme-based workflows where multiple related branches can be worked on in the same worktree

Motivation

Previously, worktree folder names were always tied to branch names (1:1 relationship). For multi-PR workflows around a theme, this meant creating new worktrees for each branch, losing context and setup.

With --dir, you can:

posthog-worktree create first-feature --dir auth-theme
cd ~/.worktrees/posthog/auth-theme
# work, commit, create PR

git checkout -b second-feature
# work on related feature in same worktree, maintaining Claude context

Changes

  • Rewrote argument parsing to support --dir flag alongside positional args
  • Updated create_worktree(), checkout_worktree(), and checkout_pr_worktree() to use custom dirname when provided
  • Updated help text with examples
  • remove command unchanged (already finds worktrees by branch name)

Test plan

  • Tested create with --dir flag
  • Verified worktree created at custom path with correct branch
  • Test checkout with --dir
  • Test pr with --dir
  • Test that existing workflows without --dir still work

Adds optional --dir parameter to create, checkout, and pr commands. Enables theme-based workflows where multiple related branches can be worked on in the same worktree directory while maintaining separate branch names.

Previously, worktree folder names were always tied to branch names, forcing a 1:1 relationship. Now you can specify a custom directory name that persists across branch switches within that worktree.
@webjunkie webjunkie marked this pull request as ready for review October 14, 2025 07:55
@webjunkie webjunkie requested a review from haacked October 14, 2025 07:55
@posthog-project-board-bot posthog-project-board-bot bot moved this to In Review in Feature Flags Oct 14, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines 17 to 33
while [[ $# -gt 0 ]]; do
case $1 in
--dir)
CUSTOM_DIR="$2"
shift 2
;;
*)
# First non-flag arg is branch name, second is base branch
if [[ -z "$BRANCH_NAME" ]]; then
BRANCH_NAME="$1"
elif [[ "$BASE_BRANCH" == "master" ]]; then
BASE_BRANCH="$1"
fi
shift
;;
esac
done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: argument parsing bug: --dir requires an argument but doesn't validate that $2 exists before using it. If user runs posthog-worktree create my-branch --dir, the script will set CUSTOM_DIR="" and then shift 2 will fail or consume the next argument incorrectly.

Suggested change
while [[ $# -gt 0 ]]; do
case $1 in
--dir)
CUSTOM_DIR="$2"
shift 2
;;
*)
# First non-flag arg is branch name, second is base branch
if [[ -z "$BRANCH_NAME" ]]; then
BRANCH_NAME="$1"
elif [[ "$BASE_BRANCH" == "master" ]]; then
BASE_BRANCH="$1"
fi
shift
;;
esac
done
while [[ $# -gt 0 ]]; do
case $1 in
--dir)
if [[ -z "$2" ]]; then
error "Missing argument for --dir flag"
exit 1
fi
CUSTOM_DIR="$2"
shift 2
;;
*)
# First non-flag arg is branch name, second is base branch
if [[ -z "$BRANCH_NAME" ]]; then
BRANCH_NAME="$1"
elif [[ "$BASE_BRANCH" == "master" ]]; then
BASE_BRANCH="$1"
fi
shift
;;
esac
done
Prompt To Fix With AI
This is a comment left during a code review.
Path: bin/posthog-worktree
Line: 17:33

Comment:
**logic:** argument parsing bug: `--dir` requires an argument but doesn't validate that `$2` exists before using it. If user runs `posthog-worktree create my-branch --dir`, the script will set `CUSTOM_DIR=""` and then `shift 2` will fail or consume the next argument incorrectly.

```suggestion
while [[ $# -gt 0 ]]; do
    case $1 in
        --dir)
            if [[ -z "$2" ]]; then
                error "Missing argument for --dir flag"
                exit 1
            fi
            CUSTOM_DIR="$2"
            shift 2
            ;;
        *)
            # First non-flag arg is branch name, second is base branch
            if [[ -z "$BRANCH_NAME" ]]; then
                BRANCH_NAME="$1"
            elif [[ "$BASE_BRANCH" == "master" ]]; then
                BASE_BRANCH="$1"
            fi
            shift
            ;;
    esac
done
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems legit.

Copy link
Contributor

github-actions bot commented Oct 14, 2025

Size Change: 0 B

Total Size: 3.05 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 3.05 MB

compressed-size-action

Copy link
Contributor

@haacked haacked left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I think the issue that Greptile points out is legit, but not a blocker.

@github-project-automation github-project-automation bot moved this from In Review to Approved in Feature Flags Oct 14, 2025
Adds validation to ensure --dir flag receives an argument. Prevents errors when --dir is used without a value.
@webjunkie webjunkie enabled auto-merge (squash) October 15, 2025 08:54
@webjunkie webjunkie merged commit 5077e3f into master Oct 15, 2025
108 of 109 checks passed
@webjunkie webjunkie deleted the fix/posthog-worktree branch October 15, 2025 08:57
@github-project-automation github-project-automation bot moved this from Approved to Done in Feature Flags Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants