commit 9e061dd61e74d88f8513bba3436f2875ea3cba44
parent 39b670765b1f338590eba931989a8176cd1b677e
Author: lash <dev@holbrook.no>
Date: Sun, 31 Jul 2022 08:57:00 +0000
Add bdbg debugging to gitrefresh command, enable bare repo fetches
Diffstat:
5 files changed, 162 insertions(+), 19 deletions(-)
diff --git a/bdbg.sh b/bdbg.sh
@@ -1,6 +1,23 @@
-if [ -z "$_level" ]; then
- _level=3
-fi
+# This script normally lives in https://git.defalsify.org/bashbdbg
+# Licenced under Do What The Fuck You Want Licence v2
+# (c) 2021-2022 by lash
+
+bdbg_check_env_level() {
+ if [ -z "$BDBG_LEVEL" ]; then
+ _level=3
+ else
+ _level=$BDBG_LEVEL
+ fi
+}
+
+bdbg_check_env_toggle() {
+ if [ ! -z "$BDBG" ]; then
+ if [ "$BDBG" -gt "0" ]; then
+ _debug=1
+ fi
+ fi
+}
+
dbg() {
if [ "$1" -lt "$_level" ]; then
@@ -33,3 +50,13 @@ dbg() {
fi
>&2 echo -e "$clr$(printf %-9s [$lvl])$2\e[0m"
}
+
+bdbg() {
+ if [ -z "$_level" ]; then
+ bdbg_check_env_level
+ fi
+
+ if [ -z "$_debug" ]; then
+ bdbg_check_env_toggle
+ fi
+}
diff --git a/gitlist.sh b/gitlist.sh
@@ -94,7 +94,6 @@ for d in $(find . -type d -not -name ".git"); do
used=''
fi
fi
-
pushd "$d" > /dev/null
if [ $(git rev-parse HEAD 2> /dev/null) ]; then
used=$d
diff --git a/gitrefresh.sh b/gitrefresh.sh
@@ -1,5 +1,55 @@
#!/bin/bash
+bdbg_check_env_level() {
+ if [ ! -z "$BDBG_LEVEL" ]; then
+ _level=$BDBG_LEVEL
+ fi
+}
+
+bdbg_check_env_toggle() {
+ if [ ! -z "$BDBG" ]; then
+ if [ "$BDBG" -gt "0" ]; then
+ _debug=1
+ fi
+ fi
+}
+
+
+dbg() {
+ if [ "$1" -lt "$_level" ]; then
+ return 0
+ fi
+
+ case "$1" in
+ 1)
+ lvl='debug'
+ clr='\e[0;96m'
+ ;;
+ 2)
+ lvl='info'
+ clr='\e[0;92m'
+ ;;
+
+ 3)
+ lvl='warn'
+ clr='\e[0;93m'
+ ;;
+ 4)
+ lvl='error'
+ clr='\e[0;91m'
+ ;;
+
+ esac
+
+ if [ -z $_debug ]; then
+ return 0
+ fi
+ >&2 echo -e "$clr$(printf %-9s [$lvl])$2\e[0m"
+}
+
+bdbg_check_env_level
+bdbg_check_env_toggle
+
wd=${2:-.}
if [ ! -d $wd ]; then
>&2 echo $wd is not a directory
@@ -33,7 +83,33 @@ case "$cmd" in
exit 1
break
esac
-#echo using repo dir $(realpath $t)
+
+
+repo_fetch_checkout() {
+ git fetch > /dev/null 2>&1
+ if [ "$?" -gt "0" ]; then
+ dbg 4 "fetch heads failed in $(pwd)"
+ return 1
+ fi
+ if [ ! -z "$_pull" ]; then
+ #branch=`git branch --show-current`
+ branch=`git rev-parse --abbrev-ref HEAD`
+ git pull --ff-only origin $branch > /dev/null 2>&1
+ fi
+}
+
+repo_fetch_bare() {
+ git fetch origin 'refs/heads/*:refs/heads/*' > /dev/null 2>&1
+ if [ "$?" -gt "0" ]; then
+ >&2 echo "fetch heads failed in $(pwd)"
+ return 1
+ fi
+ git fetch origin 'refs/tags/*:refs/tags/*' > /dev/null 2>&1
+ if [ "$?" -gt "0" ]; then
+ >&2 echo "fetch heads failed in $(pwd)"
+ return 1
+ fi
+}
repo_update() {
#>&2 echo updating `pwd`
@@ -46,15 +122,12 @@ repo_update() {
>&2 echo "remote update failed in $(pwd)"
return 1
fi
- git fetch > /dev/null 2>&1
- if [ "$?" -gt "0" ]; then
- >&2 echo "fetch failed in $(pwd)"
- return 1
- fi
- if [ ! -z "$_pull" ]; then
- #branch=`git branch --show-current`
- branch=`git rev-parse --abbrev-ref HEAD`
- git pull --ff-only origin $branch > /dev/null 2>&1
+ if [ -d ".git" ]; then
+ dbg 2 "updating work repo $remote -> $(pwd)"
+ repo_fetch_checkout
+ else
+ dbg 2 "updating bare repo $remote -> $(pwd)"
+ repo_fetch_bare
fi
}
@@ -66,15 +139,17 @@ repo_init() {
_IFS=$IFS
IFS=$'\n'
for gr in ${gf[@]}; do
- echo adding remote $gr
+ dbg 2 adding remote $gr
echo $gr | tr "\t" " " | xargs git remote add
done
IFS=$_IFS
popd
}
+p=$(realpath $p)
scan() {
- #echo entering $d parent $p
+ dd=$(realpath $d)
+ dbg 1 "entering $dd, parent $p"
pushd "$d" > /dev/null
if [ "$?" -ne "0" ]; then
p=`dirname $p`
diff --git a/tests/test_list.sh b/tests/test_list.sh
@@ -5,9 +5,9 @@ if [ ! -f ./gitrefresh.sh ]; then
exit 1;
fi
-ts=$(mktemp -d)
-td=$(mktemp -d)
-r=$(mktemp)
+export ts=$(mktemp -d)
+export td=$(mktemp -d)
+export r=$(mktemp)
pushd $ts
ds=(a b c)
diff --git a/tests/test_list_add.sh b/tests/test_list_add.sh
@@ -0,0 +1,42 @@
+. tests/test_list.sh
+
+bash ./gitrefresh.sh update $td
+
+>&2 echo have td=$td ts=$rs r=$r from source
+
+pushd $ts
+
+d="d"
+mkdir -v $d
+pushd $d
+git init
+uuidgen > data.txt
+git add data.txt
+git commit -m "initial commit"
+popd
+pushd $td
+repo="file://$ts/$d"
+echo $repo >> $r
+git clone $repo
+popd
+
+hl=$(mktemp)
+hr=$(mktemp)
+pushd a
+uuidgen > data.txt
+git commit -a -m "more commit"
+git rev-parse HEAD >> $hl
+git rev-parse HEAD >> $hr
+popd
+
+popd
+
+vr=$(mktemp)
+vl=$(mktemp)
+sort $r > $vr
+
+bash ./gitlist.sh $td | sort > $vl
+diff $vr $vl
+
+bash ./gitrefresh.sh update $td
+diff $hl $hr