#!/bin/bash [ "$1" = "-h" ] && die $(cat <<-EOF Usage: subgit save [PATH..] Updates .subgitrc with current remote, branch, and commit from the bare repositories. Captures the current state of specified subrepositories (or all if none specified). EOF ) root=$(subgit-sub root .) source "$root/.subgitrc" if [ $# -eq 0 ]; then subrepos=${!subgit[@]} else subrepos=() for a in "$@"; do parent=$(dirname "$(realpath "$a")") [ "$root" != "$(subgit-sub root "$parent")" ] \ && die "Subgits do not have same parent" subrepos+=($(subgit-sub relpath "$root" "$a")) done fi for subrepo in $subrepos; do if [ ! -d "$root/.subgit/$subrepo" -o ! -d "$root/$subrepo" ]; then die "Subrepo $subrepo uninitialized" fi subgit[$subrepo]=1 subgitinfo[$subrepo/remote]=$(git -C "$root/.subgit/$subrepo" remote get-url origin) subgitinfo[$subrepo/branch]=$(git -C "$root/.subgit/$subrepo" branch --show-current) subgitinfo[$subrepo/commit]=$(git -C "$root/.subgit/$subrepo" rev-parse --verify HEAD) done source subgit-write