#!/usr/bin/env bash
# git-list-local: list tracked files in the local repo
# Usage: git-list-local [repo_path]
#
# If repo_path is given, cd into it first.
# Default repo is controlled by DEFAPP env var or "defapp".

set -euo pipefail

REPO_PATH="${1:-}"
DEFAPP="${DEFAPP:-defapp}"

if [[ -n "$REPO_PATH" ]]; then
    if [[ ! -d "$REPO_PATH" ]]; then
        echo "Error: directory not found: $REPO_PATH" >&2
        exit 1
    fi
    cd "$REPO_PATH"
elif [[ -d "$DEFAPP" ]]; then
    cd "$DEFAPP"
fi

# List all tracked files in the current branch (HEAD)
git ls-tree -r HEAD --name-only
