#!/bin/bash [ $# -eq 0 ] && die $(cat <<-EOF Usage: subgit run CMD [ARG..] Executes a command in the current subrepository context, temporarily symlinking .git to the bare repository before running the command. EOF ) root="$(subgit-sub root)" relpath=$(subgit-sub relpath "$root" .) path="$root/$relpath" if [ ! -e "$path" ]; then echo "Subgit for $path not initialized?" exit 1 fi trap 'unlink "$path/.git"' EXIT ln -sf "$repo/.subgit/$relpath" "$path/.git" "$@"