]> git.madduck.net Git - code/vcsh.git/blobdiff - vcsh

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Keep worktree relative to GIT_DIR
[code/vcsh.git] / vcsh
diff --git a/vcsh b/vcsh
index 175a9d1a39fcef377628deb224b9074d244efdbc..d45e95d927925fa31e45deadd7e19f409a94ae9b 100755 (executable)
--- a/vcsh
+++ b/vcsh
@@ -153,6 +153,8 @@ clone() {
   Once this situation has been resolved, run 'vcsh run $VCSH_REPO_NAME git pull' to finish cloning.\n" 17
        git merge origin/master
        hook post-clone
+       retire
+       hook post-clone-retired
 }
 
 delete() {
@@ -195,9 +197,8 @@ hook() {
 
 init() {
        [ ! -e "$GIT_DIR" ] || fatal "'$GIT_DIR' exists" 10
-       export GIT_WORK_TREE="$VCSH_BASE"
-       mkdir -p "$GIT_WORK_TREE" || fatal "could not create '$GIT_WORK_TREE'" 50
-       cd "$GIT_WORK_TREE" || fatal "could not enter '$GIT_WORK_TREE'" 11
+       mkdir -p "$VCSH_BASE" || fatal "could not create '$VCSH_BASE'" 50
+       cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11
        git init
        upgrade
 }
@@ -246,11 +247,22 @@ push() {
        hook post-push
 }
 
+retire() {
+       unset GIT_WORK_TREE
+       unset VCSH_DIRECTORY
+}
+
 rename() {
        git_dir_exists
        [ -d "$GIT_DIR_NEW" ] && fatal "'$GIT_DIR_NEW' exists" 54
        mv -f "$GIT_DIR" "$GIT_DIR_NEW" || fatal "Could not mv '$GIT_DIR' '$GIT_DIR_NEW'" 52
 
+       # Now that the repository has been renamed, we need to fix up its configuration
+       # Overwrite old name..
+       GIT_DIR="$GIT_DIR_NEW"
+       $VCSH_REPO_NAME="$VCSH_REPO_NAME_NEW"
+       # ..and clobber all old configuration
+       upgrade
 }
 
 run() {
@@ -262,17 +274,22 @@ run() {
 
 upgrade() {
        hook pre-upgrade
-       use
-       git config core.worktree     "$GIT_WORK_TREE"
+       # fake-bare repositories are not bare, actually. Set this to false
+       # 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"
        git config vcsh.vcsh         'true'
+       use
        [ -e "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME" ] && git add -f "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME"
        hook post-upgrade
 }
 
 use() {
        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"
 }
 
@@ -354,9 +371,9 @@ elif [ "$1" = 'delete' ]           ||
        export VCSH_COMMAND="$1"
        export VCSH_REPO_NAME="$2"
        export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git"
-       [ "$VCSH_COMMAND" = 'rename' ] && export GIT_DIR_NEW="$VCSH_REPO_D/$3.git"
+       [ "$VCSH_COMMAND" = 'rename' ] && { export VCSH_REPO_NAME_NEW="$3";
+                                           export GIT_DIR_NEW="$VCSH_REPO_D/$VCSH_REPO_NAME_NEW.git"; }
        [ "$VCSH_COMMAND" = 'run' ]    && shift 2
-       [ "$VCSH_COMMAND" = 'write-gitignore' ]
 elif [ "$1" = 'list' ] ||
      [ "$1" = 'list-tracked' ] ||
      [ "$1" = 'pull' ] ||