diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2024-08-05 20:01:48 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2024-08-05 20:01:48 -0300 |
commit | 19664d4b42fb8bfa37ef67f7224ea49a28a844ab (patch) | |
tree | ec758a648643de846717a1a6854eefe3dc927763 /rcommit | |
parent | b2bd615615eba504a04c851769e138b554b97688 (diff) | |
download | utils-git-19664d4b42fb8bfa37ef67f7224ea49a28a844ab.tar.gz utils-git-19664d4b42fb8bfa37ef67f7224ea49a28a844ab.tar.bz2 |
Fix: rename scripts to something more meaningful to others
Diffstat (limited to 'rcommit')
-rwxr-xr-x | rcommit | 89 |
1 files changed, 89 insertions, 0 deletions
@@ -0,0 +1,89 @@ +#!/bin/bash +# +# Recursively commit submodule changes +# +# Usage: +# +# From a submodule folder: +# +# sup <message> +# +# 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 |