diff --git a/bin/git-cloneall b/bin/git-cloneall new file mode 100755 index 0000000..f4c0a32 --- /dev/null +++ b/bin/git-cloneall @@ -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 : + + + + + diff --git a/bin/git-listall b/bin/git-listall new file mode 100755 index 0000000..a2d9b21 --- /dev/null +++ b/bin/git-listall @@ -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 : diff --git a/bin/git-origins b/bin/git-origins new file mode 100755 index 0000000..d254558 --- /dev/null +++ b/bin/git-origins @@ -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 : + + + + + diff --git a/bin/git-pullall b/bin/git-pullall index 030727c..6434fa4 100755 --- a/bin/git-pullall +++ b/bin/git-pullall @@ -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"