#!/bin/sh USAGE="git-cvs-split [options] [ref]" die() { echo >&2 "$@" exit 1 } usage() { die "Usage: $0 $USAGE" } STRIP_TAGS= while case "$#" in 0) break ;; esac do case $1 in -h|--help) usage ;; -s|--strip-tags) STRIP_TAGS=1 ; shift ;; -*) usage ;; *) break ;; esac done REPOSITORY=$1 if [ -z ${REPOSITORY} ]; then usage fi shift SUBDIR=$1 if [ -z ${SUBDIR} ]; then usage fi shift REF=$1 if [ -z ${REF} ]; then REF="HEAD" fi TARGET="${SUBDIR}.git" #echo "REPOSITORY: ${REPOSITORY}" #echo "SUBDIR: ${SUBDIR}" #echo "REF: ${REF}" #echo "TARGET: ${TARGET}" #echo "STRIP_TAGS: ${STRIP_TAGS}" # we need to clone the repository to avoid touching it git-clone --no-hardlinks ${REPOSITORY} ${TARGET} && cd ${TARGET} # tags will be dangling after filtering, so we just remove them here if [ ! -z $STRIP_TAGS ]; then for TAG in `git-tag`; do git-tag -f -d ${TAG}; done fi git-filter-branch --subdirectory-filter ${SUBDIR} ${REF} git-reset --hard git-gc --aggressive && git-prune exit 0