From: Antonio Ospite Date: Mon, 17 Dec 2018 09:03:10 +0000 (+0100) Subject: submodule-update.sh: check git version before running submodule commands X-Git-Url: https://git.ao2.it/config/vcsh.git/commitdiff_plain/6eede8729318d0419b32c0d9424297889a8e57b0?ds=sidebyside;hp=69069d2039555a14acb35d378ad14cb8430b9fb4 submodule-update.sh: check git version before running submodule commands Git submodules in vcsh can only be supported reliably with git >= 2.20.0 which supports reading the .gitmodules file even when it is not checked out in the working tree. To recap, the need for git >= 2.20 is imposed by the following facts: - vcsh repositories share their working trees in $HOME; - if files with the same name (e.g. README, LICENSE) are present in different repositories they would conflict when checked out in $HOME; - sparse-checkout can solve the issue by preventing colliding files between repositories from being checked out, this includes the .gitmodules file; - submodules command require the .gitmodules file; - from git 2.20 the .gitmodules file can be accessed from the repository object store when the file is not in the working tree, this enables submodules usage with "vcsh run". Now that the version check is in place, re-enable the post-clone hook to update submodules automatically after cloning a repository. --- diff --git a/.config/vcsh/hooks-available/submodule-update.sh b/.config/vcsh/hooks-available/submodule-update.sh index 34793ed..3f68fbc 100755 --- a/.config/vcsh/hooks-available/submodule-update.sh +++ b/.config/vcsh/hooks-available/submodule-update.sh @@ -1,4 +1,15 @@ #!/bin/sh +set -e + +GIT_VERSION_MAJOR=$(git --version | sed -n 's/.* \([0-9]\{1,\}\)\..*/\1/p' ) +GIT_VERSION_MINOR=$(git --version | sed -n 's/.* \([0-9]\{1,\}\)\.\([0-9]\{1,\}\).*/\2/p' ) + +if [ "$GIT_VERSION_MAJOR" -lt 2 ] || [ "$GIT_VERSION_MINOR" -lt 20 ]; +then + echo "Git >= 2.20 is required for submodules to work properly with vcsh" 1>&2 + exit 1 +fi + 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