From e85f20d453d08afba32c752bfd432431b70764a5 Mon Sep 17 00:00:00 2001
From: Richard Hartmann <richih@debian.org>
Date: Tue, 3 Sep 2013 00:51:14 +0200
Subject: [PATCH] vcsh: Add support for choosing relative or absolute
 core.worktree

---
 doc/vcsh.1.ronn |  9 +++++++++
 vcsh            | 14 ++++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/doc/vcsh.1.ronn b/doc/vcsh.1.ronn
index 89ebff5..56df4ed 100644
--- a/doc/vcsh.1.ronn
+++ b/doc/vcsh.1.ronn
@@ -184,6 +184,15 @@ Interesting knobs you can turn:
 
   Defaults to <exact>.
 
+* <$VCSH_VCSH_WORKTREE>:
+  Can be <absolute>, or <relative>.
+
+  <absolute> will set an absolute path; defaulting to <$HOME>.
+
+  <relative> will set a path relative to <$GIT_DIR>.
+
+  Defaults to <absolute>.
+
 Less interesting knobs you could turn:
 
 * <$VCSH_DEBUG>:
diff --git a/vcsh b/vcsh
index 60fcd99..d1283e4 100755
--- a/vcsh
+++ b/vcsh
@@ -81,6 +81,11 @@ 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_WORKTREE" = 'xabsolute' ] && [ ! "x$VCSH_WORKTREE" = 'xrelative' ]; then
+	fatal "'\$VCSH_WORKTREE' must equal 'absolute', or 'relative'" 1
+fi
 
 
 help() {
@@ -313,8 +318,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
-- 
GitLab