From 19664d4b42fb8bfa37ef67f7224ea49a28a844ab Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Mon, 5 Aug 2024 20:01:48 -0300 Subject: Fix: rename scripts to something more meaningful to others --- rcommit | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 rcommit (limited to 'rcommit') diff --git a/rcommit b/rcommit new file mode 100755 index 0000000..59d95d0 --- /dev/null +++ b/rcommit @@ -0,0 +1,89 @@ +#!/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 -- cgit v1.2.3