]> gitweb.fluxo.info Git - utils-git.git/commitdiff
Fix: rsup enhancements
authorSilvio Rhatto <rhatto@riseup.net>
Tue, 30 Jul 2024 23:57:31 +0000 (20:57 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Tue, 30 Jul 2024 23:57:31 +0000 (20:57 -0300)
rsup

diff --git a/rsup b/rsup
index d535e636f80d8c612497ade00e1604d1a140a811..207d3d869427096f86f07d715115a5327bed2be7 100755 (executable)
--- 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