5 # If the vcsh repository does not exist, exit without doing anything.
6 [ -d "$GIT_DIR" ] || exit 0
8 # Only one vcsh instance at a time can have the working tree fully populated.
11 # If mkdir fails it means that the lock dir already exists and the lock is
13 if ! mkdir "$LOCKDIR" 2>/dev/null;
15 echo "An instance of vcsh already entered a repository." 1>&2
17 # Exit vcsh if the process which keeps the lock is still alive.
18 if kill -0 $(cat "$LOCKDIR/pid") 2>/dev/null;
20 # Kill the parent process instead of just bailing out because vcsh does
21 # not catch the hook exit value.
22 # See: https://github.com/RichiH/vcsh/issues/251
25 echo "The instance which entered the repository earlier does not exist anymore." 1>&2
26 echo "Continuing anyway." 1>&2
30 # Lock on the parent pid because the hooks are launched as children of vcsh.
31 echo $PPID > "$LOCKDIR/pid"
33 # Verify if the current branch is valid before updating the working tree.
34 # This avoids errors with empty repositories which would only confuse the
36 if git rev-parse --verify HEAD >/dev/null 2>&1;
38 # git read-tree manual page says this is the proper way to fully repopulate
40 git config core.sparseCheckout true
41 rm -f "$GIT_DIR/info/sparse-checkout"
42 echo "/*" > "$GIT_DIR/info/sparse-checkout"
43 git read-tree -mu HEAD
44 git config core.sparseCheckout false