mirror of
https://github.com/flynx/git-utils.git
synced 2025-12-25 12:52:05 +00:00
added several usefull meta commands...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
37ad629ddd
commit
f7793c80d4
84
bin/git-cloneall
Executable file
84
bin/git-cloneall
Executable 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
58
bin/git-listall
Executable 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
72
bin/git-origins
Executable 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 :
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,11 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# config...
|
|
||||||
#
|
|
||||||
#FALLBACK_TO_PULL=yes
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
while true ; do
|
while true ; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-h|--help)
|
-h|--help)
|
||||||
@ -16,18 +10,12 @@ while true ; do
|
|||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -h --help - print this message and exit"
|
echo " -h --help - print this message and exit"
|
||||||
echo " -r --recursive - pull directories recursively"
|
echo " -r --recursive - pull directories recursively"
|
||||||
echo " -l --list - print found repositories and exit"
|
|
||||||
echo
|
echo
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
|
|
||||||
-r|--recursive)
|
-r|--recursive)
|
||||||
RECURSIVE=1
|
RECURSIVE=-r
|
||||||
shift
|
|
||||||
continue
|
|
||||||
;;
|
|
||||||
-l|--list)
|
|
||||||
LIST=1
|
|
||||||
shift
|
shift
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
@ -43,22 +31,13 @@ while true ; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
FALLBACK_TO_PULL=${FALLBACK_TO_PULL:=yes}
|
|
||||||
|
|
||||||
TARGET_PATH=${TARGET_PATH:=.}
|
TARGET_PATH=${TARGET_PATH:=.}
|
||||||
cd "$TARGET_PATH"
|
cd "$TARGET_PATH"
|
||||||
|
|
||||||
if [ $RECURSIVE ] ; then
|
DIRS=($(git listall ${RECURSIVE}))
|
||||||
DIRS=($(find . -name .git | sort))
|
|
||||||
else
|
|
||||||
DIRS=(./*/.git)
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# inside a repo...
|
# inside a repo...
|
||||||
if [ $FALLBACK_TO_PULL = "yes" ] && [ -d ./.git ] ; then
|
if [ -d ./.git ] ; then
|
||||||
echo "running inside a repository, falling back to vanilla pull..."
|
|
||||||
git pull
|
git pull
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@ -76,9 +55,6 @@ wd=$(pwd)
|
|||||||
for dir in ${DIRS[@]} ; do
|
for dir in ${DIRS[@]} ; do
|
||||||
dir=${dir%.git}
|
dir=${dir%.git}
|
||||||
echo $dir
|
echo $dir
|
||||||
if [ $LIST ] ; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
cd "$dir"
|
cd "$dir"
|
||||||
git pull
|
git pull
|
||||||
cd "$wd"
|
cd "$wd"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user