#!/bin/bash # Checks whether the branch / commit tracked by subgit for the # specified repos are up-to-date, and whether the worktree is dirty. usage() { die $(cat <<-EOF Usage: subgit check [PATH..] Checks whether tracked subrepositories have uncommitted changes, or if their remote, branch, or commit differ from what's recorded in .subgitrc. Reports any discrepancies or dirty working trees. EOF ) } while [ "$1" ]; do case $1 in -h) usage;; --) shift; break;; -*) die "Invalid option $1";; *) break;; esac done subgit-sub subrepo "$@" | while read -r subrepo; do root=$(subgit-sub parent "$subrepo") relpath=$(realpath -m --relative-to="$root" "$subrepo") source "$root/.subgitrc" bare="$root/.subgit/$relpath" if [ ! -d "$bare" ]; then warn "Subrepo $relpath uninitialized" continue fi remote=$(git -C "$bare" remote get-url origin) if [ "${subgitinfo[$relpath/remote]}" != "$remote" ]; then echo "$relpath: new remote - '$remote'" fi branch=$(git -C "$bare" branch --show-current) if [ ! -z "${subgitinfo[$relpath/branch]}" ] && [ "${subgitinfo[$relpath/branch]}" != "$branch" ]; then echo "$relpath: new branch - '$branch'" fi commit=$(git -C "$bare" rev-parse --verify HEAD) if [ "${subgitinfo[$relpath/commit]}" != "$commit" ]; then echo "$relpath: new commit - '$commit'" fi dirty=$(git -C "$subrepo" diff --stat 2>/dev/null | head -n1) if [ ! -z "$dirty" ]; then echo "$relpath: dirty tree" fi done