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

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:

Merge pull request #89 from alerque/master
authorRichard Hartmann <RichiH@users.noreply.github.com>
Sat, 8 Feb 2014 15:30:38 +0000 (16:30 +0100)
committerRichard Hartmann <RichiH@users.noreply.github.com>
Sat, 8 Feb 2014 15:30:38 +0000 (16:30 +0100)
Add hooks to allow fancy merge handling

doc/hooks
doc/sample_hooks/post-merge-unclobber [new file with mode: 0755]
doc/sample_hooks/pre-merge-unclobber [new file with mode: 0755]
vcsh

index 54ff795611c0081e11eca8d16064f0f57f2ac60e..282ee86265c765c7a457234931aaed000ae913aa 100644 (file)
--- a/doc/hooks
+++ b/doc/hooks
@@ -14,6 +14,12 @@ Available hooks are:
 * post-enter
 * pre-init
 * post-init
+* pre-merge
+       Use this hook to detect and handle merge conflicts before vcsh's native code
+       finds and errors on them. This is useful for allowing clones on top of existing
+       files.
+* post-merge
+       Use this hook to finish handling any merge conflicts found in the pre-merge hook.
 * pre-pull
 * post-pull
 * pre-push
diff --git a/doc/sample_hooks/post-merge-unclobber b/doc/sample_hooks/post-merge-unclobber
new file mode 100755 (executable)
index 0000000..017a13f
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# This finds objects that the pre-merge script moved out of the way to
+# avoid conflicts when running git clone and moves them back to their
+# original places. The result is that the git repository gets checked out
+# and the extant objects end up back in the working directory. Git now
+# sees these as un-staged changes to the working branch and you can deal
+# with them by adding them or reverting.
+
+find -name '*.vcsh-unclobber' -execdir rename .vcsh-unclobber '' {} \;
diff --git a/doc/sample_hooks/pre-merge-unclobber b/doc/sample_hooks/pre-merge-unclobber
new file mode 100755 (executable)
index 0000000..93a7319
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# This code does amost exactly what the native VCSH sanity checking code
+# does except that on finding a potential merge conflict, it moves the 
+# extant object out of the way temporarily. The merge then happens cleanly
+# as far as git knows, and a post-merge hook can figure out what to do with
+# the extant versions of the objects.
+
+for object in $(git ls-tree -r origin/master | awk '{print $4}'); do
+       [ -e "$object" ] && mv "$object" "$object.vcsh-unclobber" 
+done
diff --git a/vcsh b/vcsh
index 6ce5320a620e098d2907c127261c65a0a334a939..a6d82138307a2d00e93f8c944b3f93ac03e69316 100755 (executable)
--- a/vcsh
+++ b/vcsh
@@ -152,6 +152,7 @@ clone() {
                exit
        fi
        git fetch
+       hook pre-merge
        git ls-tree -r --name-only origin/master | (while read object; do
                [ -e "$object" ] &&
                        error "'$object' exists." &&
@@ -161,6 +162,7 @@ clone() {
                fatal "will stop after fetching and not try to merge!
   Once this situation has been resolved, run 'vcsh run $VCSH_REPO_NAME git pull' to finish cloning." 17
        git merge origin/master
+       hook post-merge
        hook post-clone
        retire
        hook post-clone-retired