Skip to content
Snippets Groups Projects
Commit e9a6b438 authored by martin f. krafft's avatar martin f. krafft
Browse files

Keep worktree relative to GIT_DIR


core.worktree can be set relatively to GIT_DIR, thereby preventing the
hard-coding of the home directory path, which should make a vcsh setup
more portable.

On the other hand, this means that the vcsh repo.d is now invariably
linked to its position, relative to the base directory. Apply this patch
only if you think it to be less likely that people change
~/.config/vcsh/repo.d to something else, than they would rsync/tar/mv
a whole tree to a different $HOME.

Paths are resolved using Git itself, for maximum portability.

In addition to making sure the new method works on new repositories,
I checked that

  - "old" repositories can be used with the new code just fine;
  - upgrading works.

Signed-off-by: default avatarmartin f. krafft <madduck@madduck.net>
parent 84568765
No related branches found
No related tags found
No related merge requests found
...@@ -197,9 +197,8 @@ hook() { ...@@ -197,9 +197,8 @@ hook() {
init() { init() {
[ ! -e "$GIT_DIR" ] || fatal "'$GIT_DIR' exists" 10 [ ! -e "$GIT_DIR" ] || fatal "'$GIT_DIR' exists" 10
export GIT_WORK_TREE="$VCSH_BASE" mkdir -p "$VCSH_BASE" || fatal "could not create '$VCSH_BASE'" 50
mkdir -p "$GIT_WORK_TREE" || fatal "could not create '$GIT_WORK_TREE'" 50 cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11
cd "$GIT_WORK_TREE" || fatal "could not enter '$GIT_WORK_TREE'" 11
git init git init
upgrade upgrade
} }
...@@ -275,17 +274,22 @@ run() { ...@@ -275,17 +274,22 @@ run() {
upgrade() { upgrade() {
hook pre-upgrade hook pre-upgrade
use # fake-bare repositories are not bare, actually. Set this to false
git config core.worktree "$GIT_WORK_TREE" # 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)
[ ! "x$VCSH_GITIGNORE" = 'xnone' ] && git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME" [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME"
git config vcsh.vcsh 'true' git config vcsh.vcsh 'true'
use
[ -e "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME" ] && git add -f "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME" [ -e "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME" ] && git add -f "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME"
hook post-upgrade hook post-upgrade
} }
use() { use() {
git_dir_exists git_dir_exists
export GIT_WORK_TREE="$(git config --get core.worktree)" export GIT_WORK_TREE="$(git rev-parse --show-toplevel)"
export VCSH_DIRECTORY="$VCSH_REPO_NAME" export VCSH_DIRECTORY="$VCSH_REPO_NAME"
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment