From 70e9e4d42b8a344c4a68cf4bd1c7921df3067853 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 30 Jul 2024 20:57:31 -0300 Subject: Fix: rsup enhancements --- rsup | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 5 deletions(-) (limited to 'rsup') diff --git a/rsup b/rsup index d535e63..207d3d8 100755 --- a/rsup +++ b/rsup @@ -14,6 +14,46 @@ 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 if [ ! -d ".git" ]; then echo "$BASENAME: not a git repository" @@ -27,10 +67,19 @@ if [ -z "$MESSAGE" ]; then fi # Commit -commit $MESSAGE +$DIRNAME/commit $MESSAGE + +# Commit upwards until there are repositories +while true; do + # Stop on the root folder + if [ "`pwd`" == "/" ]; then + break + fi -# Go up -while test -d "../.git"; do - sup - cd .. + # Go up + if upward_commit; then + cd .. + else + break + fi done -- cgit v1.2.3