#!/bin/bash # # Recursively commit submodule changes # # Usage: # # From a submodule folder: # # sup # # This go upwards and commit, until there's no parent repository. # Parameters DIRNAME="`dirname $0`" BASENAME="`basename $0`" MESSAGE="$*" GIT="hit" # Commit upwards function upward_commit { local level="" local up="../" local found="0" local base local log local message # Check upwards if there's a .git folder while true; do # Stop on the root folder if [ "`cd $level &> /dev/null && pwd`" == "/" ]; then break fi if [ -d "$level/.git" ]; then found="1" break fi level="${level}${up}" done # Commit in the parent repository if [ "$found" == "1" ]; then base="$(basename `pwd`)" log="`git log -1 --oneline`" message="Updates $base: $log" ( cd .. &> /dev/null && $GIT add -f $base ) cd $level && $DIRNAME/commit "$message" return 0 fi return 1 } # Check if it is a git repository # Thanks https://stackoverflow.com/questions/4917871/does-git-return-specific-return-error-codes#comment124785102_19441790 #git status &> /dev/null #if [ ! -d ".git" ]; then #if [ "$?" == "128" ]; then if [ "`git rev-parse --is-inside-work-tree &> /dev/null`" == "true" ]; then echo "$BASENAME: not a git repository" exit 1 fi # Default message if [ -z "$MESSAGE" ]; then BASE="$(basename `pwd`)" MESSAGE="Updates $BASE" fi # Commit $DIRNAME/commit $MESSAGE # Commit upwards until there are repositories while true; do # Stop on the root folder if [ "`pwd`" == "/" ]; then break fi # Go up if ! upward_commit; then break fi done