From patchwork Thu Feb 3 21:59:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12734690 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2F0DC433EF for ; Thu, 3 Feb 2022 21:59:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355615AbiBCV71 (ORCPT ); Thu, 3 Feb 2022 16:59:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234897AbiBCV7Y (ORCPT ); Thu, 3 Feb 2022 16:59:24 -0500 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 B6799C061714 for ; Thu, 3 Feb 2022 13:59:23 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id u11-20020a25ab0b000000b0061a3e951dceso8741055ybi.15 for ; Thu, 03 Feb 2022 13:59:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=so/6OrSdbV/cyutuX/kcHN5Omtld7AewWEJGXcwjGrU=; b=cfqGqJJ8JlPP82+Yi7BqYTQjmD3u1VrlWdk8HRO79WHLVtQ9PWe3WoQFb5djXnXnd1 /7a50edj4PfAnJRrfFtMqzROyBB1ISNL0lXLVlf/vGMHS5GpFKiUf+AVHJO01rn2YSKI 8ukNeR/EWgFIotsb5rt+sxBJey0BoUkVFIpjaxzByemxzA1cKPJMVAbSL7vOzUMy6t7V O1x/EZWXO0kQcqnVp3kt75MSLTQneKxMd8sXyI1hSQNmpS7WHTPh8DgIJNTklyOJqWS4 ShfFFv9rhHFQCleTwDc2R1KxISfoh2GpCbiOWXxkNDLrJMid3jX0ipXGHenF2xPCE7ND UdBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=so/6OrSdbV/cyutuX/kcHN5Omtld7AewWEJGXcwjGrU=; b=2Cq80VXMWTYhKWtdzfBh2bKf0EvuTjf/b/5321Qi2i4P0CH1GM4Ipg1MiGVPg4bKpz JOiJ+UJ3Z9Gf0e4o5/VUTFW1Wz/y4u5p6pmIVTUGBqjW7iAiw4dKU5+YtE0MElRXYAMs NBNDk5PpuwVUCFSJSLEerWVqZvzgiVHAYElnq5ub0B8tqi9TZbPYyFZA/CRAIYNlNgk1 VrFI4B2tOKcvsnmH74q/IUVazR8sshhXK48oSUAx3n2rA2LyMMLodVedX+l4W6CuYFzd c5TkoF8+AUlJPG+PpZ9XIqmdqg/nlB7r/OVRvlbJ/DodHY8Hh1B+55ARGOcnIhYdS84F mLKQ== X-Gm-Message-State: AOAM5330rY9nukeiIM8Ow9vHtXJh3jfb5IXWhVGQtp1yWmmtIHNbObIR sKHDvCBsGfrMww49DWsoTJqfYTBQDmaD7kdNskSqK7AXiQwjhviadJKatNME+XfIDKl9LXlLJjq RwE24Oh4dmNRgRYFiO6n16T1AURPKqo7a31JzIWe5+C88wecar1IhvlcnB3zD2Xnu9E4JB1975w == X-Google-Smtp-Source: ABdhPJziXKpNbvKOc3MW7H+xIFmeD7Rec2KwenzGwS6CZVsixWelOOQevOwazapJOqXBxedvS6kxDeGDGhjFYBvhpWc= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:200:662:cd2f:9dc:846b]) (user=emilyshaffer job=sendgmr) by 2002:a25:783:: with SMTP id 125mr219789ybh.58.1643925562931; Thu, 03 Feb 2022 13:59:22 -0800 (PST) Date: Thu, 3 Feb 2022 13:59:11 -0800 In-Reply-To: <20220203215914.683922-1-emilyshaffer@google.com> Message-Id: <20220203215914.683922-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20220203215914.683922-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v7 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 | 40 +++++++++++++++----------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index e7cec2e457..40cf8d89aa 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" - ) + sub_dir=$1 && + + 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 && + git -C "$sub_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 @@ -248,7 +240,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 @@ -264,7 +256,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 @@ -280,7 +272,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 @@ -296,7 +288,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 @@ -312,7 +304,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 @@ -328,7 +320,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 @@ -359,7 +351,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 Feb 3 21:59:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12734691 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18442C433FE for ; Thu, 3 Feb 2022 21:59:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355622AbiBCV72 (ORCPT ); Thu, 3 Feb 2022 16:59:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355621AbiBCV70 (ORCPT ); Thu, 3 Feb 2022 16:59:26 -0500 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 2C927C061401 for ; Thu, 3 Feb 2022 13:59:26 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id t91-20020a25aae4000000b0061963cce3c1so8765299ybi.11 for ; Thu, 03 Feb 2022 13:59:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=otm8OsOeKhmWIBjc8HOa6cAJ7QsBOJqukpdmbJe/fAE=; b=GTW/IyXr/A5mfnXWaqjGx9WIwXeSmXqpyz8DoK1ylge7A/dwGcBUR2Ec5iXeOIfvJp UpTVblsuUAooRTurOUHjHaSPurl/sEMyHdyGtEi1SHY/WhXkWZT/9XT3+x5wVyzkbM3u PjkdWLmx6qJSg08rnoPX41blbLA0I8f/ECMGr9VNhRvnwsBUkQpeSN3pnTbrHiHhNNNp CZok5lMDcBHCp5Vxztg9IjnwhonEnV66NcY1Wgmj28RzS7zcQ5vjkL05hG4c3+hvjq+z weMmiU9a9s/iE2/iuRLlUO2AhxoQoZ7VJ4ivmpt+sP6a9xHOSH9uhxhLZTB3eYZ4Fn5m vYEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=otm8OsOeKhmWIBjc8HOa6cAJ7QsBOJqukpdmbJe/fAE=; b=u2cmk3eenVgwrQMB78x60Bhrr2KYwMET04y8tF9k71WPFGd9Fw+/R+Hvrl7ZQPzqLC L2ruRxCOvJZccKk6axqUotiAnqNfTXyoc/AIUBZM6lMHstPTmMvwGo4BCc0+0XFyKlIp mm/6XeU3fjml2o9VCu9xmiu1Wo13IvSg2T3p5pFnJ/xdedP//qPYkIThMoBjYLtF19oQ BA66KgDalp+97Tlp17Sj/IpAju3jpJJ5C8csHmLp2O9QZRe61wTbqUgfP0rHkhtGelqm m+j17S+RvwGqosFOA7Q/KYvd7LqkNKpzr2adFkRwnMzOyUIOwnCFdzy3udzOBRQnSpKc yW9w== X-Gm-Message-State: AOAM533pDhlatkPoyD1fSoPSn6MpuLPN+dd7QlhflGZJ2/2JorbFMyYk ViRFf8wQ4L79zjCe4sIwC2dUA0iJQxa6rJi5siNyvBaO4hrRXa8ZeFp8DxnMSnYxr672CVv8ISo AP8z1XfT9IpisJY47cuMJZCWsZRC82v7Qorgvl0ydCsShaUNqrkx45tcV2HemFNZyr4iLdIQO4g == X-Google-Smtp-Source: ABdhPJygU/ZI0WM98goNHDBiGDxQhv8v5feiLnYySNwhFAa2veb28jmBkH1lCbpJdCj/rKvmhiWjbr3z1EfTjILSvHo= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:200:662:cd2f:9dc:846b]) (user=emilyshaffer job=sendgmr) by 2002:a81:3986:: with SMTP id g128mr103437ywa.129.1643925565311; Thu, 03 Feb 2022 13:59:25 -0800 (PST) Date: Thu, 3 Feb 2022 13:59:12 -0800 In-Reply-To: <20220203215914.683922-1-emilyshaffer@google.com> Message-Id: <20220203215914.683922-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20220203215914.683922-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v7 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 config variable referencing to their superproject's gitdir. Git commands can rely on this reference to determine whether the current repo is a submodule to another repo. If this reference is absent, Git may assume the current repo is not a submodule. In practice, some commands which specifically reference the submodule relationship, like 'git rev-parse --show-superproject-working-tree', will still search the parent directory. Other newly added or implicit behavior, such as "git status" showing the submodule's status in relation to the superproject, or a config which is shared between the superproject and the submodule, should not search the parent directory and instead rely on this "submodule.superprojectGitDir" config. 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 pointer. And by using the path from gitdir to gitdir, we can move the submodule within the superproject's tree structure without breaking the submodule's pointer, too. Finally, by pointing at the superproject's worktree gitdir (if it exists), we ensure that we can tell which worktree contains our submodule. This commit teaches "git submodule add" to add the aformentioned config variable. Subsequent commits will teach other commands to do so. Signed-off-by: Emily Shaffer Helped-by: Junio C Hamano --- Documentation/config/submodule.txt | 8 ++++++++ builtin/submodule--helper.c | 11 ++++++++++ t/t7400-submodule-basic.sh | 32 ++++++++++++++++++++---------- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt index ee454f8126..bebd25684e 100644 --- a/Documentation/config/submodule.txt +++ b/Documentation/config/submodule.txt @@ -91,3 +91,11 @@ 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:: + If this repository is a submodule, the relative path from this repo's + gitdir to its superproject's gitdir. Git commands may rely on this + reference to determine whether the current repo is a submodule to + another repo; if this reference is absent, Git will treat the current + repo as though it is not a submodule (this does not make a difference to + most Git commands). It is set automatically during submodule creation. diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index c5d3fc3817..0485b384a1 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1839,6 +1839,17 @@ static int clone_submodule(struct module_clone_data *clone_data) git_config_set_in_file(p, "submodule.alternateErrorStrategy", error_strategy); + /* + * Set the path from submodule's new gitdir to superproject's gitdir. + * The latter may be a worktree gitdir. However, it is not possible for + * the submodule to have a worktree-specific gitdir or config at clone + * time, because "extensions.worktreeConfig" is only valid when set in + * the local gitconfig, which the brand new submodule does not have yet. + */ + git_config_set_in_file(p, "submodule.superprojectGitDir", + relative_path(absolute_path(get_git_dir()), + sm_gitdir, &sb)); + free(sm_alternate); free(error_strategy); diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 40cf8d89aa..7e4cc89bf5 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -109,12 +109,24 @@ submodurl=$(pwd -P) inspect() { 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 && + + # Ensure that submodule.superprojectGitDir contains the path from the + # submodule's gitdir to the superproject's gitdir. + + super_abs_gitdir=$(git -C "$super_dir" rev-parse --absolute-git-dir) && + sub_abs_gitdir=$(git -C "$sub_dir" rev-parse --absolute-git-dir) && + + [ "$(git -C "$sub_dir" config --get submodule.superprojectGitDir)" = \ + "$(test-tool path-utils relative_path "$super_abs_gitdir" \ + "$sub_abs_gitdir")" ] && + git -C "$sub_dir" clean -n -d -x >untracked } @@ -138,7 +150,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 @@ -240,7 +252,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 @@ -256,7 +268,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 @@ -272,7 +284,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 @@ -288,7 +300,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 @@ -304,7 +316,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 @@ -320,7 +332,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 @@ -351,7 +363,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 @@ -492,7 +504,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 ' @@ -551,7 +563,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 Feb 3 21:59:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12734692 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3274FC433EF for ; Thu, 3 Feb 2022 21:59:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355635AbiBCV7a (ORCPT ); Thu, 3 Feb 2022 16:59:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355617AbiBCV72 (ORCPT ); Thu, 3 Feb 2022 16:59:28 -0500 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 4EE6AC061714 for ; Thu, 3 Feb 2022 13:59:28 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id u185-20020a2560c2000000b0060fd98540f7so8940460ybb.0 for ; Thu, 03 Feb 2022 13:59:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=0bW3HvWq+MNcSsDABqymNS//hevwrVMJvogQTZn5SyI=; b=b+6vy1wSH+QP2rGEbAnl0bGlfFHJwFto4VW+9tSd4ughcxMHSWtSzdSxtozcQxTdRp y7gFj8e+A1rlSPrIOI+OJGzIvnHU/PXNRhQ7sq5ag5roveSysd5+cS0HQBQyEIwyREUU OLtELHFhkazHdZON98Mo/5z0jF9IQK26bLVKhcuR+Z9dOCCBJKtZx2hx1lKbtUdLnqBH Mbr1pvXJYiw4jYKM6I+o0UVNCpncIt6Q7Ia1fwVSmTiqQ4H60RF2oubu3fosQsm52yEa BvKt0N35/ZZxNZFNbbjNRtiIAqddWkC94TRJ9NUlR9Y58bUt+2JVJTd6PPas7C0aNrOR Z4TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=0bW3HvWq+MNcSsDABqymNS//hevwrVMJvogQTZn5SyI=; b=kLD8YrOqLLJWuzgP9/5UrnK7ufXgeF23hlm7p++8yqL476KrrJg4Z9IcRkeirTqI7I qI+86WhgZwleGZ1dZYq4nOYwIkIEllqR77CeSgd6Bz0sWM3plq7DX1pas11Pe0z0cPSK z5Tyy+v+Et0WoxGoUp00OTletX9cvQf/Q8MWxuVKm/Cu6/YqMUi8b7owyNLIttb2Gi9F kaa88EISEdWdBUByF1ydNhkyAFQ0TIJ2ig7mzrovHFC+bPmfVbCY3QoRERiKJCDvnah8 4k16zOFF4npZoVF1JX3aeXq0m+CN4f+Vz6BUwqZdJN12u/57ezVqTDcoGoNyPsXwNpWD tkaw== X-Gm-Message-State: AOAM533yiBhmG50ZlrAGNZg1PhcuyE4+C86l0B+26npHAbIahzfUYXtf pXAIxlrpGgNmlNwjV+VbLbS6L1YlcG5cGA+QaiGQ/AZxuT+MUtLvqLFvIe1lUq3L7UCcAShI3Yd koRqkfpUZOzZizVeOsBR5ePwAkUzzc9JOPW2euF/iQ3LVNmMFZcaMnPyowsREhBtMSX6PcJ5bQw == X-Google-Smtp-Source: ABdhPJzcq/49aov99Cdffyzl1IbcDtMBf6OO8NozNFVZfDhTaeOxmKb4QEQf+LeMCQClFjln5WCmtHNy1fnNUQD+jMs= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:200:662:cd2f:9dc:846b]) (user=emilyshaffer job=sendgmr) by 2002:a25:6e8b:: with SMTP id j133mr214532ybc.148.1643925567519; Thu, 03 Feb 2022 13:59:27 -0800 (PST) Date: Thu, 3 Feb 2022 13:59:13 -0800 In-Reply-To: <20220203215914.683922-1-emilyshaffer@google.com> Message-Id: <20220203215914.683922-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20220203215914.683922-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v7 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 absorbgitdirs'. Let's start adding that pointer during 'git submodule absorbgitdirs' too. Signed-off-by: Emily Shaffer --- Documentation/config/submodule.txt | 3 +- submodule.c | 23 +++++++++ t/t7412-submodule-absorbgitdirs.sh | 82 +++++++++++++++++++++++++++++- 3 files changed, 105 insertions(+), 3 deletions(-) diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt index bebd25684e..f801f49ea1 100644 --- a/Documentation/config/submodule.txt +++ b/Documentation/config/submodule.txt @@ -98,4 +98,5 @@ submodule.superprojectGitDir:: reference to determine whether the current repo is a submodule to another repo; if this reference is absent, Git will treat the current repo as though it is not a submodule (this does not make a difference to - most Git commands). It is set automatically during submodule creation. + most Git commands). It is set automatically during submodule creation + and 'git submodule absorbgitdir'. diff --git a/submodule.c b/submodule.c index c689070524..d7395c7551 100644 --- a/submodule.c +++ b/submodule.c @@ -2097,6 +2097,9 @@ 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; struct strbuf new_gitdir = STRBUF_INIT; const struct submodule *sub; + struct config_set sub_cs; + struct strbuf config_path = STRBUF_INIT, sb = STRBUF_INIT; + int tmp; if (submodule_uses_worktrees(path)) die(_("relocate_gitdir for submodule '%s' with " @@ -2127,6 +2130,26 @@ static void relocate_single_git_dir_into_superproject(const char *path) relocate_gitdir(path, real_old_git_dir, real_new_git_dir); + /* + * Note location of superproject's gitdir. Because the submodule already + * has a gitdir and local config, we can store this pointer from + * worktree config to worktree config, if the submodule has + * extensions.worktreeConfig set. + */ + strbuf_addf(&config_path, "%s/config", real_new_git_dir); + git_configset_init(&sub_cs); + git_configset_add_file(&sub_cs, config_path.buf); + /* return 0 indicates config was found - we have a worktree config */ + if (!git_configset_get_bool(&sub_cs, "extensions.worktreeConfig", &tmp)) + strbuf_addstr(&config_path, ".worktree"); + + git_config_set_in_file(config_path.buf, "submodule.superprojectGitdir", + relative_path(absolute_path(get_git_dir()), + real_new_git_dir, &sb)); + + git_configset_clear(&sub_cs); + 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..5753f90268 100755 --- a/t/t7412-submodule-absorbgitdirs.sh +++ b/t/t7412-submodule-absorbgitdirs.sh @@ -30,7 +30,17 @@ 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 + submodule_gitdir="$(git -C sub1 rev-parse --path-format=absolute --git-common-dir)" && + superproject_gitdir="$(git rev-parse --path-format=absolute --git-common-dir)" && + + test-tool path-utils relative_path "$superproject_gitdir" \ + "$submodule_gitdir" >expect && + git -C sub1 config submodule.superprojectGitDir >actual && + + test_cmp expect actual ' test_expect_success 'absorbing does not fail for deinitialized submodules' ' @@ -61,7 +71,16 @@ test_expect_success 'absorb the git dir in a nested submodule' ' git status >actual.1 && git -C sub1/nested rev-parse HEAD >actual.2 && test_cmp expect.1 actual.1 && - test_cmp expect.2 actual.2 + test_cmp expect.2 actual.2 && + + sub1_gitdir="$(git -C sub1 rev-parse --path-format=absolute --git-common-dir)" && + sub1_nested_gitdir="$(git -C sub1/nested rev-parse --path-format=absolute --git-common-dir)" && + + test-tool path-utils relative_path "$sub1_gitdir" "$sub1_nested_gitdir" \ + >expect && + git -C sub1/nested config submodule.superprojectGitDir >actual && + + test_cmp expect actual ' test_expect_success 're-setup nested submodule' ' @@ -130,4 +149,63 @@ test_expect_success 'absorbing fails for a submodule with multiple worktrees' ' test_i18ngrep "not supported" error ' +test_expect_success 'absorbgitdirs works when called from a superproject worktree' ' + # set up a worktree of the superproject + git worktree add wt && + ( + cd wt && + + # create a new unembedded git dir + git init sub4 && + test_commit -C sub4 first && + git submodule add ./sub4 && + test_tick && + + # absorb the git dir + git submodule absorbgitdirs sub4 && + + # make sure the submodule noted the superproject gitdir correctly + submodule_gitdir="$(git -C sub4 rev-parse --absolute-git-dir)" && + superproject_gitdir="$(git rev-parse --absolute-git-dir)" && + + test-tool path-utils relative_path "$superproject_gitdir" \ + "$submodule_gitdir" >expect && + git -C sub4 config submodule.superprojectGitDir >actual && + + test_cmp expect actual + ) +' + +test_expect_success 'absorbgitdirs works with a submodule with worktree config' ' + # reuse the worktree of the superproject + ( + cd wt && + + # create a new unembedded git dir + git init sub5 && + test_commit -C sub5 first && + git submodule add ./sub5 && + test_tick && + + # turn on worktree configs for submodule + git -C sub5 config extensions.worktreeConfig true && + + # absorb the git dir + git submodule absorbgitdirs sub5 && + + # make sure the submodule noted the superproject gitdir correctly + submodule_gitdir="$(git -C sub5 rev-parse --absolute-git-dir)" && + superproject_gitdir="$(git rev-parse --absolute-git-dir)" && + + test-tool path-utils relative_path "$superproject_gitdir" \ + "$submodule_gitdir" >expect && + git -C sub5 config submodule.superprojectGitDir >actual && + + test_cmp expect actual && + + # make sure the config went into the submodule config.worktree + test_file_not_empty "$submodule_gitdir/config.worktree" + ) +' + test_done From patchwork Thu Feb 3 21:59:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12734693 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DA1AC433F5 for ; Thu, 3 Feb 2022 21:59:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355625AbiBCV7i (ORCPT ); Thu, 3 Feb 2022 16:59:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355638AbiBCV7a (ORCPT ); Thu, 3 Feb 2022 16:59:30 -0500 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 A6034C061401 for ; Thu, 3 Feb 2022 13:59:30 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id e81-20020a25d354000000b0061b1a807047so516160ybf.14 for ; Thu, 03 Feb 2022 13:59:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=k7esGtayVb1Q4S+vH8OP5pOyeSUIhNYdFHRrHUKEmFM=; b=bU1zA0S8YZvj3n9Q7+TK7exGbrsPyV3PvtJygW2RFB8kW10lhKwaZiSL+OAV9Wli4W F6kVT3LrxQP/jHxGRMoHDpOgso3NV8CJBUirizbZyw19ArL+PhSjLGZOmMY8TYLg8dlJ 0CE3SuYFQrVZ7RzjCSf4XQyz8A9hyghkAg6bHeA5x/XZ7YSY9cxtdo60wZ2RWZgrsGWs pgSanMYDl+Gaca+kW7UCgf8yv/z5pUoxIVtztyho/RwDKbJ4hVVkcMI3b9nVBIzdI84H 5VNwdikxcIYZVQ2R2jHWm21QHezd9V2zz26nDNoK0E6gjUDa8gIv0AFOsRQ2PbZAT/ib a+1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=k7esGtayVb1Q4S+vH8OP5pOyeSUIhNYdFHRrHUKEmFM=; b=YTy/W+kNzvDvNQe08lesI1dQriJDTbzrmjDnoGl9B4cHJV2adD7PV1o1agUL1TYgO8 e6Kq2PfjLVIKHxGS8HuPOXpJOitpKPEjYMJNdghsxcmyCfxYFhcqcVYR0FwR907HvfQV ukgssU3ccTZBJk6klGBvg9N5rvnHAdesEVkQSNnAS+vLO8RFitEHsmAybmmHQ1b6k4md um8ZTCgo1+vhwHCGcoUSmOmu2EKEb5gN27KlW4DR0zkA7klut8+osE31kHI2UJ6of2Zo iOLyBSzd1cQkwlo8IwBCQP0NdSfh/hvWHHw8Uwx6jbR0Qdgcvkt8AbvGlJfCijLW/tJs PPww== X-Gm-Message-State: AOAM533ZkeNzSAKww42UecBQ7x9SXh0YVfhMT/QTVSRsSxS7wlyWNV8V 1deYCcWFuyQqzYkAIGRqBpKP4xrqmEcV2XEGmS6I+Ofgh6a7Ai876Hx9Em2qjHTl8cLSpWnh6p+ RLBapbZymBzGyHivyADCAWMhBfjPF9b3Vt4YjyJBoqXZGQjTfa7z0By9FnJnlomznGJRk4wZaLg == X-Google-Smtp-Source: ABdhPJyUU1NuicCEtbQNj/TM4aRG9MjzEPitfRe+4Z8tgsG1256zgs7qNTPHLeDoFcYxlAVj8KzuFMiGBfXEGzUpOYA= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:200:662:cd2f:9dc:846b]) (user=emilyshaffer job=sendgmr) by 2002:a25:ef05:: with SMTP id g5mr189739ybd.568.1643925569905; Thu, 03 Feb 2022 13:59:29 -0800 (PST) Date: Thu, 3 Feb 2022 13:59:14 -0800 In-Reply-To: <20220203215914.683922-1-emilyshaffer@google.com> Message-Id: <20220203215914.683922-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20220203215914.683922-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v7 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 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 pointer. 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 --- Documentation/config/submodule.txt | 4 ++-- git-submodule.sh | 15 +++++++++++++++ t/t7406-submodule-update.sh | 27 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt index f801f49ea1..ab37800954 100644 --- a/Documentation/config/submodule.txt +++ b/Documentation/config/submodule.txt @@ -98,5 +98,5 @@ submodule.superprojectGitDir:: reference to determine whether the current repo is a submodule to another repo; if this reference is absent, Git will treat the current repo as though it is not a submodule (this does not make a difference to - most Git commands). It is set automatically during submodule creation - and 'git submodule absorbgitdir'. + most Git commands). It is set automatically during submodule creation, + update, and 'git submodule absorbgitdir'. diff --git a/git-submodule.sh b/git-submodule.sh index 652861aa66..7c247bee7f 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -449,6 +449,21 @@ cmd_update() ;; esac + # Store a poitner to the superproject's gitdir. This may have + # changed, unless it's a fresh clone. Write to worktree if + # applicable, and point to superproject's worktree gitdir if + # applicable. + if test -z "$just_cloned" + then + sm_gitdir="$(git -C "$sm_path" rev-parse --absolute-git-dir)" + relative_gitdir="$(git rev-parse --path-format=relative \ + --prefix "${sm_gitdir}" \ + --git-dir)" + + git -C "$sm_path" config --worktree \ + submodule.superprojectgitdir "$relative_gitdir" + fi + if test -n "$recursive" then ( diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 11cccbb333..b42a339982 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1061,4 +1061,31 @@ 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 && + test-tool path-utils relative_path \ + "$(git rev-parse --absolute-git-dir)" \ + "$(git -C submodule rev-parse --absolute-git-dir)" >expect && + git -C submodule config submodule.superprojectGitdir >actual && + test_cmp expect actual + ) +' + +test_expect_success 'submodule update uses config.worktree if applicable' ' + (cd super && + git -C submodule config --unset submodule.superprojectGitDir && + git -C submodule config extensions.worktreeConfig true && + git submodule update && + test-tool path-utils relative_path \ + "$(git rev-parse --absolute-git-dir)" \ + "$(git -C submodule rev-parse --absolute-git-dir)" >expect && + git -C submodule config submodule.superprojectGitdir >actual && + test_cmp expect actual && + + test_file_not_empty "$(git -C submodule rev-parse --absolute-git-dir)/config.worktree" + ) +' + test_done