From patchwork Thu Oct 14 20:34:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12559395 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A38C5C4332F for ; Thu, 14 Oct 2021 20:34:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8513A61130 for ; Thu, 14 Oct 2021 20:34:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231732AbhJNUgk (ORCPT ); Thu, 14 Oct 2021 16:36:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbhJNUgk (ORCPT ); Thu, 14 Oct 2021 16:36:40 -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 DE422C061570 for ; Thu, 14 Oct 2021 13:34:34 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id y18-20020a25a092000000b005bddb39f160so7014350ybh.10 for ; Thu, 14 Oct 2021 13:34:34 -0700 (PDT) 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=EAMaV35359qSPUPd0E6tAUxjFw7qmvwY1vPLP8ryqhw=; b=hVNzlfENxT901vsmfFVqJozr2STgkW1qr6FQmICj/nsUHAPhMLR7dJNvse4YWO9UTs eGm6Kuy9BUekhUq5RGkb4CSSJ158MQMVGNKDYTm0ZocQugtzKSogPWYGaeRzFpSyFNa3 bMqhjrKngns2YKGItOJf08yjH5UyqYJsyAKznXmP7g0g1cn84ToVjVhVg//gGKarznym lsOwWzSDZWKaxX/C2ymZg6d2VN5N05E4QzNLlCsUGna9njxqKW4ad9F+x76yzUVDlfWY oX5oOwYQPD4YDdomllds07lpZoxfkTw/dk8cZp38jmwEO+xb2WvqqqUY3oQG2w1xRNBe cTEA== 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=EAMaV35359qSPUPd0E6tAUxjFw7qmvwY1vPLP8ryqhw=; b=ZYgBZkF/YLl8ozs/mDPU587UWImiT7B1UOXIVa0oZ1KC5YIiSvG4lWGIB7F6JxawCP fxmwKjfM2cmgVmb9ifhdGKAmJaNZncAHwX1ldDsWeca9fyByFAX3FmSPqeKcPadvZ5aB adJqMFS7g/gENa8KYdMVsGovNJfB8Q9UIx10eH1LxEIn1Krcp/UDlb5k9+U00lr1SryI dcKfbeuou+V+dJOuhTBM8pfm9xuwHSKJ/I110zyY+lzM8PEHupaUgPMQ/2rOxsyoTnV/ mYs7q0jzCI2j6sL1UqoNu2rzHobJChSJU8MohS5UvFKKA4SALmdv/Rb8HcyNCz+V0/BO bhNw== X-Gm-Message-State: AOAM532RD3k74+XOMsZeHv37O1jTUlsKuhVw0nybmG2XlZiiB6qFcHM+ KF5CH5nX8krxq6soEYgKm1BBgYFTgt0Vc9hLAWLySMmB0gClWoL7pH0t6YJZ8xJLdRs9NtLS3tG tl589L0vwh47g5BRX94pcsM8WELxjqQmYkTF20La5yPpEZ7D4kzPNJh+RmMOJFu2fBmYXr2yvLA == X-Google-Smtp-Source: ABdhPJybvJql5v6eB3JkpC34FqklFPSCXY+IdusF7OUlFbEsWFfn+FoNToIkQEJV1dPXCl0oIwUcaWAl+Wkhu2U5uIU= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:200:e9ae:673a:ec5:a064]) (user=emilyshaffer job=sendgmr) by 2002:a25:abf0:: with SMTP id v103mr8207523ybi.385.1634243674107; Thu, 14 Oct 2021 13:34:34 -0700 (PDT) Date: Thu, 14 Oct 2021 13:34:13 -0700 In-Reply-To: <20211014203416.2802639-1-emilyshaffer@google.com> Message-Id: <20211014203416.2802639-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20211014203416.2802639-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog Subject: [PATCH v4 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 cb1b8e35db..d69a5c0032 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 Oct 14 20:34:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12559397 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 016DFC433F5 for ; Thu, 14 Oct 2021 20:34:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF65861151 for ; Thu, 14 Oct 2021 20:34:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231730AbhJNUgo (ORCPT ); Thu, 14 Oct 2021 16:36:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231744AbhJNUgm (ORCPT ); Thu, 14 Oct 2021 16:36:42 -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 8C34EC061755 for ; Thu, 14 Oct 2021 13:34:37 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id i83-20020a252256000000b005b67a878f56so2028090ybi.17 for ; Thu, 14 Oct 2021 13:34:37 -0700 (PDT) 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=EKLa1BbpT8qQs7NTfceOdKmh57l3JvJT2UwkBs9U6sc=; b=Nx2mS3oo7/BgBqRL2ctdJLBYLoSWx4Gb60LGl8KmypFntp6YKTy8QjzbGn4b6gbQvM s/Ikl5f6ndm6bT/LVFPozd8E8V0gMmULcsnMsC8g790B+B7LFtnG0LtLe/a+Ti9NTgx+ aCQk1TVv+U+I5R/tTQBT0BQ9fgLoZmQ9+uByREHHTCkR+uLf87zSYK+yvSpVrBfiXk9X HbOo5HqNw4rYJUCI+c0FX72e1hO3KQ2Jet/hBo9MrplnBZi89dbm5RSNxQIOquUrl4wB QXn5kyPAlmIvJNhYjcDrTuUu6l3lqD1EpVS+eHf/H2M38icHps0F3qRkuya+uqtaOzLS H0PA== 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=EKLa1BbpT8qQs7NTfceOdKmh57l3JvJT2UwkBs9U6sc=; b=jAMxiros8ybVb0Z27tJbxqIId56KsUATz9/GbcHsyVuBl/EDiQfafNHhyZtb32Hp3Q GayxdgDMvgsT5/sIQjEK+lJMxJww1qqU8oou3WZQ5skgy1oUyockhltPBlk/tSOPvezH Iq+iRaDsoYcQBAfTUR51n2859EiB2Vf+mTSeQZEV9Q8kspE4ersEdvl5Qc9HVjJAXoP0 2ymJVJxhTLYvl1a0hERAoNznNOCScbMQjgYsoInOhfk4FpbXp30OopxanwfTX0hpof3n vDRsQcRiuZgOUN4l606UJ/iz1jt8uGC1LCjnXKBg5M+QCOPem00jTxCnrkPDph9G1HuL s78g== X-Gm-Message-State: AOAM532zN3/sP28nVo5bvH4KusxRa6seiqi64KDebXlErisfAiCszk86 IGFJNiPXeNDnm3u+HTCM+zvVg33a9nhNehFXuSUZ9UGHBXSyvRVe4LcDJoeia8yqBifvK/Fyjv1 07suC/yZuosDq0du0f0xTkRGtic6eBxgBr7itnOqb8CMwm8Y/6xP2fvOY2WFsgO4XGYK7rHOF9g == X-Google-Smtp-Source: ABdhPJzkzXZUDPJxCQS2tD4OBolppLOWLwJr/qP5zAnC9rAuw/xoZk+2EInRv4HZ5pBodz+kfBYhU+LJIstQKLJHmfo= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:200:e9ae:673a:ec5:a064]) (user=emilyshaffer job=sendgmr) by 2002:a25:c6c9:: with SMTP id k192mr9314127ybf.409.1634243676631; Thu, 14 Oct 2021 13:34:36 -0700 (PDT) Date: Thu, 14 Oct 2021 13:34:14 -0700 In-Reply-To: <20211014203416.2802639-1-emilyshaffer@google.com> Message-Id: <20211014203416.2802639-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20211014203416.2802639-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog Subject: [PATCH v4 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. 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 cache, too. 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 | 12 +++++++++++ builtin/submodule--helper.c | 4 ++++ t/t7400-submodule-basic.sh | 32 ++++++++++++++++++++---------- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt index ee454f8126..c10aeb7fdc 100644 --- a/Documentation/config/submodule.txt +++ b/Documentation/config/submodule.txt @@ -91,3 +91,15 @@ 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 gitdir 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. diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index d574d650af..338dcbd364 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1838,6 +1838,10 @@ static int clone_submodule(struct module_clone_data *clone_data) 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()), + sm_gitdir, &sb)); + free(sm_alternate); free(error_strategy); diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index d69a5c0032..3d146491df 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 Oct 14 20:34:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12559399 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66261C433EF for ; Thu, 14 Oct 2021 20:34:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 476D761130 for ; Thu, 14 Oct 2021 20:34:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231987AbhJNUgq (ORCPT ); Thu, 14 Oct 2021 16:36:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231752AbhJNUgp (ORCPT ); Thu, 14 Oct 2021 16:36:45 -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 DE6F5C061570 for ; Thu, 14 Oct 2021 13:34:39 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id i83-20020a252256000000b005b67a878f56so2028236ybi.17 for ; Thu, 14 Oct 2021 13:34:39 -0700 (PDT) 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=s4sEv+6xVXcWi7T5s6s6soiQrcCHXeCvHZIVwXF0ccc=; b=mJjcZ6yxGL1gYQfqiCnIq/xQIYzittARA4GIws6h6cDrsBrZRnWsXjTbbbe3QJaXoR B540L8CraJI/kv23BHRrmKEqz8LpJRPNUIIjAg/8yD68sfe9fuBuE/JX5xN2pM5v8w2v D/3U1LquEz5RYuNI7EEjRGlQV0UlSHPkiR1DT6xP/6x2Nr38R3z7RShJTAAWo3iwIlmz 3v/44nGrIDy+F9/fK3CvGSbz2UG5vEpPMTEv5xSMNG+vtt3QDD33l/cR4W7rKIizfXLJ JsL7EjpCOrfvCMvIzYNmteV/H/b6sE9wT6p+BCWCToQ5LL18/BJFmtEwA0CNiCWiFPq9 VGLA== 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=s4sEv+6xVXcWi7T5s6s6soiQrcCHXeCvHZIVwXF0ccc=; b=JrSMp0xZl2ZKEm/cj+HYSyLdBvevdx33BxylTAEyq/S8HE1XZgKTyhlBONNjR7Xa6t uQ5Ame6aRkww5sZrziwzWJJWxmvK4gO2SFZzGtrfWHSt2XLPnB1+NR/IRnlq5o6vI/pd 1c4LKWKknjFLnAzYijVwzReRObDP318R1VF/Nc/bOWAbcxmM4NTbFGYfKH3vWpPPpEmX 4AMj/Z1yvQS+qwebV8d72fmFb1Xp4PvnY5Ykshi+d0I89sfP9YWVNtjRWVEAKb5qfu5l S3DL74otf5Hiiu2oKzb5Ac47FsaTiVNB/HsRn2Zqflq8gP1MFPjKkOOsrmeo/ckAhB1A zN1A== X-Gm-Message-State: AOAM531/m1Yj08iK3OljNK6NTjzKdV7pSr4nXZj+ucFZfNgWLwJVnL38 yRmirTZKUOfp3NC6PJFI5krbM8YUdEp5q/+14RQWDC8BNekJktxbT1HN1IuVGPMZpeugGscFjV3 bAzqqq5KKxyBV66Et/95RB0DhJ8FJJX3l+OhbbuualNCtfKt1AlgdJ/ptQLhTw8ZWJnC6g1WddQ == X-Google-Smtp-Source: ABdhPJyE1cGEXpqgws+flNGJXB7gmPGZ/cOK+PR8Nko5kXwVBG+yCsmaHZEm2xVtRmlmhZiuU7NGh1f1BZ/4sTHZL6M= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:200:e9ae:673a:ec5:a064]) (user=emilyshaffer job=sendgmr) by 2002:a25:d3cd:: with SMTP id e196mr7854518ybf.274.1634243679066; Thu, 14 Oct 2021 13:34:39 -0700 (PDT) Date: Thu, 14 Oct 2021 13:34:15 -0700 In-Reply-To: <20211014203416.2802639-1-emilyshaffer@google.com> Message-Id: <20211014203416.2802639-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20211014203416.2802639-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog Subject: [PATCH v4 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 | 23 +++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/submodule.c b/submodule.c index 96487517f9..571b68b66d 100644 --- a/submodule.c +++ b/submodule.c @@ -2084,6 +2084,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; struct strbuf new_gitdir = STRBUF_INIT; 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 " @@ -2114,6 +2115,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(absolute_path(get_git_dir()), + real_new_git_dir, &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..9ee5ccd660 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 --absolute-git-dir)" && + superproject_gitdir="$(git rev-parse --absolute-git-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 --absolute-git-dir)" && + sub1_nested_gitdir="$(git -C sub1/nested rev-parse --absolute-git-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' ' From patchwork Thu Oct 14 20:34:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12559401 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E05A7C433F5 for ; Thu, 14 Oct 2021 20:34:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC5DF61156 for ; Thu, 14 Oct 2021 20:34:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231822AbhJNUgt (ORCPT ); Thu, 14 Oct 2021 16:36:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232110AbhJNUgs (ORCPT ); Thu, 14 Oct 2021 16:36:48 -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 56D8CC061768 for ; Thu, 14 Oct 2021 13:34:42 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id x16-20020a25b910000000b005b6b7f2f91cso8624864ybj.1 for ; Thu, 14 Oct 2021 13:34:42 -0700 (PDT) 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=QoIuthpLr65F7LoCkm9qKz6B4flEd++2C1i+hilV5+A=; b=IjE2LX5fNoXJt+trlDfqKv5a62+2a5hXLATlLS5kCats3iN8DGXptvQbgLPoTLtKSw dIMC4M8PUY4fkQAYZ6V9ap9y8/GhpzBfdQFT4CwMvv/qPRAv3l1j7TOn8o/yAt2raWu6 V3vAhdWIk7z436wAsT+qYgT7bv057cO+peK+UaE8VvrUH1+VJ9e7s30J0cbacEvAiYb/ aZCXYel7MlvZCCZ4mBsM7FdZQCTeBWCk6wUsA6Lqg41okT5aecemQGv3N4Hgo/4vzmD3 CRdm2x+eePQkbaiQz4ar0JR3RvxL01WO7jyuPDBEI97xyhwGwfyzYYi87Ad35bVH8Laz +ZgA== 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=QoIuthpLr65F7LoCkm9qKz6B4flEd++2C1i+hilV5+A=; b=nAPXHAHEx4aN17Y28npZKq3OOjc7uUj47uduPBCV8TSET0RsL+0B4baqOer+WNkmRV XwlBi3S2k5ffyC0XfWhn5SagwyuW+SVFOVC70MtQPmEZRABEpoN0GV/kUGTTLESHuSxf 2K96yJnExobLjC/cjDs36xYfmAKgJBCQ+Xx5ObuwkUqf+TrK7RBjbu4TJG5gLBGxAZv5 GmSGU1ONdwINN1YonkFJxOSgzc995MWZOKYk1ZnolpU2QvJts5wlDIOuxsGV9HzG7C8Y WKHHGNElZ569aaEMP+5FCf25VCoxsQ9TnONkZMHB4rcLJAf8KQCXOijJ1nvrY8vNtkv3 7cFQ== X-Gm-Message-State: AOAM5317PNjKli8eKZXzhm/x/Enqbu+5thmE/Va7diO5A96twQJH4UyQ NLu9cvATaekAqtWrN2YqOMxN/V0DSU9V/20s2YhwRvddQedKc3gEwVJ09SXGdluWKoCHEzpAOqp x7nPmiAWvF53O7x3eCJoSZ1QLJsujvJ4SFlROhPtLa//yMzUmxRkeJCVVJgbFrknlbouoflx3ig == X-Google-Smtp-Source: ABdhPJxnmiOMbs+zyXTvMxgPmwBdfivkHEFTNJFAvE80X9ESw2Nup0i0Latbz0T3oDGn9c3zWgou1hQWzTNSbOdMb18= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:200:e9ae:673a:ec5:a064]) (user=emilyshaffer job=sendgmr) by 2002:a25:cfc9:: with SMTP id f192mr8177700ybg.122.1634243681486; Thu, 14 Oct 2021 13:34:41 -0700 (PDT) Date: Thu, 14 Oct 2021 13:34:16 -0700 In-Reply-To: <20211014203416.2802639-1-emilyshaffer@google.com> Message-Id: <20211014203416.2802639-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20211014203416.2802639-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog Subject: [PATCH v4 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 | 14 ++++++++++++++ t/t7406-submodule-update.sh | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/git-submodule.sh b/git-submodule.sh index 652861aa66..ec02eb5971 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -449,6 +449,20 @@ cmd_update() ;; esac + # Cache a pointer to the superproject's gitdir. This may have + # changed, unless it's a fresh clone. Writes it to worktree + # if applicable, otherwise to local. + 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..7fd5741a5a 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1061,4 +1061,16 @@ 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_done