mirror of
https://github.com/flynx/git-utils.git
synced 2025-10-28 10:40:08 +00:00
Compare commits
3 Commits
e72a99e6c8
...
de8c0781b9
| Author | SHA1 | Date | |
|---|---|---|---|
| de8c0781b9 | |||
| 662e1f8ea3 | |||
| a16861458b |
12
README.md
12
README.md
@ -15,6 +15,7 @@ Provided commands:
|
|||||||
These enable setting up and maintaining mutiple development machines with
|
These enable setting up and maintaining mutiple development machines with
|
||||||
a number of git repositories.
|
a number of git repositories.
|
||||||
|
|
||||||
|
|
||||||
## Workflow
|
## Workflow
|
||||||
|
|
||||||
In a tree with multiple git repositories:
|
In a tree with multiple git repositories:
|
||||||
@ -24,12 +25,21 @@ In a tree with multiple git repositories:
|
|||||||
```
|
```
|
||||||
- to create the same env on a different computer:
|
- to create the same env on a different computer:
|
||||||
```shell
|
```shell
|
||||||
$ git listall -o -r > repos.lst
|
$ git listall -r > repos.lst
|
||||||
```
|
```
|
||||||
move the `repos.lst` to the target machine and:
|
move the `repos.lst` to the target machine and:
|
||||||
```shell
|
```shell
|
||||||
$ git cloneall repos.lst
|
$ git cloneall repos.lst
|
||||||
```
|
```
|
||||||
|
- to update the repository list with new repos:
|
||||||
|
```shell
|
||||||
|
$ git listall -r repos.lst >> repos.lst
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Tips
|
||||||
|
- It is convenient to manage `repos.lst` as symlinks to a unified directory and
|
||||||
|
syncronize it between machines via someting like [syncthing](https://syncthing.net/)
|
||||||
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
@ -5,105 +5,44 @@ shopt -s globstar
|
|||||||
while true ; do
|
while true ; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-h|--help)
|
-h|--help)
|
||||||
echo "Usage: $(basename "$0") [OPTIONS] FILE [PATH]"
|
echo "Usage: $(basename "$0") [OPTIONS] FILE"
|
||||||
echo
|
echo
|
||||||
echo "Clone all repositories from lst (FILE)."
|
echo "Clone all repositories from lst (FILE)."
|
||||||
echo
|
echo
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -h --help - print this message and exit"
|
echo " -h --help - print this message and exit"
|
||||||
echo " -o - print repos and exit"
|
|
||||||
echo " -r - print repos recursively and exit"
|
|
||||||
echo
|
echo
|
||||||
echo "Repository list can be constructed from an existing set of"
|
echo "The repository list is a text file containing:"
|
||||||
echo "repositories via:"
|
echo " - Repository definition lines -- a \"=\"-separated path and a remote url"
|
||||||
echo " $ git listall -o > reposiotry.lst"
|
echo " Repository definitions starting with \"-\" will not get cloned"
|
||||||
echo "or recursively:"
|
echo " - Lines starting with \"#\" and empty lines are ignored"
|
||||||
echo " $ git listall -r > reposiotry.lst"
|
|
||||||
echo "If a repository list already exists it can be expanded via:"
|
|
||||||
echo " $ git listall -r reposiotry.lst >> reposiotry.lst"
|
|
||||||
echo
|
echo
|
||||||
echo "The repository list is a text file with each line consisting"
|
|
||||||
echo "of a \"=\"-separated path and a remote url (as supported by"
|
|
||||||
echo "git clone)."
|
|
||||||
echo "Lines starting with \"-\" will not get cloned"
|
|
||||||
echo "The list file can also contain empty lines and supports shell"
|
|
||||||
echo "comments (lines starting with \"#\")"
|
|
||||||
echo "Example:"
|
echo "Example:"
|
||||||
echo " # comment..."
|
echo " # comment..."
|
||||||
echo " ./path/to/repo=git@example.com:user/repo.git"
|
echo " ./path/to/repo=git@example.com:user/repo.git"
|
||||||
|
echo
|
||||||
echo " # disabled repo..."
|
echo " # disabled repo..."
|
||||||
echo " -./path/to/repo=git@example.com:user/repo.git"
|
echo " -./path/to/other-repo=git@example.com:user/other-repo.git"
|
||||||
|
echo
|
||||||
|
echo "For info on constructing and updating repository lists see:"
|
||||||
|
echo " $ git-listall --help"
|
||||||
echo
|
echo
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# list...
|
|
||||||
-o)
|
|
||||||
LIST_REPOS=1
|
|
||||||
shift
|
|
||||||
continue
|
|
||||||
;;
|
|
||||||
-r)
|
|
||||||
RECURSIVE=1
|
|
||||||
shift
|
|
||||||
continue
|
|
||||||
;;
|
|
||||||
|
|
||||||
-*|--*)
|
-*|--*)
|
||||||
echo "Error: unknown option: \"$1\"" >&2
|
echo "Error: unknown option: \"$1\"" >&2
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
LIST=$1
|
LIST=$1
|
||||||
TARGET_PATH=$2
|
#TARGET_PATH=$2
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# list...
|
|
||||||
#
|
|
||||||
|
|
||||||
if ! [ -z $LIST_REPOS ] || ! [ -z $RECURSIVE ] ; then
|
|
||||||
if ! [ -z $RECURSIVE ] ; then
|
|
||||||
REPOS=(./**/.git/config)
|
|
||||||
else
|
|
||||||
REPOS=(./*/.git/config)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# format and print unique lines...
|
|
||||||
lines=()
|
|
||||||
{
|
|
||||||
for p in "${REPOS[@]}" ; do
|
|
||||||
path=${p/.git\/config/}
|
|
||||||
remote=$(cat "$p" \
|
|
||||||
| sed -n '/\[remote "origin"\]/,/^\s*url/p' \
|
|
||||||
| grep 'url = ' \
|
|
||||||
| sed \
|
|
||||||
-e 's/\s*url\s*=\s*//')
|
|
||||||
[ -z $remote ] \
|
|
||||||
&& continue
|
|
||||||
line="$path=$remote"
|
|
||||||
lines+=($line)
|
|
||||||
echo $line
|
|
||||||
done
|
|
||||||
if [ -e "$LIST" ] ; then
|
|
||||||
cat "$LIST" \
|
|
||||||
| grep -ve '\(^\s*#\|^\s*$\)' \
|
|
||||||
| sed -e 's/^-//'
|
|
||||||
fi
|
|
||||||
} \
|
|
||||||
| sort \
|
|
||||||
| uniq -u
|
|
||||||
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# clone...
|
|
||||||
#
|
|
||||||
|
|
||||||
TARGET_PATH=${TARGET_PATH:=.}
|
TARGET_PATH=${TARGET_PATH:=.}
|
||||||
cd "$TARGET_PATH"
|
cd "$TARGET_PATH"
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,29 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
shopt -s globstar
|
||||||
|
|
||||||
while true ; do
|
while true ; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-h|--help)
|
-h|--help)
|
||||||
echo "Usage: $(basename "$0") [OPTIONS] [PATH]"
|
echo "Usage: $(basename "$0") [OPTIONS] [LIST]"
|
||||||
echo
|
echo
|
||||||
echo "List all repositories in PATH."
|
echo "List all repositories in current directory."
|
||||||
echo
|
echo
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -h --help - print this message and exit"
|
echo " -h --help - print this message and exit"
|
||||||
echo " -r --recursive - list directories recursively"
|
echo " -r --recursive - list directories recursively"
|
||||||
echo " -o --origin - also print origin url"
|
echo
|
||||||
|
echo "Repository list can be constructed from an existing set of repositories via:"
|
||||||
|
echo " $ git listall > reposiotry.lst"
|
||||||
|
echo
|
||||||
|
echo "or recursively:"
|
||||||
|
echo " $ git listall -r > reposiotry.lst"
|
||||||
|
echo
|
||||||
|
echo "If a repository list already exists it can be expanded via:"
|
||||||
|
echo " $ git listall -r reposiotry.lst >> reposiotry.lst"
|
||||||
|
echo
|
||||||
|
echo "For info on list file format see:"
|
||||||
|
echo " $ git-cloneall --help"
|
||||||
echo
|
echo
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
@ -20,56 +33,53 @@ while true ; do
|
|||||||
shift
|
shift
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
-o|--origin)
|
|
||||||
ORIGIN=1
|
|
||||||
shift
|
|
||||||
continue
|
|
||||||
;;
|
|
||||||
|
|
||||||
-*|--*)
|
-*|--*)
|
||||||
echo "Error: unknown option: \"$1\"" >&2
|
echo "Error: unknown option: \"$1\"" >&2
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
TARGET_PATH=$1
|
LIST=$1
|
||||||
|
#TARGET_PATH=$2
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
TARGET_PATH=${TARGET_PATH:=.}
|
TARGET_PATH=${TARGET_PATH:=.}
|
||||||
cd "$TARGET_PATH"
|
cd "$TARGET_PATH"
|
||||||
|
|
||||||
if [ $RECURSIVE ] ; then
|
if ! [ -z $RECURSIVE ] ; then
|
||||||
IFS=$'\n' \
|
REPOS=(./**/.git/config)
|
||||||
DIRS=($(find . -name .git | sort))
|
|
||||||
else
|
else
|
||||||
IFS=$'\n' \
|
REPOS=(./*/.git/config)
|
||||||
DIRS=(./*/.git)
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# XXX handle local repos...
|
# format and print unique lines...
|
||||||
getOrigin(){
|
lines=()
|
||||||
if ! [ -z $ORIGIN ] ; then
|
{
|
||||||
cd "$1"
|
for p in "${REPOS[@]}" ; do
|
||||||
echo "=`git ls-remote --get-url origin`"
|
path=${p/.git\/config/}
|
||||||
cd "$wd"
|
remote=$(cat "$p" \
|
||||||
|
| sed -n '/\[remote "origin"\]/,/^\s*url/p' \
|
||||||
|
| grep 'url = ' \
|
||||||
|
| sed \
|
||||||
|
-e 's/\s*url\s*=\s*//')
|
||||||
|
[ -z $remote ] \
|
||||||
|
&& continue
|
||||||
|
line="$path=$remote"
|
||||||
|
lines+=($line)
|
||||||
|
echo $line
|
||||||
|
done
|
||||||
|
if [ -e "$LIST" ] ; then
|
||||||
|
cat "$LIST" \
|
||||||
|
| grep -ve '\(^\s*#\|^\s*$\)' \
|
||||||
|
| sed -e 's/^-//'
|
||||||
fi
|
fi
|
||||||
}
|
} \
|
||||||
|
| sort \
|
||||||
|
| uniq -u
|
||||||
|
|
||||||
# inside a repo...
|
|
||||||
if [ -d ./.git ] ; then
|
|
||||||
echo ".`getOrigin .`"
|
|
||||||
exit 0
|
|
||||||
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 :
|
# vim:set sw=4 ts=4 :
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user