#!/usr/bin/env bash
set -euo pipefail

crate_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
repo_root="$crate_root"

if [[ -n "${LAIRU_GIT_DIR:-}" || -n "${LAIRU_WORK_TREE:-}" ]]; then
  git_dir="${LAIRU_GIT_DIR:-$repo_root/.git}"
  work_tree="${LAIRU_WORK_TREE:-$repo_root}"
  exec git --git-dir="$git_dir" --work-tree="$work_tree" "$@"
fi

exec git -C "$repo_root" "$@"
