diff --git a/src/git/devcontainer-feature.json b/src/git/devcontainer-feature.json index 87fb2ab3f..61125f2d1 100644 --- a/src/git/devcontainer-feature.json +++ b/src/git/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "git", - "version": "1.3.2", + "version": "1.3.3", "name": "Git (from source)", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/git", "description": "Install an up-to-date version of Git, built from source as needed. Useful for when you want the latest and greatest features. Auto-detects latest stable version and installs needed dependencies.", @@ -19,7 +19,12 @@ "type": "boolean", "default": true, "description": "Install from PPA if available (only supported for Ubuntu distributions)" - } + }, + "installSubtree": { + "type": "boolean", + "default": true, + "description": "Install git/contrib/subtree" + } }, "installsAfter": [ "ghcr.io/devcontainers/features/common-utils" diff --git a/src/git/install.sh b/src/git/install.sh index 976eb348d..c965f5503 100755 --- a/src/git/install.sh +++ b/src/git/install.sh @@ -9,6 +9,7 @@ GIT_VERSION=${VERSION} # 'system' checks the base image first, else installs 'latest' USE_PPA_IF_AVAILABLE=${PPA} +INSTALL_SUBTREE="${INSTALLSUBTREE:-"true"}" GIT_CORE_PPA_ARCHIVE_GPG_KEY=E1DD270288B4E6030699E45FA1715D88E1DF1F24 @@ -208,7 +209,32 @@ export DEBIAN_FRONTEND=noninteractive if [ ${GIT_VERSION} = "os-provided" ] || [ ${GIT_VERSION} = "system" ]; then if type git > /dev/null 2>&1; then echo "Detected existing system install: $(git version)" - # Clean up + if [[ $INSTALL_SUBTREE = "true" ]]; then + + if ! type make > /dev/null 2>&1; then + check_packages make + fi + if ! type asciidoc > /dev/null 2>&1; then + check_packages asciidoc + fi + if ! type xmlto > /dev/null 2>&1; then + check_packages xmlto + fi + if ! type tar > /dev/null 2>&1; then + check_packages tar + fi + if ! type curl > /dev/null 2>&1; then + check_packages curl + fi + cd /tmp/ + GIT_VERSION=$(git --version | awk '{print $3}') + curl -sL https://github.com/git/git/archive/v${GIT_VERSION}.tar.gz | tar -xzC /tmp 2>&1 + cd /tmp/git-${GIT_VERSION} + cd contrib/subtree + make && make install && make install-doc && cp git-subtree ../.. 2>&1 + cd ../../ + rm -rf /tmp/git-${GIT_VERSION} + fi clean_up exit 0 fi @@ -224,6 +250,41 @@ if [ ${GIT_VERSION} = "os-provided" ] || [ ${GIT_VERSION} = "system" ]; then check_packages ca-certificates fi check_packages git + if [[ $INSTALL_SUBTREE = "true" ]]; then + if ! type make > /dev/null 2>&1; then + check_packages make + fi + if ! type asciidoc > /dev/null 2>&1; then + check_packages asciidoc + fi + if ! type xmlto > /dev/null 2>&1; then + check_packages xmlto + fi + if ! type tar > /dev/null 2>&1; then + check_packages tar + fi + if ! type curl > /dev/null 2>&1; then + check_packages curl + fi + if ! type cmp > /dev/null 2>&1; then + check_packages diffutils + fi + cd /tmp/ + GIT_VERSION=$(git --version | awk '{print $3}') + curl -sL https://github.com/git/git/archive/v${GIT_VERSION}.tar.gz | tar -xzC /tmp 2>&1 + cd /tmp/git-${GIT_VERSION} + cd contrib/subtree + make && make install && make install-doc && cp git-subtree ../.. 2>&1 + cd ../../ + #For some base images such as alma, rocky, fedora git subtree feature doesn’t work + # even after successful subtree installation. This happens particularly when the git + # version provided by default is an old one. Adding the installation path specifically + # for them. + if [ -f "/usr/local/libexec/git-core/git-subtree" ]; then + echo 'export PATH=$PATH:/usr/local/libexec/git-core' >> ~/.bashrc + fi + rm -rf /tmp/git-${GIT_VERSION} + fi # Clean up clean_up exit 0 @@ -309,6 +370,11 @@ if [ "${ADJUSTED_ID}" = "alpine" ]; then git_options+=("NO_GETTEXT=YesPlease") fi make -s "${git_options[@]}" all && make -s "${git_options[@]}" install 2>&1 +if [[ $INSTALL_SUBTREE = "true" ]]; then + cd contrib/subtree/ + make && make install && make install-doc && cp git-subtree ../.. 2>&1 + cd ../../ +fi rm -rf /tmp/git-${GIT_VERSION} clean_up echo "Done!" diff --git a/test/git/scenarios.json b/test/git/scenarios.json index 0f5d522b3..35aee050f 100644 --- a/test/git/scenarios.json +++ b/test/git/scenarios.json @@ -116,15 +116,6 @@ } } }, - "install_git_from_src_mariner": { - "image": "mcr.microsoft.com/cbl-mariner/base/core:2.0", - "features": { - "git": { - "version": "latest", - "ppa": "false" - } - } - }, "install_git_from_system_alpine": { "image": "mcr.microsoft.com/devcontainers/base:alpine", "features": { @@ -187,14 +178,5 @@ "ppa": "true" } } - }, - "install_git_from_system_mariner": { - "image": "mcr.microsoft.com/cbl-mariner/base/core:2.0", - "features": { - "git": { - "version": "system", - "ppa": "true" - } - } } }