123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #!/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 "$@"
- }
-
-
-
-
- origin_name="origin"
- 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
- ;;
- "")
- 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"
-
- think \'git clone $new_remote\'
- git clone $new_remote
|