#!/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 .gittum-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=".gittum-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 "[^.]*" | sort | 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