X-Git-Url: https://git.madduck.net/code/vcsh.git/blobdiff_plain/6927829eb87b6abbe8b9cdee346624c73aecb512..b81e4c5cd981a4ca32317f93510a62d04d1e6456:/vcsh diff --git a/vcsh b/vcsh index 60fcd99..cf0c8cf 100755 --- a/vcsh +++ b/vcsh @@ -24,7 +24,7 @@ basename() { } SELF=$(basename $0) -VERSION='1.20130829' +VERSION='1.20130909' fatal() { echo "$SELF: fatal: $1" >&2 @@ -81,6 +81,15 @@ fi [ -z "$VCSH_HOOK_D" ] && VCSH_HOOK_D="$XDG_CONFIG_HOME/vcsh/hooks-enabled" [ -z "$VCSH_BASE" ] && VCSH_BASE="$HOME" [ -z "$VCSH_GITIGNORE" ] && VCSH_GITIGNORE='exact' +[ -z "$VCSH_WORKTREE" ] && VCSH_WORKTREE='absolute' + +if [ ! "x$VCSH_GITIGNORE" = 'xexact' ] && [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && [ ! "x$VCSH_GITIGNORE" = 'xrecursive' ]; then + fatal "'\$VCSH_GITIGNORE' must equal 'exact', 'none', or 'recursive'" 1 +fi + +if [ ! "x$VCSH_WORKTREE" = 'xabsolute' ] && [ ! "x$VCSH_WORKTREE" = 'xrelative' ]; then + fatal "'\$VCSH_WORKTREE' must equal 'absolute', or 'relative'" 1 +fi help() { @@ -313,8 +322,13 @@ upgrade() { # because otherwise Git complains "fatal: core.bare and core.worktree # do not make sense" git config core.bare false - # in core.worktree, keep a relative reference to the base directory - git config core.worktree $(cd $GIT_DIR && GIT_WORK_TREE="$VCSH_BASE" git rev-parse --show-cdup) + # core.worktree may be absolute or relative to $GIT_DIR, depending on + # user preference + if [ ! "x$VCSH_WORKTREE" = 'xabsolute' ]; then + git config core.worktree $(cd $GIT_DIR && GIT_WORK_TREE="$VCSH_BASE" git rev-parse --show-cdup) + elif [ ! "x$VCSH_WORKTREE" = 'xrelative' ]; then + git config core.worktree "$VCSH_BASE" + fi [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME" git config vcsh.vcsh 'true' use @@ -351,7 +365,11 @@ write_gitignore() { file="$new" done; done | sort -u) - tempfile=$(mktemp) || fatal "could not create tempfile" 51 + + # Contrary to GNU mktemp, mktemp on BSD/OSX requires a template for temp files + # Use the template GNU mktemo defaults to + tempfile=$(mktemp tmp.XXXXXXXXXX) || fatal "could not create tempfile" 51 + echo '*' > "$tempfile" || fatal "could not write to '$tempfile'" 57 for gitignore in $gitignores; do echo "$gitignore" | sed 's@^@!/@' >> "$tempfile" || fatal "could not write to '$tempfile'" 57 @@ -372,10 +390,6 @@ write_gitignore() { fatal "could not move '$tempfile' to '$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME'" 53 } -if [ ! "x$VCSH_GITIGNORE" = 'xexact' ] && [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && [ ! "x$VCSH_GITIGNORE" = 'xrecursive' ]; then - fatal "'\$VCSH_GITIGNORE' must equal 'exact', 'none', or 'recursive'" 1 -fi - if [ "$1" = 'clone' ]; then [ -z "$2" ] && fatal "$1: please specify a remote" 1 export VCSH_COMMAND="$1" @@ -385,6 +399,7 @@ if [ "$1" = 'clone' ]; then export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git" elif [ "$1" = 'version' ]; then echo "$SELF $VERSION" + git version exit elif [ "$1" = 'which' ]; then [ -z "$2" ] && fatal "$1: please specify a filename" 1