From patchwork Thu Aug 19 20:09:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12447923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD13EC432BE for ; Thu, 19 Aug 2021 20:10:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C41766108E for ; Thu, 19 Aug 2021 20:10:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234371AbhHSUKl (ORCPT ); Thu, 19 Aug 2021 16:10:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbhHSUKl (ORCPT ); Thu, 19 Aug 2021 16:10:41 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5127C061575 for ; Thu, 19 Aug 2021 13:10:04 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id k4-20020a25b284000000b0059844c88867so775089ybj.6 for ; Thu, 19 Aug 2021 13:10:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=svC2bw+hfNi7PDC0jKl0o27KlCYtB/u8DrVNCo35o0A=; b=pn2G3hevpRak+439JAYjc9AF11VyVzpcvKRJEQXMYlePaSR4h8CoCpOuThx3+/vzjQ /E2aLJdyfNipUApnEkxNi/gLYBuEETVODuEWd0B9rDazhnqlOdA8BJEpbyKCQl/WNEls xjvGpUmYgLdS1c4l11P71A0tNgmhXpD5RFJX6Tp8+b3EF/2RiGZSTkkjRIyGnp3y4Itr xLQipo+DGjpUZQ/Hj6nAT/4jYUvjJiZjoeu2Y9JbDpKYh6/7sX1q18+udf49v62RtGdM jO56/zc+nnQ3fW1bv54x9Kn63ERblTnkx4WkP7kaYQabWgXPTkrHKl+C2Z6/Y9tMK1T7 jBZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=svC2bw+hfNi7PDC0jKl0o27KlCYtB/u8DrVNCo35o0A=; b=GXdiR5QVNIw6z2aEv7/u9U73/KZztRMWX68M0XSHz5r0pLvhjzLgpcgnynXFaqQSMz bjYDVHT6zZZtGcJn6NCgBUEA3/nwff8E+Tl0RG7OjqxKPWgRgcLxCzgmUMOEQX/N6hJJ fSfS2lf024oOHIsV2MuyJiDhEohP+fwB3m3zDlav+Mt+SHJNR+TPSy/bSlNtiSCf1Qii CCu7tc83/Mgw5zFhv00TchpWsq/LnTwEKyUxBjQ2qeoA4ZzMTYTNhhUOVPVReigDPCLm Uu7VcvR67vts7rfuyH+uVQQWxPxNqnmR7vLwjxs7TDzz/wQ3uUnbCOd7fZy6N+xUrSe0 7RPA== X-Gm-Message-State: AOAM533TH3i26oTNjZZEY7EFweB1cTI2nm1ZXHyqrTxXsGqbVGW804VM traF3ueMi8PSHEHeQygX76zqp47veiXF8IGUaMLt6m076wtXHerinOqOpFqfYeiIc/smAxf4fb3 YmVDkSOl7iIq5WqS76WaiilEd5Sgc/RpkE2KhGySKebFudHkmjxHcx1Ts57Lrl2dtE93oGUkRPw == X-Google-Smtp-Source: ABdhPJxuOBMrqB9nxORA8cNMBbdUkpAdPzWQ0vogpJhYAd9xQndr0vw0jKgxTkKsGn83Z+aeI1NVxTSEhKDghrprx2c= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:200:5c:aa12:af53:acbb]) (user=emilyshaffer job=sendgmr) by 2002:a5b:f43:: with SMTP id y3mr20763541ybr.45.1629403803907; Thu, 19 Aug 2021 13:10:03 -0700 (PDT) Date: Thu, 19 Aug 2021 13:09:50 -0700 In-Reply-To: <20210819200953.2105230-1-emilyshaffer@google.com> Message-Id: <20210819200953.2105230-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20210819200953.2105230-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog Subject: [PATCH v3 1/4] t7400-submodule-basic: modernize inspect() helper From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since the inspect() helper in the submodule-basic test suite was written, 'git -C ' was added. By using -C, we no longer need a reference to the base directory for the test. This simplifies callsites, and will make the addition of other arguments in later patches more readable. Signed-off-by: Emily Shaffer --- t/t7400-submodule-basic.sh | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index a924fdb7a6..4bc6b6c886 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -107,23 +107,15 @@ test_expect_success 'setup - repository to add submodules to' ' # generates, which will expand symbolic links. submodurl=$(pwd -P) -listbranches() { - git for-each-ref --format='%(refname)' 'refs/heads/*' -} - inspect() { dir=$1 && - dotdot="${2:-..}" && - ( - cd "$dir" && - listbranches >"$dotdot/heads" && - { git symbolic-ref HEAD || :; } >"$dotdot/head" && - git rev-parse HEAD >"$dotdot/head-sha1" && - git update-index --refresh && - git diff-files --exit-code && - git clean -n -d -x >"$dotdot/untracked" - ) + git -C "$dir" for-each-ref --format='%(refname)' 'refs/heads/*' >heads && + { git -C "$dir" symbolic-ref HEAD || :; } >head && + git -C "$dir" rev-parse HEAD >head-sha1 && + git -C "$dir" update-index --refresh && + git -C "$dir" diff-files --exit-code && + git -C "$dir" clean -n -d -x >untracked } test_expect_success 'submodule add' ' @@ -146,7 +138,7 @@ test_expect_success 'submodule add' ' ) && rm -f heads head untracked && - inspect addtest/submod ../.. && + inspect addtest/submod && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -237,7 +229,7 @@ test_expect_success 'submodule add --branch' ' ) && rm -f heads head untracked && - inspect addtest/submod-branch ../.. && + inspect addtest/submod-branch && test_cmp expect-heads heads && test_cmp expect-head head && test_must_be_empty untracked @@ -253,7 +245,7 @@ test_expect_success 'submodule add with ./ in path' ' ) && rm -f heads head untracked && - inspect addtest/dotsubmod/frotz ../../.. && + inspect addtest/dotsubmod/frotz && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -269,7 +261,7 @@ test_expect_success 'submodule add with /././ in path' ' ) && rm -f heads head untracked && - inspect addtest/dotslashdotsubmod/frotz ../../.. && + inspect addtest/dotslashdotsubmod/frotz && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -285,7 +277,7 @@ test_expect_success 'submodule add with // in path' ' ) && rm -f heads head untracked && - inspect addtest/slashslashsubmod/frotz ../../.. && + inspect addtest/slashslashsubmod/frotz && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -301,7 +293,7 @@ test_expect_success 'submodule add with /.. in path' ' ) && rm -f heads head untracked && - inspect addtest/realsubmod ../.. && + inspect addtest/realsubmod && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -317,7 +309,7 @@ test_expect_success 'submodule add with ./, /.. and // in path' ' ) && rm -f heads head untracked && - inspect addtest/realsubmod2 ../.. && + inspect addtest/realsubmod2 && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -348,7 +340,7 @@ test_expect_success 'submodule add in subdirectory' ' ) && rm -f heads head untracked && - inspect addtest/realsubmod3 ../.. && + inspect addtest/realsubmod3 && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked From patchwork Thu Aug 19 20:09:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12447925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDC6DC4338F for ; Thu, 19 Aug 2021 20:10:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1AD0610CF for ; Thu, 19 Aug 2021 20:10:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234529AbhHSUKs (ORCPT ); Thu, 19 Aug 2021 16:10:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234511AbhHSUKn (ORCPT ); Thu, 19 Aug 2021 16:10:43 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0220EC061757 for ; Thu, 19 Aug 2021 13:10:07 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id b127-20020a25e485000000b005943f1efa05so7670704ybh.15 for ; Thu, 19 Aug 2021 13:10:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=CN/DOpPuJ1P1FOpYJ/QGBoBm1MZNCH2SXA7GrbHEwnc=; b=J5SsIyQhQJpp4a+Az9djjKeA1hithCFJ9XRx/AtRXhM6b1K09QL4KM2VlLsV/uNHMm XGw0bjtQkmRMcpi58ZDSQsvuHugtFoJIUfRbRW3zAKOa5kOXNmfFvOBiDr5iIA2ffaP2 S8FGHBfP91Z+JVAXjxUO+MVmhY7psa4QBl0TVAPlELvPHeF312Zv2r2BhIIdyP6ARN9m iVvJAM+4Gxt1qxVBss65qCwfpORrZrWxwNfte9VblIKPJsKPcvhJ1ydd5oePwMPE9JVM kQnlu97szt7Ob/dvew704vQZjFePnK+nlmUjSeHaffQoq7EjOovDeV62cWnPd6DqzL9A C6aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=CN/DOpPuJ1P1FOpYJ/QGBoBm1MZNCH2SXA7GrbHEwnc=; b=uMJPCvuwyI/GChJ+5mzm6ZNoNPgW4bUoZWXju9u1lHh4m7KtjJsSBXz5MXA6winK4I Fc2+Fs0UYjeEvOvDO41GrsBnVNSScm//5tstnn9tU5tGD7EYS0u3aD1MxMZQtqOtHIcN qeD/q/XIQCr9lBCHiqid7wFbEuQ3sYgYdJiCy4HT73SCUy7MbVaH3Vear52/67DHH681 dLFEDxUGpcnKFOfo9AaKbZh2VQZBxQmyw6AKhXMSFoIBb+2oNG04ZDbWjs2EOaCeuYkV VRb7c4/rNi3U6ycnBIAoBbyr7iuMNBxBPEv/sFh+OvfxYiQ13GSqj6EX/M1PQaUtET4t sd/g== X-Gm-Message-State: AOAM531XLUuSeGl4Hd+Y1c/EMmKxGBr10GrSQRgqNTJAVX9KLlBjtO3F z8EQq62JF1v18F4B+En/piwz5RGtYa3WpTodeiDq8664J99KJlTd1P2O0M8Hw+bvP78WkmOd+jB b5E/vOewV5bhh73sRmhR5ICdfL3UIlETQ4fTZbSX87DSLeeYJtWVX8XmdsaUL2VwHSzhrTSBC+g == X-Google-Smtp-Source: ABdhPJyyI+yM+umMPqXDxnh5jIvv4liSzj1H2mEBbNjn6Fi0CZ3xPVRQRPQVm7rAIIdPSijwbqhz56qhb6REquzzm2E= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:200:5c:aa12:af53:acbb]) (user=emilyshaffer job=sendgmr) by 2002:a25:818a:: with SMTP id p10mr20214870ybk.363.1629403806197; Thu, 19 Aug 2021 13:10:06 -0700 (PDT) Date: Thu, 19 Aug 2021 13:09:51 -0700 In-Reply-To: <20210819200953.2105230-1-emilyshaffer@google.com> Message-Id: <20210819200953.2105230-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20210819200953.2105230-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog Subject: [PATCH v3 2/4] introduce submodule.superprojectGitDir record From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer , Junio C Hamano Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Teach submodules a reference to their superproject's gitdir. This allows us to A) know that we're running from a submodule, and B) have a shortcut to the superproject's vitals, for example, configs. By using a relative path instead of an absolute path, we can move the superproject directory around on the filesystem without breaking the submodule's cache. Since this hint value is only introduced during new submodule creation via `git submodule add`, though, there is more work to do to allow the record to be created at other times. If the new config is present, we can do some optional value-added behavior, like letting "git status" print additional info about the submodule's status in relation to its superproject, or like letting the superproject and submodule share an additional config file separate from either one's local config. Signed-off-by: Emily Shaffer Helped-by: Junio C Hamano --- Documentation/config/submodule.txt | 15 +++++++++++ builtin/submodule--helper.c | 4 +++ t/t7400-submodule-basic.sh | 40 ++++++++++++++++-------------- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt index d7a63c8c12..23e0a01d90 100644 --- a/Documentation/config/submodule.txt +++ b/Documentation/config/submodule.txt @@ -90,3 +90,18 @@ submodule.alternateErrorStrategy:: `ignore`, `info`, `die`. Default is `die`. Note that if set to `ignore` or `info`, and if there is an error with the computed alternate, the clone proceeds as if no alternate was specified. + +submodule.superprojectGitDir:: + The relative path from the submodule's worktree to its superproject's + gitdir. When Git is run in a repository, it usually makes no difference + whether this repository is standalone or a submodule, but if this + configuration variable is present, additional behavior may be possible, + such as "git status" printing additional information about this + submodule's status with respect to its superproject. This config should + only be present in projects which are submodules, but is not guaranteed + to be present in every submodule, so only optional value-added behavior + should be linked to it. It is set automatically during + submodule creation. ++ + Because of this configuration variable, it is forbidden to use the + same submodule worktree shared by multiple superprojects. diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index d55f6262e9..d60fcd2c7d 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1910,6 +1910,10 @@ static int module_clone(int argc, const char **argv, const char *prefix) git_config_set_in_file(p, "submodule.alternateErrorStrategy", error_strategy); + git_config_set_in_file(p, "submodule.superprojectGitdir", + relative_path(absolute_path(get_git_dir()), + path, &sb)); + free(sm_alternate); free(error_strategy); diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 4bc6b6c886..e407329d81 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -108,14 +108,18 @@ test_expect_success 'setup - repository to add submodules to' ' submodurl=$(pwd -P) inspect() { - dir=$1 && - - git -C "$dir" for-each-ref --format='%(refname)' 'refs/heads/*' >heads && - { git -C "$dir" symbolic-ref HEAD || :; } >head && - git -C "$dir" rev-parse HEAD >head-sha1 && - git -C "$dir" update-index --refresh && - git -C "$dir" diff-files --exit-code && - git -C "$dir" clean -n -d -x >untracked + sub_dir=$1 && + super_dir=$2 && + + git -C "$sub_dir" for-each-ref --format='%(refname)' 'refs/heads/*' >heads && + { git -C "$sub_dir" symbolic-ref HEAD || :; } >head && + git -C "$sub_dir" rev-parse HEAD >head-sha1 && + git -C "$sub_dir" update-index --refresh && + git -C "$sub_dir" diff-files --exit-code && + cached_super_dir="$(git -C "$sub_dir" config --get submodule.superprojectGitDir)" && + [ "$(git -C "$super_dir" rev-parse --absolute-git-dir)" \ + -ef "$sub_dir/$cached_super_dir" ] && + git -C "$sub_dir" clean -n -d -x >untracked } test_expect_success 'submodule add' ' @@ -138,7 +142,7 @@ test_expect_success 'submodule add' ' ) && rm -f heads head untracked && - inspect addtest/submod && + inspect addtest/submod addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -229,7 +233,7 @@ test_expect_success 'submodule add --branch' ' ) && rm -f heads head untracked && - inspect addtest/submod-branch && + inspect addtest/submod-branch addtest && test_cmp expect-heads heads && test_cmp expect-head head && test_must_be_empty untracked @@ -245,7 +249,7 @@ test_expect_success 'submodule add with ./ in path' ' ) && rm -f heads head untracked && - inspect addtest/dotsubmod/frotz && + inspect addtest/dotsubmod/frotz addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -261,7 +265,7 @@ test_expect_success 'submodule add with /././ in path' ' ) && rm -f heads head untracked && - inspect addtest/dotslashdotsubmod/frotz && + inspect addtest/dotslashdotsubmod/frotz addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -277,7 +281,7 @@ test_expect_success 'submodule add with // in path' ' ) && rm -f heads head untracked && - inspect addtest/slashslashsubmod/frotz && + inspect addtest/slashslashsubmod/frotz addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -293,7 +297,7 @@ test_expect_success 'submodule add with /.. in path' ' ) && rm -f heads head untracked && - inspect addtest/realsubmod && + inspect addtest/realsubmod addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -309,7 +313,7 @@ test_expect_success 'submodule add with ./, /.. and // in path' ' ) && rm -f heads head untracked && - inspect addtest/realsubmod2 && + inspect addtest/realsubmod2 addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -340,7 +344,7 @@ test_expect_success 'submodule add in subdirectory' ' ) && rm -f heads head untracked && - inspect addtest/realsubmod3 && + inspect addtest/realsubmod3 addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -481,7 +485,7 @@ test_expect_success 'update should work when path is an empty dir' ' git submodule update -q >update.out && test_must_be_empty update.out && - inspect init && + inspect init . && test_cmp expect head-sha1 ' @@ -540,7 +544,7 @@ test_expect_success 'update should checkout rev1' ' echo "$rev1" >expect && git submodule update init && - inspect init && + inspect init . && test_cmp expect head-sha1 ' From patchwork Thu Aug 19 20:09:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12447927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 884BBC4320A for ; Thu, 19 Aug 2021 20:10:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72E6561075 for ; Thu, 19 Aug 2021 20:10:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229514AbhHSUKt (ORCPT ); Thu, 19 Aug 2021 16:10:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234839AbhHSUKr (ORCPT ); Thu, 19 Aug 2021 16:10:47 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C277C0613D9 for ; Thu, 19 Aug 2021 13:10:09 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id s4-20020ad44b24000000b0035c77ac6861so5352174qvw.0 for ; Thu, 19 Aug 2021 13:10:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=GtDJwGeOmkpjVKgwAk3YCpxAa9e5dXZn18GHFSpKqAg=; b=KIWolS83jTMd6hgyvso/gEwkisVCHrUPn5AZtfwZAL/DMptRxWjSkNavJuI+IaMvFL PV0jNOhtIzlV5NmN/Oqk/zSI4r1iQa8QrGtwPTsGgbrBYLDK2wqWwGAHF7x6g5TwRhxS kEpsfVTw7wm+OfzJqJ5uamhk55akMAs5ExfwsHD79wGdPZ7Qv/XR+Zig3N2asxZWIMoU JPVNQLGXzpcXZgB8rL5CulC3jpyKDmOxPOW18Ru7nO9Woj5ewnYZogP2A9ODiemE8E4v ZFz4bwX7KMayluw7ntxHyU1TKLxzqOmJs9gzf818NVIhgCuqF/aBTR0YhAGeMRtVufoY W0Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=GtDJwGeOmkpjVKgwAk3YCpxAa9e5dXZn18GHFSpKqAg=; b=WOFfAKz/iVleNrqFZdzBQT7mPeh/JVCp79Na+3C2E2BnjPFGZx442MR4y6fF9REVFd K8kqAVHHvAMd/2jd+bekwHU8ShETVpE3PkmSZqluYqKjWnBbhm5g/0IPMEDJQbSLXFdo EioRXmCw1mCsnjvc9DX3PjRLiNSySxPr4O/pc8UNlpYOhncZdfseBCFzGdLUQpCDqu7k nzlx+sjt5G2h6SsT3AS+fDsf9syb4mjmQAoE2WvxWuUODO3TlT0jF8wzqFN0U3mliPBQ M0y+OeYlbafk168xAKUh0YjMWwHbB6w21xFzeBbQs7Xdnb+vH7BQLiQmqB5tLeJALr8T osZw== X-Gm-Message-State: AOAM531/0kdLTMWwRgwbdFy6xPcIM5TGOd6aSb1UKVXliLstxgRN3twd 1LfR7vzO+nJFug5pIV7e2ZM+DoapuS1CU+adzQgMg/EOFl/HXepAykejIW+nm5eRpt3t4IOQIpn 3G3e0u4eGSnW5wwt62RHtx0d2NoY0wXs9QL+1Aat32JgEiV/phQwmgITbHCihhDC71VSlmgYzEQ == X-Google-Smtp-Source: ABdhPJz84xyIT1vvrPEQBEbks/8t3bDFznBWDhImayVC1drOtsjQSDFe24GolifQBp/O/x7Pd+LmzRSslofCNAKAgBw= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:200:5c:aa12:af53:acbb]) (user=emilyshaffer job=sendgmr) by 2002:a0c:fca2:: with SMTP id h2mr7124008qvq.5.1629403808409; Thu, 19 Aug 2021 13:10:08 -0700 (PDT) Date: Thu, 19 Aug 2021 13:09:52 -0700 In-Reply-To: <20210819200953.2105230-1-emilyshaffer@google.com> Message-Id: <20210819200953.2105230-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20210819200953.2105230-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog Subject: [PATCH v3 3/4] submodule: record superproject gitdir during absorbgitdirs From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Already during 'git submodule add' we record a pointer to the superproject's gitdir. However, this doesn't help brand-new submodules created with 'git init' and later absorbed with 'git submodule absorbgitdir'. Let's start adding that pointer during 'git submodule absorbgitdir' too. Signed-off-by: Emily Shaffer --- submodule.c | 10 ++++++++++ t/t7412-submodule-absorbgitdirs.sh | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/submodule.c b/submodule.c index 0b1d9c1dde..4b314bf09c 100644 --- a/submodule.c +++ b/submodule.c @@ -2065,6 +2065,7 @@ static void relocate_single_git_dir_into_superproject(const char *path) char *old_git_dir = NULL, *real_old_git_dir = NULL, *real_new_git_dir = NULL; char *new_git_dir; const struct submodule *sub; + struct strbuf config_path = STRBUF_INIT, sb = STRBUF_INIT; if (submodule_uses_worktrees(path)) die(_("relocate_gitdir for submodule '%s' with " @@ -2096,6 +2097,15 @@ static void relocate_single_git_dir_into_superproject(const char *path) relocate_gitdir(path, real_old_git_dir, real_new_git_dir); + /* cache pointer to superproject's gitdir */ + /* NEEDSWORK: this may differ if experimental.worktreeConfig is enabled */ + strbuf_addf(&config_path, "%s/config", real_new_git_dir); + git_config_set_in_file(config_path.buf, "submodule.superprojectGitdir", + relative_path(get_super_prefix_or_empty(), + path, &sb)); + + strbuf_release(&config_path); + strbuf_release(&sb); free(old_git_dir); free(real_old_git_dir); free(real_new_git_dir); diff --git a/t/t7412-submodule-absorbgitdirs.sh b/t/t7412-submodule-absorbgitdirs.sh index 1cfa150768..e2d78e01df 100755 --- a/t/t7412-submodule-absorbgitdirs.sh +++ b/t/t7412-submodule-absorbgitdirs.sh @@ -30,7 +30,14 @@ test_expect_success 'absorb the git dir' ' git status >actual.1 && git -C sub1 rev-parse HEAD >actual.2 && test_cmp expect.1 actual.1 && - test_cmp expect.2 actual.2 + test_cmp expect.2 actual.2 && + + # make sure the submodule cached the superproject gitdir correctly + test-tool path-utils real_path . >expect && + test-tool path-utils real_path \ + "$(git -C sub1 config submodule.superprojectGitDir)" >actual && + + test_cmp expect actual ' test_expect_success 'absorbing does not fail for deinitialized submodules' ' From patchwork Thu Aug 19 20:09:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12447929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A290C432BE for ; Thu, 19 Aug 2021 20:10:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 359E6610D2 for ; Thu, 19 Aug 2021 20:10:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234903AbhHSUKu (ORCPT ); Thu, 19 Aug 2021 16:10:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234838AbhHSUKs (ORCPT ); Thu, 19 Aug 2021 16:10:48 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71D87C061756 for ; Thu, 19 Aug 2021 13:10:11 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id x10-20020a05622a000ab02902982df43057so3415346qtw.9 for ; Thu, 19 Aug 2021 13:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=1qdRTQjSkrijWEztupM+Dn+VxpuMQu76dkre4l8ppG8=; b=jiYdA8ypaeCPY+slT7QEgywvndhS9xpzyq4Cc+EQxHRnIxZX0PYnOfrRKw7cF5u8OV u5WCKLSMEg2MztBZeimudWIMgIyDWadSnP2TfrbwM9PZO+EPJxbwzQsFJ4mIjUEjaq4y xM+8g4aa6guFtYQYjXniJk88rEZ2fYkQgUiYq0L9xymYQVG4b+7ubggWEXOV7Et27XZX hDlBFTX83UVjBfMGlPgoh5pp+oIua0L+CrjVyPJg2l7zikha60Qm4qBMvEu2bwoSwe6M u6hdWyh7Xp61DA7blRvQi/Hp1qrqE5MO3It7GT6qSq9sp3iM+VMlswKuccf3cTSek8PN fSIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1qdRTQjSkrijWEztupM+Dn+VxpuMQu76dkre4l8ppG8=; b=CXvhZRabSHZ3iz2+siC4Mx9rM72H14GS1ZqjaBtbPU45+WWpua23mAqxkr+o6mMYyZ xTRkGwbzAXTdnVfx5SFkJyy1Wu2aTG96whFo7OgvfYgBEUJeTJZK8cGUNVFj7yDipORM q+d8WuP0C2y3hZr+ErnKVGaOrWEmtvIGr7qcMoiXyKppatWidxgxYLsCez7BJeWasBEW X+7r9y6n+hcHEULRMs+3PBOAD5zeOZKIzNRaJYXQZXbAdH3h32ox5246zXOTDWNyziXp vx2a+SPSAbBx46YGWyYhg0lrMJrWkroRgnBHQzINZu4hSKlUaordciJ9+Bt3TVLe7ppf 6Whg== X-Gm-Message-State: AOAM532KHltAktkMCI8euTNWMctt1hkuDuo6P3mJkqkNA60tSjFVgIuS FCd9qC9xJj6JeYWiKG5HuLsb+wAYbNOl8663AzezXwEP/vMSk6hI63DbEDf7yxJEpn6RE7CbAoo ai42m7rbb67uDUlzJIwo//sN7rVy/zoajExJhipOToh6OsH+St4ZuHzwz4omFZopfyufDCnwQwg == X-Google-Smtp-Source: ABdhPJwhJYk9fK6bf0M/Y7ZW4oLEYQufnHBMtcPjxbsetea9eBOHeSbvwRq0i+yO4tFqpwLbbi/oZ4XFG1t/enn/ejM= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:200:5c:aa12:af53:acbb]) (user=emilyshaffer job=sendgmr) by 2002:a05:6214:126:: with SMTP id w6mr16377166qvs.61.1629403810601; Thu, 19 Aug 2021 13:10:10 -0700 (PDT) Date: Thu, 19 Aug 2021 13:09:53 -0700 In-Reply-To: <20210819200953.2105230-1-emilyshaffer@google.com> Message-Id: <20210819200953.2105230-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20210819200953.2105230-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog Subject: [PATCH v3 4/4] submodule: record superproject gitdir during 'update' From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A recorded hint path to the superproject's gitdir might be added during 'git submodule add', but in some cases - like submodules which were created before 'git submodule add' learned to record that info - it might be useful to update the hint. Let's do it during 'git submodule update', when we already have a handle to the superproject while calling operations on the submodules. Signed-off-by: Emily Shaffer --- git-submodule.sh | 10 ++++++++++ t/t7406-submodule-update.sh | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/git-submodule.sh b/git-submodule.sh index 4678378424..f98dcc16ae 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -648,6 +648,16 @@ cmd_update() fi fi + # Cache a pointer to the superproject's gitdir. This may have + # changed, so rewrite it unconditionally. Writes it to worktree + # if applicable, otherwise to local. + relative_gitdir="$(git rev-parse --path-format=relative \ + --prefix "${sm_path}" \ + --git-dir)" + + git -C "$sm_path" config --worktree \ + submodule.superprojectgitdir "$relative_gitdir" + if test -n "$recursive" then ( diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index f4f61fe554..c39821ba8e 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1061,4 +1061,14 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s ) ' +test_expect_success 'submodule update adds superproject gitdir to older repos' ' + (cd super && + git -C submodule config --unset submodule.superprojectGitdir && + git submodule update && + echo "../.git" >expect && + git -C submodule config submodule.superprojectGitdir >actual && + test_cmp expect actual + ) +' + test_done