diff --git a/README.md b/README.md index 78d732b..c9c5f30 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ # git-utlis -git utilities + +This package provides a set of git meta "porcelain" commands to manage +a work tree, i.e. a set of git repositories. + +Provided commands: +- `git listall` + List repositories in tree. +- `git cloneall FILE` + Clone all repositories in file +- `git pullall` + Pull changes for all repositories in tree + + diff --git a/bin/git-cloneall b/bin/git-cloneall index f4c0a32..19cd2eb 100755 --- a/bin/git-cloneall +++ b/bin/git-cloneall @@ -12,12 +12,12 @@ while true ; do echo echo "Repository list can be constructed from an existing set of" echo "repositories via:" - echo " $ git remotes > reposiotry.lst" + echo " $ git listall -o > reposiotry.lst" echo "or recursively:" - echo " $ git remotes -r > reposiotry.lst" + echo " $ git listall -o -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 "of a \"=\"-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 \"#\")" @@ -56,11 +56,11 @@ for repo in ${LIST[@]} ; do continue fi - IFS=$' ' \ + IFS=$'=' \ repo=($repo) - # skip existing dirs... - if [ -e "${repo[0]}" ] ; then + # skip existing dirs or local repos... + if [ -e "${repo[0]}" ] || [ "${repo[1]}" = "origin" ] ; then #echo "skipping: ${repo[0]}" continue fi diff --git a/bin/git-listall b/bin/git-listall index a2d9b21..950bc26 100755 --- a/bin/git-listall +++ b/bin/git-listall @@ -9,7 +9,8 @@ while true ; do echo echo "Options:" echo " -h --help - print this message and exit" - echo " -r --recursive - pull directories recursively" + echo " -r --recursive - list directories recursively" + echo " -o --origin - also print origin url" echo exit ;; @@ -19,6 +20,11 @@ while true ; do shift continue ;; + -o|--origin) + ORIGIN=1 + shift + continue + ;; -*|--*) echo "Error: unknown option: \"$1\"" >&2 @@ -36,14 +42,25 @@ TARGET_PATH=${TARGET_PATH:=.} cd "$TARGET_PATH" if [ $RECURSIVE ] ; then - DIRS=($(find . -name .git | sort)) + IFS=$'\n' \ + DIRS=($(find . -name .git | sort)) else - DIRS=(./*/.git) + IFS=$'\n' \ + DIRS=(./*/.git) fi +# XXX handle local repos... +getOrigin(){ + if ! [ -z $ORIGIN ] ; then + cd "$1" + echo "=`git ls-remote --get-url origin`" + cd "$wd" + fi +} + # inside a repo... if [ -d ./.git ] ; then - echo . + echo ".`getOrigin .`" exit 0 fi @@ -51,7 +68,7 @@ fi wd=$(pwd) for dir in ${DIRS[@]} ; do dir=${dir%.git} - echo $dir + echo "$dir`getOrigin "$dir"`" done diff --git a/bin/git-origins b/bin/git-origins deleted file mode 100755 index d254558..0000000 --- a/bin/git-origins +++ /dev/null @@ -1,72 +0,0 @@ -#!/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 : - - - - -