added several usefull meta commands...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-09-07 14:11:26 +03:00
parent 37ad629ddd
commit f7793c80d4
4 changed files with 217 additions and 27 deletions

84
bin/git-cloneall Executable file
View File

@ -0,0 +1,84 @@
#!/usr/bin/env bash
while true ; do
case $1 in
-h|--help)
echo "Usage: $(basename "$0") [OPTIONS] FILE [PATH]"
echo
echo "Clone all repositories from lst (FILE)."
echo
echo "Options:"
echo " -h --help - print this message and exit"
echo
echo "Repository list can be constructed from an existing set of"
echo "repositories via:"
echo " $ git remotes > reposiotry.lst"
echo "or recursively:"
echo " $ git remotes -r > reposiotry.lst"
echo
echo "The repository list is a text file with each line consisting"
echo "of a space-separated path and a remote url (as supported by"
echo "git clone)."
echo "The list file can also contain empty lines and supports shell"
echo "comments (lines starting with \"#\")"
echo
exit
;;
-*|--*)
echo "Error: unknown option: \"$1\"" >&2
exit
;;
*)
LIST=$1
TARGET_PATH=$2
break
;;
esac
done
TARGET_PATH=${TARGET_PATH:=.}
cd "$TARGET_PATH"
if [ -z $LIST ] ; then
echo "need a list file..." >&2
exit 1
fi
IFS=$'\n' \
LIST=($(cat "$LIST"))
wd=`pwd`
for repo in ${LIST[@]} ; do
repo=`xargs<<<"${repo}"`
# skip comments and empty lines...
if [ -z "$repo" ] || [[ "${repo}" =~ ^# ]] ; then
continue
fi
IFS=$' ' \
repo=($repo)
# skip existing dirs...
if [ -e "${repo[0]}" ] ; then
#echo "skipping: ${repo[0]}"
continue
fi
mkdir -p "${repo[0]}"
cd "${repo[0]}"
git clone ${repo[1]} "${repo[0]}"
cd "$wd"
done
# vim:set sw=4 ts=4 :

58
bin/git-listall Executable file
View File

@ -0,0 +1,58 @@
#!/usr/bin/env bash
while true ; do
case $1 in
-h|--help)
echo "Usage: $(basename "$0") [OPTIONS] [PATH]"
echo
echo "List all repositories in PATH."
echo
echo "Options:"
echo " -h --help - print this message and exit"
echo " -r --recursive - pull directories recursively"
echo
exit
;;
-r|--recursive)
RECURSIVE=1
shift
continue
;;
-*|--*)
echo "Error: unknown option: \"$1\"" >&2
exit
;;
*)
TARGET_PATH=$1
break
;;
esac
done
TARGET_PATH=${TARGET_PATH:=.}
cd "$TARGET_PATH"
if [ $RECURSIVE ] ; then
DIRS=($(find . -name .git | sort))
else
DIRS=(./*/.git)
fi
# inside a repo...
if [ -d ./.git ] ; then
echo .
exit 0
fi
# do the update...
wd=$(pwd)
for dir in ${DIRS[@]} ; do
dir=${dir%.git}
echo $dir
done
# vim:set sw=4 ts=4 :

72
bin/git-origins Executable file
View File

@ -0,0 +1,72 @@
#!/usr/bin/env bash
while true ; do
case $1 in
-h|--help)
echo "Usage: $(basename "$0") [OPTIONS] [PATH]"
echo
echo "Print origins of all repositories in PATH."
echo
echo "Options:"
echo " -h --help - print this message and exit"
echo " -r --recursive - pull directories recursively"
echo
exit
;;
-r|--recursive)
RECURSIVE=-r
shift
continue
;;
-*|--*)
echo "Error: unknown option: \"$1\"" >&2
exit
;;
*)
TARGET_PATH=$1
break
;;
esac
done
TARGET_PATH=${TARGET_PATH:=.}
cd "$TARGET_PATH"
DIRS=($(git listall ${RECURSIVE}))
getOrigin(){
cd "$1"
git ls-remote --get-url origin
cd "$wd"
}
# inside a repo...
if [ -d ./.git ] ; then
echo ". `getOrigin .`"
exit 0
fi
# no matches...
if [[ $DIRS =~ \* ]] ; then
echo "no repos found." >&2
exit 1
fi
# do the update...
wd=$(pwd)
for dir in ${DIRS[@]} ; do
dir=${dir%.git}
echo "$dir `getOrigin "$dir"`"
done
# vim:set sw=4 ts=4 :

View File

@ -1,11 +1,5 @@
#!/usr/bin/env bash
# config...
#
#FALLBACK_TO_PULL=yes
#
while true ; do
case $1 in
-h|--help)
@ -16,18 +10,12 @@ while true ; do
echo "Options:"
echo " -h --help - print this message and exit"
echo " -r --recursive - pull directories recursively"
echo " -l --list - print found repositories and exit"
echo
exit
;;
-r|--recursive)
RECURSIVE=1
shift
continue
;;
-l|--list)
LIST=1
RECURSIVE=-r
shift
continue
;;
@ -43,22 +31,13 @@ while true ; do
esac
done
FALLBACK_TO_PULL=${FALLBACK_TO_PULL:=yes}
TARGET_PATH=${TARGET_PATH:=.}
cd "$TARGET_PATH"
if [ $RECURSIVE ] ; then
DIRS=($(find . -name .git | sort))
else
DIRS=(./*/.git)
fi
DIRS=($(git listall ${RECURSIVE}))
# inside a repo...
if [ $FALLBACK_TO_PULL = "yes" ] && [ -d ./.git ] ; then
echo "running inside a repository, falling back to vanilla pull..."
if [ -d ./.git ] ; then
git pull
exit 0
fi
@ -76,9 +55,6 @@ wd=$(pwd)
for dir in ${DIRS[@]} ; do
dir=${dir%.git}
echo $dir
if [ $LIST ] ; then
continue
fi
cd "$dir"
git pull
cd "$wd"