#!/bin/bash # Clones a repository for use in .subgit for tracking worktree changes. usage() { die $(cat <<-EOF Usage: subgit clone [-b BRANCH] [CLONE-ARGS..] REMOTE PATH Clones a bare repository for use in .subgit directory. The bare repository is configured to track changes from a remote while allowing the working tree to be symlinked separately. EOF ) } while [ "$1" ]; do case $1 in -b) [ $# -lt 2 ] && die "Missing branch" || branch="$2"; shift; shift;; -h) usage;; --) shift; break;; -*) die "Invalid option $1";; *) break;; esac done [ $# -lt 2 ] && usage path="${@: -1}" [ -d "$path" ] && die "Path already exists" args=() if [ ! -z "$branch" ]; then args+=(--single-branch -b "$branch") fi git clone --bare "${args[@]}" "$@" git -C "$path" config --local --bool core.bare false git -C "$path" config --local remote.origin.fetch \ "+refs/heads/*:refs/remotes/origin/*"