From 6eede8729318d0419b32c0d9424297889a8e57b0 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Mon, 17 Dec 2018 10:03:10 +0100 Subject: [PATCH] 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. --- .config/vcsh/hooks-available/submodule-update.sh | 11 +++++++++++ .config/vcsh/hooks-enabled/post-clone.00-submodule-init | 1 + 2 files changed, 12 insertions(+) create mode 120000 .config/vcsh/hooks-enabled/post-clone.00-submodule-init 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 -- 2.1.4