#!/usr/bin/env bash

pull-prompt-log() {
    local repo_path="${1:-.}"

    if [[ ! -d "$repo_path/.git" ]]; then
        echo "Error: No .git directory found in $repo_path."
        return 1
    fi

    local worktree_path="$repo_path/tmp/prompt-log"

    if [[ ! -d "$worktree_path" ]]; then
        echo "No prompt-log worktree found. Run init-prompt-log first."
        return 1
    fi

    if ! git -C "$worktree_path" rev-parse --abbrev-ref origin/prompt-log &>/dev/null; then
        echo "Remote branch origin/prompt-log does not exist."
        return 1
    fi

    git -C "$worktree_path" branch --set-upstream-to=origin/prompt-log prompt-log
    git -C "$worktree_path" pull
}
ppl() {
    pull-prompt-log "$@"
}
