123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #!/bin/bash
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- die() {
- echo "$@" 1>&2
- exit 1
- }
-
- usage() {
- echo "usage: git $(basename "$0") [-v] [-s SIBLING] [-r REMOTE] PROJECT"
- exit 0
- }
-
- rewrite_uri () {
- local remote=$1
- local to=$2
-
- git remote -v \
- | grep "^$remote" \
- | grep "(fetch)$" \
- | cut -f 2 \
- | cut -d" " -f 1 \
- | perl -pe "s|[^/]+$|$to|;"
- }
-
- think() {
- $verbose && echo "$@"
- }
-
- sibling_conf=".gittum-sibling"
- verbose=false
- sibling=$(find -maxdepth 1 -type d -name "[^.]*" | sort | head -1)
- test -f $sibling_conf && sibling=$(cat $sibling_conf)
- remote_name="origin"
-
- while true; do case $1 in
- -r|--remote-name) remote_name=$2; shift 2 ;;
- -s|--sibling) sibling=$2; shift 2 ;;
- -v|--verbose) verbose=true; shift ;;
- -*) usage ;;
- "") break ;;
- *) project=$1; shift ;;
- esac done
-
- test -n "$project" || usage
- test -n "$sibling" || die "could not find older sibling"
- test -d "$sibling" || die "sibling does not exist: $sibling"
-
- pushd "$sibling" >/dev/null
- new_remote=$(rewrite_uri "$remote_name" "$project")
- popd >/dev/null
-
- test -n "$new_remote" || die "no such remote at sibling: $new_remote at $sibling"
-
- cmd="git clone $new_remote"
-
- think "cmd='$cmd'"
- $cmd
|