From: Antonio Ospite Date: Tue, 8 May 2018 07:48:34 +0000 (+0200) Subject: Initial import X-Git-Url: https://git.ao2.it/config/vcsh.git/commitdiff_plain/e7109b26ca3742d660d77df5a94326297f00eaa0?ds=sidebyside Initial import --- e7109b26ca3742d660d77df5a94326297f00eaa0 diff --git a/.config/vcsh/hooks-available/populate-fully.sh b/.config/vcsh/hooks-available/populate-fully.sh new file mode 100755 index 0000000..46e155f --- /dev/null +++ b/.config/vcsh/hooks-available/populate-fully.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +# Only one vcsh instance at a time can have the work dir fully populated. +LOCKDIR=/run/lock/vcsh + +# Kill the parent process because vcsh does not catch the hook exit value. +# See: https://github.com/RichiH/vcsh/issues/251 +mkdir "$LOCKDIR" 2>/dev/null || { echo "An instance of vcsh already entered a repository." 1>&2; kill -- -$PPID;} + +# Lock on the parent pid because the hooks are launched as children of vcsh. +echo $PPID > "$LOCKDIR/pid" + +# git read-tree manual page says this is the proper way to fully repopulate +# the working directory +git config core.sparseCheckout true +rm -f "$GIT_DIR/info/sparse-checkout" +echo "/*" > "$GIT_DIR/info/sparse-checkout" +git read-tree -mu HEAD +git config core.sparseCheckout false diff --git a/.config/vcsh/hooks-available/populate-sparsely.sh b/.config/vcsh/hooks-available/populate-sparsely.sh new file mode 100755 index 0000000..a49e4b4 --- /dev/null +++ b/.config/vcsh/hooks-available/populate-sparsely.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -e + +# Only the same instance of vcsh that had the work dir fully populated is +# allowed to repopulate it sparsely. +LOCKDIR=/run/lock/vcsh +LOCKPID=$(cat "$LOCKDIR/pid") +# Use the parent pid because the hooks are launched as children of vcsh. +[ "$LOCKPID" = $PPID ] || { echo "Repository entered from another vcsh instance. Aborting." 1>&2; exit 1; } + +: "${XDG_CONFIG_HOME:="$HOME/.config"}" +. "$XDG_CONFIG_HOME/vcsh/hooks-available/sparse-checkout.sh" +git read-tree -mu HEAD + +# Unlock the work dir. +rm -rf "$LOCKDIR" diff --git a/.config/vcsh/hooks-available/sparse-checkout.sh b/.config/vcsh/hooks-available/sparse-checkout.sh new file mode 100755 index 0000000..b23909d --- /dev/null +++ b/.config/vcsh/hooks-available/sparse-checkout.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +: "${XDG_CONFIG_HOME:="$HOME/.config"}" + +git config core.sparseCheckout true +rm -f "$GIT_DIR/info/sparse-checkout" +ln -s "$XDG_CONFIG_HOME/vcsh/sparse-checkout" "$GIT_DIR/info/sparse-checkout" diff --git a/.config/vcsh/hooks-available/submodule-update.sh b/.config/vcsh/hooks-available/submodule-update.sh new file mode 100755 index 0000000..34793ed --- /dev/null +++ b/.config/vcsh/hooks-available/submodule-update.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +git submodule sync --recursive +git submodule update --init --recursive diff --git a/.config/vcsh/hooks-enabled/post-clone.00-submodule-init b/.config/vcsh/hooks-enabled/post-clone.00-submodule-init new file mode 120000 index 0000000..fc302b7 --- /dev/null +++ b/.config/vcsh/hooks-enabled/post-clone.00-submodule-init @@ -0,0 +1 @@ +../hooks-available/submodule-update.sh \ No newline at end of file diff --git a/.config/vcsh/hooks-enabled/post-enter.00-populate-sparsely b/.config/vcsh/hooks-enabled/post-enter.00-populate-sparsely new file mode 120000 index 0000000..20dd6f6 --- /dev/null +++ b/.config/vcsh/hooks-enabled/post-enter.00-populate-sparsely @@ -0,0 +1 @@ +../hooks-available/populate-sparsely.sh \ No newline at end of file diff --git a/.config/vcsh/hooks-enabled/post-pull.00-submodule-init b/.config/vcsh/hooks-enabled/post-pull.00-submodule-init new file mode 120000 index 0000000..fc302b7 --- /dev/null +++ b/.config/vcsh/hooks-enabled/post-pull.00-submodule-init @@ -0,0 +1 @@ +../hooks-available/submodule-update.sh \ No newline at end of file diff --git a/.config/vcsh/hooks-enabled/pre-enter.00-populate-fully b/.config/vcsh/hooks-enabled/pre-enter.00-populate-fully new file mode 120000 index 0000000..8bdf4fb --- /dev/null +++ b/.config/vcsh/hooks-enabled/pre-enter.00-populate-fully @@ -0,0 +1 @@ +../hooks-available/populate-fully.sh \ No newline at end of file diff --git a/.config/vcsh/hooks-enabled/pre-upgrade.00-sparse-checkout b/.config/vcsh/hooks-enabled/pre-upgrade.00-sparse-checkout new file mode 120000 index 0000000..2a2ca43 --- /dev/null +++ b/.config/vcsh/hooks-enabled/pre-upgrade.00-sparse-checkout @@ -0,0 +1 @@ +../hooks-available/sparse-checkout.sh \ No newline at end of file diff --git a/.config/vcsh/sparse-checkout b/.config/vcsh/sparse-checkout new file mode 100644 index 0000000..485e4a5 --- /dev/null +++ b/.config/vcsh/sparse-checkout @@ -0,0 +1,6 @@ +/* +!/.gitattributes +!/.gitignore +!/.gitmodules +!/LICENSE* +!/README* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8235482 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +* +!/.config +!/.config/vcsh +!/.config/vcsh/hooks-available +!/.config/vcsh/hooks-available/populate-fully.sh +!/.config/vcsh/hooks-available/populate-sparsely.sh +!/.config/vcsh/hooks-available/sparse-checkout.sh +!/.config/vcsh/hooks-available/submodule-update.sh +!/.config/vcsh/hooks-enabled +!/.config/vcsh/hooks-enabled/post-clone.00-submodule-init +!/.config/vcsh/hooks-enabled/post-enter.00-populate-sparsely +!/.config/vcsh/hooks-enabled/post-pull.00-submodule-init +!/.config/vcsh/hooks-enabled/pre-enter.00-populate-fully +!/.config/vcsh/hooks-enabled/pre-upgrade.00-sparse-checkout +!/.config/vcsh/sparse-checkout +!/.gitignore +!/README diff --git a/README b/README new file mode 100644 index 0000000..bc44f6e --- /dev/null +++ b/README @@ -0,0 +1,14 @@ +vcsh configuration to handle collisions of files common to distinct vcsh +repositories using the sparse-checkout functionality of git. + +The patterns for the colliding files are in .config/vcsh/sparse-checkout and +a pre-upgrade hook is used to make vcsh repositories use it. + +Many git commands (e.g. git-merge, git-checkout) will automatically use the +information in $GIT_DIR/info/sparse-checkout when dealing with files in the +git work directory, so generally a calling git-read-tree explicitly is not +needed. + +However when the content of $GIT_DIR/info/sparse-checkout changes it is +necessary to call "git read-tree -mu HEAD" to update the content of the +working directory.