hooks: factor out an update-working-tree.sh script
[config/vcsh.git] / .config / vcsh / hooks-available / update-working-tree.sh
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
+