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 --- commit | 6 ++--- hit | 2 +- rcommit | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rsup | 89 ----------------------------------------------------------------- scommit | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sup | 85 +------------------------------------------------------------- 6 files changed, 177 insertions(+), 177 deletions(-) create mode 100755 rcommit delete mode 100755 rsup create mode 100755 scommit mode change 100755 => 120000 sup diff --git a/commit b/commit index d16fc81..d099d00 100755 --- a/commit +++ b/commit @@ -55,7 +55,7 @@ function is_git { return else ( cd "$1" && $GIT status &> /dev/null ) - + if [ "$?" != "128" ]; then return else @@ -68,13 +68,13 @@ function is_git { function is_svn { # simple svn folder checker # usage: is_svn - + if [ -d "$1/.svn" ]; then return else return 1 fi -} +} # Push to repositories function git_push { diff --git a/hit b/hit index 2a30ba5..568ea45 100755 --- a/hit +++ b/hit @@ -12,7 +12,7 @@ # * Check proper user/email config. # * Automatically set git-flow when initializing a repository. # * Automatically set git-hooks integration. -# * Allow hook whitelisting. +# * Allow for hook access control list (i.e, which hooks are allowed). # * Implement global hooks like using a global init.templateDir config. # * Check remote configuration. # * Check hook tampering before doing anything in the repository, like removing hook permissions. 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 diff --git a/rsup b/rsup deleted file mode 100755 index 59d95d0..0000000 --- a/rsup +++ /dev/null @@ -1,89 +0,0 @@ -#!/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 diff --git a/scommit b/scommit new file mode 100755 index 0000000..2c1606a --- /dev/null +++ b/scommit @@ -0,0 +1,83 @@ +#!/bin/bash +# +# Commit submodule changes +# +# Usage: +# +# 1. From a submodule folder: +# +# scommit # go the upward repo and commit +# +# 2. From the top-level git repo: +# +# scommit +# +# Usage in an alternative design: +# +# 1. From a submodule folder: +# +# scommit # go the upward repo and commit +# +# 2. From the top-level git repo: +# +# scommit # detect changed submodules +# scommit [..] + +# Parameters +DIRNAME="`dirname $0`" +BASENAME="`basename $0`" +PROJECT="$1" +GIT="hit" + +# Check each file at the the submodule registry +#function sup_registry { +# $GIT status --short | grep -v "??" | awk '{ print $2 }' | while read module; do +# if grep -q "\[submodule \"$module\"\]" .gitmodules; then +# true +# fi +# done +#} + +# Check if it is a git repository, and wheter we're in the top of it +if [ ! -d ".git" ]; then + echo "$BASENAME: not a git repository, or not in the top-level of that repository" + exit 1 +fi + +# Remove trailing slash from project name +PROJECT="`echo "$PROJECT" | sed -e 's|/$||'`" + +# Check if param is a project +if [ ! -z "$PROJECT" ]; then + # Check if project is a registered submodule + if ! grep -q "\[submodule \"$PROJECT\"\]" .gitmodules; then + echo "$BASENAME: not a submodule: $PROJECT" + exit 1 + fi + + # Check if it has changes to be commited + #if ! $GIT status --short $PROJECT | grep -q "^[AM]"; then + # echo "$BASENAME: not changes to be commited for $PROJECT" + # exit 1 + #fi + + # Work with cached version only + #COMMIT="`$GIT diff --cached $PROJECT | grep '^\+Subproject commit ' | cut -d ' ' -f 3`" + #LOG="`cd $PROJECT &> /dev/null && git log -1 --oneline $COMMIT`" + + # Always work with the latest commit + $GIT add $PROJECT + LOG="`cd $PROJECT &> /dev/null && git log -1 --oneline`" + + MESSAGE="Updates $PROJECT: $LOG" + $DIRNAME/commit $MESSAGE +else + # Get log + LOG="`git log -1 --oneline`" + BASE="$(basename `pwd`)" + MESSAGE="Updates $BASE: $LOG" + + # Got upward and commit + #( cd .. &> /dev/null && $GIT add $BASE && $DIRNAME/commit "$MESSAGE" ) + ( cd .. &> /dev/null && $GIT add -f $BASE && $DIRNAME/commit "$MESSAGE" ) +fi diff --git a/sup b/sup deleted file mode 100755 index 842ad5a..0000000 --- a/sup +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash -# -# Commit submodule changes -# -# Usage: -# -# 1. From a submodule folder: -# -# sup # go the upward repo and commit -# -# 2. From the top-level git repo: -# -# sup -# -# Usage in an alternative design: -# -# 1. From a submodule folder: -# -# sup # go the upward repo and commit -# -# 2. From the top-level git repo: -# -# sup # detect changed submodules -# sup [..] -# - -# Parameters -DIRNAME="`dirname $0`" -BASENAME="`basename $0`" -PROJECT="$1" -GIT="hit" - -# Check each file at the the submodule registry -#function sup_registry { -# $GIT status --short | grep -v "??" | awk '{ print $2 }' | while read module; do -# if grep -q "\[submodule \"$module\"\]" .gitmodules; then -# true -# fi -# done -#} - -# Check if it is a git repository, and wheter we're in the top of it -if [ ! -d ".git" ]; then - echo "$BASENAME: not a git repository, or not in the top-level of that repository" - exit 1 -fi - -# Remove trailing slash from project name -PROJECT="`echo "$PROJECT" | sed -e 's|/$||'`" - -# Check if param is a project -if [ ! -z "$PROJECT" ]; then - # Check if project is a registered submodule - if ! grep -q "\[submodule \"$PROJECT\"\]" .gitmodules; then - echo "$BASENAME: not a submodule: $PROJECT" - exit 1 - fi - - # Check if it has changes to be commited - #if ! $GIT status --short $PROJECT | grep -q "^[AM]"; then - # echo "$BASENAME: not changes to be commited for $PROJECT" - # exit 1 - #fi - - # Work with cached version only - #COMMIT="`$GIT diff --cached $PROJECT | grep '^\+Subproject commit ' | cut -d ' ' -f 3`" - #LOG="`cd $PROJECT &> /dev/null && git log -1 --oneline $COMMIT`" - - # Always work with the latest commit - $GIT add $PROJECT - LOG="`cd $PROJECT &> /dev/null && git log -1 --oneline`" - - MESSAGE="Updates $PROJECT: $LOG" - $DIRNAME/commit $MESSAGE -else - # Get log - LOG="`git log -1 --oneline`" - BASE="$(basename `pwd`)" - MESSAGE="Updates $BASE: $LOG" - - # Got upward and commit - #( cd .. &> /dev/null && $GIT add $BASE && $DIRNAME/commit "$MESSAGE" ) - ( cd .. &> /dev/null && $GIT add -f $BASE && $DIRNAME/commit "$MESSAGE" ) -fi diff --git a/sup b/sup new file mode 120000 index 0000000..8832612 --- /dev/null +++ b/sup @@ -0,0 +1 @@ +scommit \ No newline at end of file -- cgit v1.2.3