46e155fdbc9f100a21dd2c87bacbaa892d36fe43
[config/vcsh.git] / .config / vcsh / hooks-available / populate-fully.sh
1 #!/bin/sh
2
3 set -e
4
5 # Only one vcsh instance at a time can have the work dir fully populated.
6 LOCKDIR=/run/lock/vcsh
7
8 # Kill the parent process because vcsh does not catch the hook exit value.
9 # See: https://github.com/RichiH/vcsh/issues/251
10 mkdir "$LOCKDIR" 2>/dev/null || { echo "An instance of vcsh already entered a repository." 1>&2; kill -- -$PPID;}
11
12 # Lock on the parent pid because the hooks are launched as children of vcsh.
13 echo $PPID > "$LOCKDIR/pid"
14
15 # git read-tree manual page says this is the proper way to fully repopulate
16 # the working directory
17 git config core.sparseCheckout true
18 rm -f "$GIT_DIR/info/sparse-checkout"
19 echo "/*" > "$GIT_DIR/info/sparse-checkout"
20 git read-tree -mu HEAD
21 git config core.sparseCheckout false