hooks: factor out an update-working-tree.sh script
authorAntonio Ospite <ao2@ao2.it>
Thu, 24 Jan 2019 14:54:48 +0000 (15:54 +0100)
committerAntonio Ospite <ao2@ao2.it>
Thu, 31 Jan 2019 08:34:40 +0000 (09:34 +0100)
In some cases the working tree needs to be updated outside of
populate-sparsely.sh (which is meant for a post-enter hook), so split
out this task from the main script.

.config/vcsh/hooks-available/populate-sparsely.sh
.config/vcsh/hooks-available/update-working-tree.sh [new file with mode: 0755]

index 937122a..cca8218 100755 (executable)
@@ -19,13 +19,8 @@ LOCKPID=$(cat "$LOCKDIR/pid")
 # shellcheck source=/dev/null
 . "$XDG_CONFIG_HOME/vcsh/hooks-available/enable-sparse-checkout.sh"
 
-# Verify if the current branch is valid before updating the working tree.
-# This avoids errors with empty repositories which would only confuse the
-# user.
-if git rev-parse --verify HEAD >/dev/null 2>&1;
-then
-  git read-tree -mu HEAD
-fi
+# shellcheck source=/dev/null
+. "$XDG_CONFIG_HOME/vcsh/hooks-available/update-working-tree.sh"
 
 # Unlock the working tree.
 rm -rf "$LOCKDIR"
diff --git a/.config/vcsh/hooks-available/update-working-tree.sh b/.config/vcsh/hooks-available/update-working-tree.sh
new file mode 100755 (executable)
index 0000000..8d88e8c
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# Verify if the current branch is valid before updating the working tree.
+# This avoids errors with empty repositories which would only confuse the
+# user.
+if git rev-parse --verify HEAD >/dev/null 2>&1;
+then
+  git read-tree -mu HEAD
+fi
+