| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 | 
							- #!/bin/sh
 - #
 - # Take first subdir (or a subdir specified in a file) and consider
 - # it a git repo dir.  Get its origin, exchange the last bit for
 - # other project name and clone the other repo
 - #
 - # This is useful if you have a local dir where you store repos
 - # for various projects from a common namespace that differ only
 - # in last part of the remote URI.  Now all you need to do to
 - # clone new one is "git sibling aproject".  The script will
 - # do the rest for you including sniffing the URI.
 - #
 - # The script simply takes the first subdir.  In case this is not
 - # OK for you (e.g. the dir id likely to be empty or contain
 - # come "non-compliant" repos, you can specify path to the
 - # other "template" repo in .git-universe-sibling file.
 - #
 - # Hint: regarding the "template" repo, you can easily create
 - # a "fake" repo that would sit elsewhere, e.g.:
 - #     $ mkdir .some/hidden/dir
 - #     $ cd .some/hidden/dir
 - #     $ git init
 - #     $ git remote add origin ssh://our_server/projects/FAKE
 - 
 - 
 - ## cfgz
 - #
 - 
 - origin_name="origin"
 - sibling_conf=".git-universe-sibling"
 - 
 - 
 - ## funz
 - #
 - 
 - rewrite_uri_to () {
 -     # create a new remote URI based on current one
 -     git remote -v \
 -         | grep "^$origin_name" \
 -         | grep "(fetch)$" \
 -         | cut -f 2 \
 -         | cut -d" " -f 1 \
 -         | perl -pe "s|[^/]+$|$1|;"
 - }
 - 
 - 
 - ## initz
 - #
 - 
 - project=$1
 - 
 - if [ -f $sibling_conf ];
 - then
 -     sibling=$(cat $sibling_conf);
 - else
 -     sibling=$(find -maxdepth 1 -type d -name "[^.]*" | head -1)
 - fi
 - 
 - if [ -z "$sibling" ];
 - then
 -     echo "could not find older sibling" 1>&2
 -     exit 1
 - fi
 - 
 - 
 - ## body
 - #
 - 
 - pushd "$sibling" >/dev/null
 - new_remote=$(rewrite_uri_to $project)
 - popd >/dev/null
 - 
 - echo \'git clone $new_remote\'
 - git clone $new_remote
 
 
  |