gitrefresh

Easily export, reinitialize and update all git repositories in a file hierarchy
git clone git://git.defalsify.org/gitrefresh.git
Log | Files | Refs | README | LICENSE

commit bad6c754fa8c479caaea1e9c78310e4fd327fb9a
parent c4eb2c477d52a8fc86d3411ca1a580d172dc1bcf
Author: lash <dev@holbrook.no>
Date:   Sat,  8 Jun 2024 03:56:03 +0100

Add description scraper

Diffstat:
Agitmeta.sh | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+), 0 deletions(-)

diff --git a/gitmeta.sh b/gitmeta.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +nocontent_sha256="85ab6c163d43a17ea9cf7788308bca1466f1b0a8d1cc92e26e9bf63da4062aee" +localdir=$HOME/.local/share/gitdesc + +_level=3 +while test $# != 0; do + case "$1" in + -v) + _debug=1 + shift + _level=$1 + shift + ;; + *) + break + ;; + esac +done + +dbg() { + if [ "$1" -lt "$_level" ]; then + return 0 + fi + + case "$1" in + 1) + lvl='debug' + clr='\e[0;36m' + ;; + 2) + lvl='info' + clr='\e[0;32m' + ;; + + 3) + lvl='warn' + clr='\e[0;33m' + ;; + 4) + lvl='error' + clr='\e[0;31m' + ;; + + esac + + if [ -z $_debug ]; then + return 0 + fi + >&2 echo -e "$clr$(printf %-9s [$lvl])$2\e[0m" +} +wd=${1:-`pwd`} +wd=$(realpath $wd) + +_IFS=$IFS +IFS=$(echo -en "\n\b") +used='' +pushd "$wd" > /dev/null +if [ "$?" -gt "0" ]; then + exit 1 +fi + +for d in $(find . -type d -not -name ".git"); do + if [ ! -z $used ]; then + if [[ "$d" =~ ^$used ]]; then + dbg 1 "still in repo, skipping $d" + continue + else + used='' + fi + fi + pushd "$d" > /dev/null + if [ $(git rev-parse HEAD 2> /dev/null) ]; then + used=$d + dbg 2 "found repo $d" + dsc="description" + if [ -d .git ]; then + dsc=.git/description + fi + h=$(sha256sum $dsc | awk '{ print $1; }') + if [ "$h" != $nocontent_sha256 ]; then + if [ -f $localdir/$h ]; then + dbg 2 "already have $d ($h)" + else + cp -v $dsc $localdir/$h + fi + fi + fi + popd > /dev/null +done +popd > /dev/null