From patchwork Mon Aug 29 20:54:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12958410 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 F0AF3ECAAD8 for ; Mon, 29 Aug 2022 20:54:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229587AbiH2UyX (ORCPT ); Mon, 29 Aug 2022 16:54:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbiH2UyV (ORCPT ); Mon, 29 Aug 2022 16:54:21 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7070182845 for ; Mon, 29 Aug 2022 13:54:20 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id m16so11631287wru.9 for ; Mon, 29 Aug 2022 13:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=7B+IpJe/zaczEsI7evqyq9ZQLpHLVvfFYSDHDH0tswQ=; b=XBvH3XJN6jApb/LBUUeENySKzjHAUriHj7rr8JzigKTjybQ9dtehV3IDWR0hrW21XZ iVcoCjm7pigLfEiC0ngXNnLcC5UdgJVx0XRNitV8DxGyR1qgjDwOi/LLFM+/3Ut/WqTM 7Ke4rgwr7Hb7PCBYttEQuzxeyziSCcEgYA29VnA7nu4THpHdnIihSNmhzhCiOIG0l7li knO+2B2weMAVHV/4IYIPkIsfvwPSrYdIfK62IlxRuOFCbaDtzNZ2CZSYn4FpJJzxkUPB 3iamEjaRsgcGPx23gv+3fiuJR3dQ+pCvJ85ScvBT8HA44Ry/mNYd520/WEzRZMuvNI8i faIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=7B+IpJe/zaczEsI7evqyq9ZQLpHLVvfFYSDHDH0tswQ=; b=lP3HUYslfZzUU29ZW5evDT3ctMbJZx1NOdNbvcAipo5KHj+cVvtYKiB9SAThy+t+xN w5Ro8hUZyDthqcmcwciYZBgKdSMCGLXjWVIlyHCIb47tqKSCdZecXodyYid7eSk3GoEM 4qJX1Gox9iOLsvBgwBzi2oEUEii9n/SOC/IAdS5DbAbTj4tX7v+G3/IIkGLIyfc2LZjA 0wjZKYIroV42mCWLLSz2+lXkDt8oDssi8y4FucjJ9GXY28OwanfTwt22EZ+bPxZccomt BfEuhZyh5IjD1EiPvp2RJQSIO47UEHvgxmo5KBPxGv7XY81YbWaCRiWVim0t29ei4lvv CJ5Q== X-Gm-Message-State: ACgBeo01+SUfE/1Mqrbp40nGEWUkk0aOCHtqXn1UBKDdQT/nH/oI5OHH R+0gKJrpgm2a/oyZKbQTlFaLT5jZFIU= X-Google-Smtp-Source: AA6agR4goBKoBnbMfDbAJXIFkCRhJrOPFMwrZkWu4uBybLXxIi7vWWSfQnZOd7UJPmNSjbqXN6Q9ow== X-Received: by 2002:adf:e502:0:b0:225:8785:eee7 with SMTP id j2-20020adfe502000000b002258785eee7mr7202796wrm.304.1661806458813; Mon, 29 Aug 2022 13:54:18 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bq25-20020a5d5a19000000b0021e519eba9bsm3144797wrb.42.2022.08.29.13.54.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 13:54:18 -0700 (PDT) Message-Id: <936e237c716bddf3a5889829e0c907e881736336.1661806456.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 29 Aug 2022 20:54:11 +0000 Subject: [PATCH 1/6] clone: teach --detach option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Glen Choo , Glen Choo Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo From: Glen Choo Teach "git clone" the "--detach" option, which leaves the cloned repo in detached HEAD (like "git checkout --detach"). If the clone is not bare, the remote's HEAD branch is also not created (bare clones always copy all remote branches directly to local branches, so the branch is still created in the bare case). This is especially useful in the "submodule.propagateBranches" workflow, where the submodule branch names match the superproject's branch names, so it makes no sense to name the branches after the submodule's remote's branches. Signed-off-by: Glen Choo --- Documentation/git-clone.txt | 7 ++++++- builtin/clone.c | 12 +++++++++--- t/t5601-clone.sh | 22 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt index 632bd1348ea..a3af90824b6 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -16,7 +16,7 @@ SYNOPSIS [--depth ] [--[no-]single-branch] [--no-tags] [--recurse-submodules[=]] [--[no-]shallow-submodules] [--[no-]remote-submodules] [--jobs ] [--sparse] [--[no-]reject-shallow] - [--filter= [--also-filter-submodules]] [--] + [--filter= [--also-filter-submodules] [--detach]] [--] [] DESCRIPTION @@ -210,6 +210,11 @@ objects from the source repository into a pack in the cloned repository. `--branch` can also take tags and detaches the HEAD at that commit in the resulting repository. +--detach:: + If the cloned repository's HEAD points to a branch, point the newly + created HEAD to the branch's commit instead of the branch itself. In a + non-bare repository, the branch will not be created. + -u :: --upload-pack :: When given, and the repository to clone from is accessed diff --git a/builtin/clone.c b/builtin/clone.c index c4ff4643ecd..1bc1807360e 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -77,6 +77,7 @@ static int option_filter_submodules = -1; /* unspecified */ static int config_filter_submodules = -1; /* unspecified */ static struct string_list server_options = STRING_LIST_INIT_NODUP; static int option_remote_submodules; +static int option_detach; static int recurse_submodules_cb(const struct option *opt, const char *arg, int unset) @@ -160,6 +161,8 @@ static struct option builtin_clone_options[] = { N_("any cloned submodules will use their remote-tracking branch")), OPT_BOOL(0, "sparse", &option_sparse_checkout, N_("initialize sparse-checkout file to include only files at root")), + OPT_BOOL(0, "detach", &option_detach, + N_("detach HEAD and don't create branch")), OPT_END() }; @@ -607,10 +610,12 @@ static void update_remote_refs(const struct ref *refs, } static void update_head(const struct ref *our, const struct ref *remote, - const char *unborn, const char *msg) + const char *unborn, int should_detach, + const char *msg) { const char *head; - if (our && skip_prefix(our->name, "refs/heads/", &head)) { + if (our && !should_detach && + skip_prefix(our->name, "refs/heads/", &head)) { /* Local default branch link */ if (create_symref("HEAD", our->name, NULL) < 0) die(_("unable to update HEAD")); @@ -1339,7 +1344,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix) branch_top.buf, reflog_msg.buf, transport, !is_local); - update_head(our_head_points_at, remote_head, unborn_head, reflog_msg.buf); + update_head(our_head_points_at, remote_head, unborn_head, + option_detach, reflog_msg.buf); /* * We want to show progress for recursive submodule clones iff diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index cf3be0584f4..1e7e5143a76 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -333,6 +333,28 @@ test_expect_success 'clone checking out a tag' ' test_cmp fetch.expected fetch.actual ' +test_expect_success '--detach detaches and does not create branch' ' + test_when_finished "rm -fr dst" && + git clone --detach src dst && + ( + cd dst && + test_must_fail git rev-parse main && + test_must_fail git symbolic-ref HEAD && + test_cmp_rev HEAD refs/remotes/origin/HEAD + ) +' + +test_expect_success '--detach with --bare detaches but creates branch' ' + test_when_finished "rm -fr dst" && + git clone --bare --detach src dst && + ( + cd dst && + git rev-parse main && + test_must_fail git symbolic-ref HEAD && + test_cmp_rev HEAD refs/heads/main + ) +' + test_expect_success 'set up ssh wrapper' ' cp "$GIT_BUILD_DIR/t/helper/test-fake-ssh$X" \ "$TRASH_DIRECTORY/ssh$X" && From patchwork Mon Aug 29 20:54:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12958411 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 6C6AFECAAD4 for ; Mon, 29 Aug 2022 20:54:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbiH2Uy0 (ORCPT ); Mon, 29 Aug 2022 16:54:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229659AbiH2UyX (ORCPT ); Mon, 29 Aug 2022 16:54:23 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E9EA81B20 for ; Mon, 29 Aug 2022 13:54:21 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id s23so4815227wmj.4 for ; Mon, 29 Aug 2022 13:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=VBmlkK5/i+WZz4kX9tb0g/+bYeVRK7sjPeTnmm/LLl0=; b=dcXijBNJ/LSblEe40i4HjsT1qgRMVPYq93vWRO0/08bLENk7Lt8GcCoWn+nLK3f7xj CIB2RYfpTBG3ayOgv3kS3Q70mL/bYAqBoABtU1JJ6WSVn5eAm+PrFJkRxCuSfAVDUB/j o5R+xWGbDJJd11jOMB7BooygbV1P1fqEN5/b60ugHJn0jD80QdQMr9/nV2fh2tcGFppe 2cnxLtHfdtQGM8JkIxM8lPVpF/tcPlqYajH0WFN0nyN5zhDsMumTg9r2F2nnSsrEw7rJ 8B04NiqrFC2O/xOkZLWStiGUUMZNRlDFyXC2nDt6syAkI4cCPtrWbKVICd/c8PaCAaGz HLYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=VBmlkK5/i+WZz4kX9tb0g/+bYeVRK7sjPeTnmm/LLl0=; b=b/rLYPRuSADgsK86G0wa15tgLmPn5qiOFo2A3bKQpJHH7qHmUUA72cIx+hSgXP/bvK 9zqC/UT7eAcM3lejk36sZWB8KF/owM5RW6wEQUumY2DTvsi+DMudQZAiXmWE0CNggfOQ GTKORzKYy7IcepieT7VSNzkD+lQBY8WsVAPzMtNq9ryTc4AnpA3zxOfp+QYmle2r+tkE +nXqk3a6TzD+XCN5CzoGHdHLGhIEvTq//3j/x8aFdRzOuqsNX4eZ+BFhT29gYN9TP4+B 3x7IhxmzvNkZPNs1U0NMxrxy5fJwtcL6qsJwN5XKAfLODtP+xavVBc0Kq0wqEr6wToXV Zp7g== X-Gm-Message-State: ACgBeo3gyU9BIcyo6x1Q7oKYwhD/NHp5TeuS3jtKFMc741XlVkg4SqXV 5pD/Y6ySL3dFVeRYvwrWHYDUldPPcpo= X-Google-Smtp-Source: AA6agR7aPrgfvpcjy56Ep/RDYNL7YDTBfaFcqJCfI9EYJGoXG4YnxJCbyrkMrrcgsvyVemYDM8ZA1w== X-Received: by 2002:a05:600c:34c5:b0:3a5:fd9d:7b2b with SMTP id d5-20020a05600c34c500b003a5fd9d7b2bmr7848653wmq.1.1661806459632; Mon, 29 Aug 2022 13:54:19 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n5-20020a05600c3b8500b003a319b67f64sm407366wms.0.2022.08.29.13.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 13:54:19 -0700 (PDT) Message-Id: <35f068eb0318653ee0474b30d3420d210f47f8e4.1661806456.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 29 Aug 2022 20:54:12 +0000 Subject: [PATCH 2/6] repo-settings: add submodule_propagate_branches Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Glen Choo , Glen Choo Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo From: Glen Choo When processes recurse into submodules, the child processes have to use the same value of "submodule.propagateBranches" as the parent process regardless of whether the process is spawned in the superproject or submodule, otherwise the behavior may be inconsistent if the repositories don't agree on the config. We haven't needed a way to propagate the config because because the only command that reads "submodule.propagateBranches" is "git branch", which only has one mode of operation with "--recurse-submodules". However, a future commit will teach "submodule.propagateBranches" to "git submodule update", making this necessary. Propagate "submodule.propagateBranches" to child processes by adding a corresponding GIT_INTERNAL_* environment variable and repository setting, and setting the environment variable inside prepare_submodule_repo_env(). Then, refactor builtin/branch.c to read the repository setting. Using an internal environment variable is a potentially leaky abstraction because environment variables can come from sources besides the parent process. A more robust solution would be to teach Git that the repository is a submodule and to only read "submodule.propagateBranches" from the superproject config. There is WIP for this on the ML [1]. Another alternative would be to pass "-c submodule.propagateBranches" to all child processes. This is error-prone because many different processes are invoked directly or indirectly by "git submodule update" (e.g. "git submodule--helper clone", "git clone", "git checkout"). With an environment variable, we can avoid this work because prepare_submodule_repo_env() is already called for submodule child processes. [1] https://lore.kernel.org/git/20220310004423.2627181-1-emilyshaffer@google.com/ Signed-off-by: Glen Choo --- builtin/branch.c | 11 +++-------- cache.h | 1 + repo-settings.c | 11 ++++++----- repository.h | 1 + submodule.c | 2 ++ 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index 55cd9a6e998..1201e41ef8c 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -40,7 +40,6 @@ static const char * const builtin_branch_usage[] = { static const char *head; static struct object_id head_oid; static int recurse_submodules = 0; -static int submodule_propagate_branches = 0; static int branch_use_color = -1; static char branch_colors[][COLOR_MAXLEN] = { @@ -106,10 +105,6 @@ static int git_branch_config(const char *var, const char *value, void *cb) recurse_submodules = git_config_bool(var, value); return 0; } - if (!strcasecmp(var, "submodule.propagateBranches")) { - submodule_propagate_branches = git_config_bool(var, value); - return 0; - } return git_color_default_config(var, value, cb); } @@ -714,7 +709,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, builtin_branch_usage, 0); - + prepare_repo_settings(the_repository); if (!delete && !rename && !copy && !edit_description && !new_upstream && !show_current && !unset_upstream && argc == 0) list = 1; @@ -730,7 +725,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) usage_with_options(builtin_branch_usage, options); if (recurse_submodules_explicit) { - if (!submodule_propagate_branches) + if (!the_repository->settings.submodule_propagate_branches) die(_("branch with --recurse-submodules can only be used if submodule.propagateBranches is enabled")); if (noncreate_actions) die(_("--recurse-submodules can only be used to create branches")); @@ -738,7 +733,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) recurse_submodules = (recurse_submodules || recurse_submodules_explicit) && - submodule_propagate_branches; + the_repository->settings.submodule_propagate_branches; if (filter.abbrev == -1) filter.abbrev = DEFAULT_ABBREV; diff --git a/cache.h b/cache.h index 302810b353a..023f8feba42 100644 --- a/cache.h +++ b/cache.h @@ -505,6 +505,7 @@ static inline enum object_type object_type(unsigned int mode) #define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE" #define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX" #define GIT_SUPER_PREFIX_ENVIRONMENT "GIT_INTERNAL_SUPER_PREFIX" +#define GIT_SUBMODULE_PROPAGATE_BRANCHES_ENVIRONMENT "GIT_INTERNAL_SUBMODULE_PROPAGATE_BRANCHES" #define DEFAULT_GIT_DIR_ENVIRONMENT ".git" #define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY" #define INDEX_ENVIRONMENT "GIT_INDEX_FILE" diff --git a/repo-settings.c b/repo-settings.c index 43bc881bfc9..2fde9bcdbf6 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -60,16 +60,17 @@ void prepare_repo_settings(struct repository *r) repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1); repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1); repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0); + repo_cfg_bool(r, "submodule.propagateBranches", &r->settings.submodule_propagate_branches, 0); /* - * The GIT_TEST_MULTI_PACK_INDEX variable is special in that - * either it *or* the config sets - * r->settings.core_multi_pack_index if true. We don't take - * the environment variable if it exists (even if false) over - * any config, as in most other cases. + * Boolean settings from config and environment variables. Only + * take the environment variable if it is true, otherwise, use + * the config. */ if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0)) r->settings.core_multi_pack_index = 1; + if (git_env_bool(GIT_SUBMODULE_PROPAGATE_BRANCHES_ENVIRONMENT, 0)) + r->settings.submodule_propagate_branches = 1; /* * Non-boolean config diff --git a/repository.h b/repository.h index 797f471cce9..bf36b9ee6d7 100644 --- a/repository.h +++ b/repository.h @@ -36,6 +36,7 @@ struct repo_settings { int fetch_write_commit_graph; int command_requires_full_index; int sparse_index; + int submodule_propagate_branches; struct fsmonitor_settings *fsmonitor; /* lazily loaded */ diff --git a/submodule.c b/submodule.c index 3fa5db3ecdf..510c1b04a76 100644 --- a/submodule.c +++ b/submodule.c @@ -504,6 +504,8 @@ static void print_submodule_diff_summary(struct repository *r, struct rev_info * void prepare_submodule_repo_env(struct strvec *out) { + if (the_repository->settings.submodule_propagate_branches) + strvec_pushf(out, "%s=1", GIT_SUBMODULE_PROPAGATE_BRANCHES_ENVIRONMENT); prepare_other_repo_env(out, DEFAULT_GIT_DIR_ENVIRONMENT); } From patchwork Mon Aug 29 20:54:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12958412 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 45CC0ECAAD8 for ; Mon, 29 Aug 2022 20:54:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229691AbiH2Uy1 (ORCPT ); Mon, 29 Aug 2022 16:54:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229663AbiH2UyX (ORCPT ); Mon, 29 Aug 2022 16:54:23 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22C2582845 for ; Mon, 29 Aug 2022 13:54:22 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id k17so4820940wmr.2 for ; Mon, 29 Aug 2022 13:54:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=dVT4Komgau6X4o+PgTxTUfj/QefvKOJ79AQA8TUj2zQ=; b=VsHRjFNFrYGVTHxVZHkrCWeDcRiW8yXLVuuNs4JMYHNFMT49qzDc4O5gGTEq+JXzul pAjzWqJhPq+W5aItOD++UJupeZBnL+3UzeVR41bkKxm+uF1MnGWnuBDaeaMHhI41b1R2 OGIS2sLvt3HyPyPMeKl/7xEjUWn1QIXrBHF0qzMrJ0+qqUWijTSpnKxVEl/e3s2W/Kp7 0SFc1nWri23x6TMpHi05EfnvY6pG1PmxEhCaWRDWedblMzIOJheHwleBHoRaaQpywNtt hEi1+oC9cjeROyr7QnasR+Bsjr2TkeSVx/L1UVrD0sKfUrwB3SFF+XHMgNA9gJQdhPWZ J0Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=dVT4Komgau6X4o+PgTxTUfj/QefvKOJ79AQA8TUj2zQ=; b=nfajSEadvkAPkBmdowHyJXHrfOuqHKi3dvFDQ+TFeowBh9iGin/SvmLs6wyuO26+Nm RucOydH/5kqKhanfFNfQgMEaquXSgahcjCv0OjNgyltgHn1Dz6qUk8EfcP4CFc/U4RBH p0BUqgK+Ib/+68R9tw09RE+2e4lJZ6kOueZ4GDDa09WSH8tuCw0bCXbopQQjpEFxlwR1 9tClPP+zDdML0GE4h6VlnTcm6negZolFVB+Jy2JDTS4MAhT68h/pxklq8NiyBd2iKQqD vS8KXbWUFLkyPxv0JfMGrNymimmS3cSsIygnvu+V/ZubUVCYGG+KR7kuBHWtl9zAM3qB kjHg== X-Gm-Message-State: ACgBeo02lbG0ix0RSCwHt8N+jxlFgW7x5Db6RJBVtDty9g5GnXv2rtFx qYf7AToa6oYMZ3QZwNXXendqD2/VPko= X-Google-Smtp-Source: AA6agR4D39Kgq3gG6BvkXQHIohr8pWSfHujf/UCzHKCBTVAQTRYrjxrVta8Q6T3JVrrM57ChK5JyAw== X-Received: by 2002:a05:600c:3ac3:b0:3a5:e1de:5994 with SMTP id d3-20020a05600c3ac300b003a5e1de5994mr7896424wms.133.1661806460477; Mon, 29 Aug 2022 13:54:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i10-20020a1c3b0a000000b003a601707174sm10221990wma.33.2022.08.29.13.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 13:54:20 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 29 Aug 2022 20:54:13 +0000 Subject: [PATCH 3/6] t5617: drop references to remote-tracking branches Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Glen Choo , Glen Choo Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo From: Glen Choo It has included submodule cloning tests without remote-tracking branches tests since f05da2b48b (clone, submodule: pass partial clone filters to submodules, 2022-02-04) at least. Rename it accordingly so that we can put future submodule cloning tests there. Signed-off-by: Glen Choo --- ...617-clone-submodules-remote.sh => t5617-clone-submodules.sh} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename t/{t5617-clone-submodules-remote.sh => t5617-clone-submodules.sh} (97%) diff --git a/t/t5617-clone-submodules-remote.sh b/t/t5617-clone-submodules.sh similarity index 97% rename from t/t5617-clone-submodules-remote.sh rename to t/t5617-clone-submodules.sh index ca8f80083a2..b5c66cb18cb 100755 --- a/t/t5617-clone-submodules-remote.sh +++ b/t/t5617-clone-submodules.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='Test cloning repos with submodules using remote-tracking branches' +test_description='Test cloning repos with submodules' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME From patchwork Mon Aug 29 20:54:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12958413 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 56984C0502C for ; Mon, 29 Aug 2022 20:54:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229478AbiH2Uya (ORCPT ); Mon, 29 Aug 2022 16:54:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbiH2UyY (ORCPT ); Mon, 29 Aug 2022 16:54:24 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 231E3861D5 for ; Mon, 29 Aug 2022 13:54:23 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id c7so4984389wrp.11 for ; Mon, 29 Aug 2022 13:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=qmsYLljht0Usq3r7uS3Jei7wDsWb5bwYrAKGSGWUZVA=; b=Lu8WtaHpM8dCvSPuhoAKeio5DenOYppdCWSe8uyDWDjtsA30OzgiwU+ZIMa10wYHCM 4/dXgEZfHl57pGz8eLclIIMUBycp7UcRlydcIb61Y0W+MTEROtqKoyaOHV7kMQdoxzku p3Sjx67YzfF1UsoCq2wd7wbO1nhfbeNdOINn2r09b271F46/wA3h4asRNPzkLnm5Homr lw7gl0ytI0YTYaCwImrck1pTm/kkQVp/ZXeRk9tMvHQoavS+DyW2Cbtnga/2qXuUICsV e3YRt7SDAiffJj97osjIVOtf1G+i29JxjbzfYkJA7OhugeJ+cHHlQ3qT+9fy4cH7Tnwk mKhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=qmsYLljht0Usq3r7uS3Jei7wDsWb5bwYrAKGSGWUZVA=; b=yXbX8qQ2hpCGUmveglL3r9c/ON0RBTsIi7ckFL5/gHl3ee0wdsvRyRZRGtvRmUIS5p Ad7Tm0B2F6w8dJgjuzVfhRQLaYpeHiTLArpkfKTqMgS1Pe+aqOBTArwM8nTwTG9LGWOJ iXdGtfDBKEOzQ877ZqWjDIiSGTmdTR5iGXZ35eMgY04x5jbQcf3Akv/LFoPPsOOCqfwR WgBjWZGsRpM2rlcc4pp4/K8iAZx7xMSzBVhw/f6JK0xPp56tko7E1u4ukpUPW39euwkU 3RIRz29GZrn92QIQIrJLnKcwwWW6lc2C85m9Lr+bXgpoJtI3M1ARMvamJtMDaKPZOA8y wRQA== X-Gm-Message-State: ACgBeo2jysyk/G1L21MdIoEQewlyY9n0Q3Ylr9Lgrb46qEDjp5lADpb2 od1p0dY/1QdwnJ9jJqzHg6tmuuvZow4= X-Google-Smtp-Source: AA6agR63H8Yt6tlE/uJHDGPjWSIBbRm8fvL5AHYHuJ+inVq5fxdYSlNwMkzfvPMh/wwA6r1h5DOpsQ== X-Received: by 2002:a5d:64e2:0:b0:225:79d3:d6c4 with SMTP id g2-20020a5d64e2000000b0022579d3d6c4mr7315777wri.464.1661806461311; Mon, 29 Aug 2022 13:54:21 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x18-20020a5d4452000000b00225307f43fbsm7764007wrr.44.2022.08.29.13.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 13:54:20 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 29 Aug 2022 20:54:14 +0000 Subject: [PATCH 4/6] submodule: return target of submodule symref Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Glen Choo , Glen Choo Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo From: Glen Choo resolve_gitlink_ref() can tell us which oid the submodule ref is pointing to, but in a future commit, we would also like to know the symbolic ref target if we are checking a symbolic ref. Teach resolve_gitlink_ref() to "return" the symbolic ref's target via an "out" parameter. This changes resolve_gitlink_ref()'s signature so that new callers trying to use the old signature will be stopped by the compiler. If we returned the target instead (just like refs_resolve_ref_unsafe()), we would be more consistent with refs_resolve_ref_unsafe(), but callers expecting the old signature will get the opposite return value from what they expect (since exit code 0 means success, but NULL pointer means failure). We should do this refactor once we think that nobody will try to use the old signature. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 8 +++++--- builtin/update-index.c | 4 ++-- combine-diff.c | 3 ++- diff-lib.c | 2 +- dir.c | 2 +- object-file.c | 2 +- read-cache.c | 4 ++-- refs.c | 10 ++++++---- refs.h | 5 ++++- unpack-trees.c | 3 ++- 10 files changed, 26 insertions(+), 17 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index b63f420ecef..dd00a0db522 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2466,7 +2466,8 @@ static int update_submodule(struct update_data *update_data) if (update_data->just_cloned) oidcpy(&update_data->suboid, null_oid()); - else if (resolve_gitlink_ref(update_data->sm_path, "HEAD", &update_data->suboid)) + else if (resolve_gitlink_ref(update_data->sm_path, "HEAD", + &update_data->suboid, NULL)) die(_("Unable to find current revision in submodule path '%s'"), update_data->displaypath); @@ -2482,7 +2483,8 @@ static int update_submodule(struct update_data *update_data) update_data->sm_path); } - if (resolve_gitlink_ref(update_data->sm_path, remote_ref, &update_data->oid)) + if (resolve_gitlink_ref(update_data->sm_path, remote_ref, + &update_data->oid, NULL)) die(_("Unable to find %s revision in submodule path '%s'"), remote_ref, update_data->sm_path); @@ -3231,7 +3233,7 @@ static void die_on_repo_without_commits(const char *path) strbuf_addstr(&sb, path); if (is_nonbare_repository_dir(&sb)) { struct object_id oid; - if (resolve_gitlink_ref(path, "HEAD", &oid) < 0) + if (resolve_gitlink_ref(path, "HEAD", &oid, NULL) < 0) die(_("'%s' does not have a commit checked out"), path); } strbuf_release(&sb); diff --git a/builtin/update-index.c b/builtin/update-index.c index b62249905f1..19a21a4586c 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -339,7 +339,7 @@ static int process_directory(const char *path, int len, struct stat *st) if (S_ISGITLINK(ce->ce_mode)) { /* Do nothing to the index if there is no HEAD! */ - if (resolve_gitlink_ref(path, "HEAD", &oid) < 0) + if (resolve_gitlink_ref(path, "HEAD", &oid, NULL) < 0) return 0; return add_one_path(ce, path, len, st); @@ -365,7 +365,7 @@ static int process_directory(const char *path, int len, struct stat *st) } /* No match - should we add it as a gitlink? */ - if (!resolve_gitlink_ref(path, "HEAD", &oid)) + if (!resolve_gitlink_ref(path, "HEAD", &oid, NULL)) return add_one_path(NULL, path, len, st); /* Error out. */ diff --git a/combine-diff.c b/combine-diff.c index b0ece954808..88efcaeefa7 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1060,7 +1060,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, elem->mode = canon_mode(st.st_mode); } else if (S_ISDIR(st.st_mode)) { struct object_id oid; - if (resolve_gitlink_ref(elem->path, "HEAD", &oid) < 0) + if (resolve_gitlink_ref(elem->path, "HEAD", &oid, + NULL) < 0) result = grab_blob(opt->repo, &elem->oid, elem->mode, &result_size, NULL, NULL); diff --git a/diff-lib.c b/diff-lib.c index 7eb66a417aa..0c1f76d5fe9 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -53,7 +53,7 @@ static int check_removed(const struct index_state *istate, const struct cache_en * a directory --- the blob was removed! */ if (!S_ISGITLINK(ce->ce_mode) && - resolve_gitlink_ref(ce->name, "HEAD", &sub)) + resolve_gitlink_ref(ce->name, "HEAD", &sub, NULL)) return 1; } return 0; diff --git a/dir.c b/dir.c index d7cfb08e441..33368b399e2 100644 --- a/dir.c +++ b/dir.c @@ -3255,7 +3255,7 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up) struct object_id submodule_head; if ((flag & REMOVE_DIR_KEEP_NESTED_GIT) && - !resolve_gitlink_ref(path->buf, "HEAD", &submodule_head)) { + !resolve_gitlink_ref(path->buf, "HEAD", &submodule_head, NULL)) { /* Do not descend and nuke a nested git work tree. */ if (kept_up) *kept_up = 1; diff --git a/object-file.c b/object-file.c index 5b270f046dd..a10a49d7a2a 100644 --- a/object-file.c +++ b/object-file.c @@ -2526,7 +2526,7 @@ int index_path(struct index_state *istate, struct object_id *oid, strbuf_release(&sb); break; case S_IFDIR: - return resolve_gitlink_ref(path, "HEAD", oid); + return resolve_gitlink_ref(path, "HEAD", oid, NULL); default: return error(_("%s: unsupported file type"), path); } diff --git a/read-cache.c b/read-cache.c index 4de207752dc..4b68bd0c9a6 100644 --- a/read-cache.c +++ b/read-cache.c @@ -285,7 +285,7 @@ static int ce_compare_gitlink(const struct cache_entry *ce) * * If so, we consider it always to match. */ - if (resolve_gitlink_ref(ce->name, "HEAD", &oid) < 0) + if (resolve_gitlink_ref(ce->name, "HEAD", &oid, NULL) < 0) return 0; return !oideq(&oid, &ce->oid); } @@ -776,7 +776,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, namelen = strlen(path); if (S_ISDIR(st_mode)) { - if (resolve_gitlink_ref(path, "HEAD", &oid) < 0) + if (resolve_gitlink_ref(path, "HEAD", &oid, NULL) < 0) return error(_("'%s' does not have a commit checked out"), path); while (namelen && path[namelen-1] == '/') namelen--; diff --git a/refs.c b/refs.c index 90bcb271687..d72015c95e9 100644 --- a/refs.c +++ b/refs.c @@ -1784,19 +1784,21 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags, } int resolve_gitlink_ref(const char *submodule, const char *refname, - struct object_id *oid) + struct object_id *oid, const char **referent_out) { struct ref_store *refs; int flags; + const char *referent; refs = get_submodule_ref_store(submodule); if (!refs) return -1; - - if (!refs_resolve_ref_unsafe(refs, refname, 0, oid, &flags) || - is_null_oid(oid)) + referent = refs_resolve_ref_unsafe(refs, refname, 0, oid, &flags); + if (!referent || is_null_oid(oid)) return -1; + if (referent_out) + *referent_out = referent; return 0; } diff --git a/refs.h b/refs.h index 47cb9edbaa8..c5ae76654c5 100644 --- a/refs.h +++ b/refs.h @@ -136,9 +136,12 @@ int peel_iterated_oid(const struct object_id *base, struct object_id *peeled); * submodule (which must be non-NULL). If the resolution is * successful, return 0 and set oid to the name of the object; * otherwise, return a non-zero value. + * + * FIXME: Return "referent" just like refs_resolve_ref_unsafe(). This will be + * safe to do once we merge resolve_gitlink_ref() into master. */ int resolve_gitlink_ref(const char *submodule, const char *refname, - struct object_id *oid); + struct object_id *oid, const char **referent); /* * Return true iff abbrev_name is a possible abbreviation for diff --git a/unpack-trees.c b/unpack-trees.c index 8a454e03bff..43a1a056a19 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -2202,7 +2202,8 @@ static int verify_clean_subdirectory(const struct cache_entry *ce, if (S_ISGITLINK(ce->ce_mode)) { struct object_id oid; - int sub_head = resolve_gitlink_ref(ce->name, "HEAD", &oid); + int sub_head = + resolve_gitlink_ref(ce->name, "HEAD", &oid, NULL); /* * If we are not going to update the submodule, then * we don't care. From patchwork Mon Aug 29 20:54:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12958415 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 A7019ECAAD4 for ; Mon, 29 Aug 2022 20:54:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229550AbiH2Uyf (ORCPT ); Mon, 29 Aug 2022 16:54:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbiH2UyZ (ORCPT ); Mon, 29 Aug 2022 16:54:25 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20C069AFDD for ; Mon, 29 Aug 2022 13:54:23 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id h1so4818009wmd.3 for ; Mon, 29 Aug 2022 13:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=jb7GuWyEWZ1RDMEHb244Y7j7VQsv21C4ORtBDFTmJK4=; b=PzXwvEwfdLQ7kv+K05u4c4hJcxlrVfvmLNsWWfPjdyQqOHxcOzv+pNtja0l2MCgfzj o5NujU1Czws4mxU9933fFSJfcWvFGZn+//kXDK2VoiJ/vjTlkpX2u4NW2zsRWonCbZAj 0YlbH52c3z228Ho3GwxqX3PcfsThfbIB1ykiZ8VGsLxvCHGJIwCBBmsggUTuzbREky/l IppC0rkN20bQx1Z46cVa64f1iwbvjkhcOcq29cC3i2wL0p5SwsZpRB9Gf5F8KiFplYH3 Qf6JTyk8tuKiVZ57TYAsUsp1/qA24D66fJHxRPP5Gxlp56wK4bjZAFXsPI4EV2sD1kKL WPYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=jb7GuWyEWZ1RDMEHb244Y7j7VQsv21C4ORtBDFTmJK4=; b=EAO4R05jWoO8BxRTHIqBpG1xwN/UUdOV3Drj05vYnw0yT9wqIhIgpwUxJ6WHzvRMy6 ykHA2qFu8K2FKEzyWRG3oBOncQfFRyatif27m/7sQwB/UIgQyqUjyVP5nkFsnWVyyyQk VFAlnsnP27wsFHjU4dRJFfG8D+yC3h+4vgXo59F/JnEO7okOtcyEt0HOQYGKszhY+Kju XvFjjSx/YKVTproAzEwXRDBMO8m9Swi6cYhXQ51nQYFnQv2P5Olp6qHlThwpFvz8YBfL kvCM/s6CIjr449P7MoQL9vIo5wzbPQuVxEK+qsRRklX/Ba1OcLQlqAAFSL8wO7xvVSiG xbPQ== X-Gm-Message-State: ACgBeo3wjAQJ8NJknEVAdf4SwfHfvwCW2F/ho3t6jTDrlRHy1XiNjuIK 4olyMxQsvnfFKQWPchAfxBCoPnNo8oE= X-Google-Smtp-Source: AA6agR5OV97Hebjryruy94jq+N+DIw6rPPDLCva4nJA0iv4D4Uvir74TZcxycl0p/c0+j4DvxfHfbQ== X-Received: by 2002:a05:600c:2483:b0:3a5:e70c:d5f6 with SMTP id 3-20020a05600c248300b003a5e70cd5f6mr7761318wms.51.1661806462121; Mon, 29 Aug 2022 13:54:22 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r1-20020a5d4e41000000b00226d1711276sm7705197wrt.1.2022.08.29.13.54.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 13:54:21 -0700 (PDT) Message-Id: <513d18e56d3b60d1b522af212fb8b7be232992d4.1661806456.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 29 Aug 2022 20:54:15 +0000 Subject: [PATCH 5/6] submodule--helper: refactor up-to-date criterion Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Glen Choo , Glen Choo Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo From: Glen Choo Refactor builtin/submodule--helper.c:update_submodule() to check if the submodule is up to date using a variable instead of checking the oids directly. In a subsequent commit, we will expand the definition of "up to date" to include checked out branches. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index dd00a0db522..cbf6bda4850 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2455,6 +2455,8 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * static int update_submodule(struct update_data *update_data) { + int submodule_up_to_date; + ensure_core_worktree(update_data->sm_path); update_data->displaypath = get_submodule_displaypath( @@ -2491,7 +2493,8 @@ static int update_submodule(struct update_data *update_data) free(remote_ref); } - if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) + submodule_up_to_date = oideq(&update_data->oid, &update_data->suboid); + if (!submodule_up_to_date || update_data->force) if (run_update_procedure(update_data)) return 1; From patchwork Mon Aug 29 20:54:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12958414 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 614FFECAAD2 for ; Mon, 29 Aug 2022 20:54:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229738AbiH2Uyc (ORCPT ); Mon, 29 Aug 2022 16:54:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229687AbiH2Uy1 (ORCPT ); Mon, 29 Aug 2022 16:54:27 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E0599C2F5 for ; Mon, 29 Aug 2022 13:54:25 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id b5so11654676wrr.5 for ; Mon, 29 Aug 2022 13:54:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=iSzxIQogg6zwsEHgDzSYmH9zyqomLzQ/xCWHlrw8wo0=; b=cEiLtaPBW/QtrCaNwyHUgnm9pO4+cZre6WXGxf4wCt9zgwoSaEdaIP559SKyh3dBFM 2DTMYYhfG8xnsV7s9l3to/ChJ+ybLu9DjK23p5JdkXR9U2yBRyDMDQe2REc5ruX6Ztty ChJxbiyr4H3hGnRDS7Ryt6k0si7WNAg6T1dtGUhEiSKUfyj8MQrSeUabLUIkexbnrUSW J0REgCWD4ZmnhldHQBbFsfsVdWx2K5xL5pfYIXoBmDq84HUjK/cpcxkzMkV5mEDyzPdw RaPE5e/6AG3goVJct/DBAv9Iy746iyFhHA/FK6ESqm98epsxeriX672EfchHdC7WyrUA h4xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=iSzxIQogg6zwsEHgDzSYmH9zyqomLzQ/xCWHlrw8wo0=; b=2pF6PmkHvZwejmTS41AE4HRVThrsHP5IttyOy1pFiQE5vefd/pKRA7AxrOAsB3299Y 8y8zak/hGni4QekeH/wUIsfrZ22svIuclnu1LCw6nMAVHbdO3jk5ffiWJGbENgmk1SpH 8iZOVmrJXg3foXCH0B+cvt1s3ZPbTGiXVp5BVc5diZDyXBBNSB2WOlzcSRuCXI7deNuJ x4aZuTsqBYvBpYkvKTw+E2O3HopycIv8Pqa6/w+UNYSzWSP+92DecmpVy9o+913yf2V6 44A7pkso95obalWnk/B+5Xyh18faoD2uWR+uDv2icjPVO0kptYZLfLggObMzCYH10nbr zL6A== X-Gm-Message-State: ACgBeo0QOeAnA4ZxRZ48KLhaw+KRL5OgLnTl683OQbMgAWOBydW3CQGl gwROjZP6zA2mblKX16Tevg4c03L93eM= X-Google-Smtp-Source: AA6agR61rsmyPVdfh0f9BQQ3MAYpAK4onVHt+li7lvxY7Luj4D9GPxtl6JDi0NB2h+1yIu40C0c91A== X-Received: by 2002:adf:e845:0:b0:226:d461:9cf1 with SMTP id d5-20020adfe845000000b00226d4619cf1mr5730620wrn.136.1661806463136; Mon, 29 Aug 2022 13:54:23 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ay15-20020a5d6f0f000000b002207a5d8db3sm8133290wrb.73.2022.08.29.13.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 13:54:22 -0700 (PDT) Message-Id: <6f7f2f9a3f19b6d874d644b7fb7feb3a72fc6227.1661806456.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 29 Aug 2022 20:54:16 +0000 Subject: [PATCH 6/6] clone, submodule update: check out branches Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Glen Choo , Glen Choo Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo From: Glen Choo Teach "git submodule update" to update submodules by creating and checking out the current superproject branch when "submodule.propagateBranches=true". "git clone --recurse-submodules" also learns this trick because it is implemented with "git submodule update --recursive". With "submodule.propagateBranches=true", submodules are cloned with "--detach" so that they do not contain branches from their upstream. This prevents conflicts between branch names from the superproject and the branch names from the submodule's upstream. Arguably, "--detach" should also be the default for "submodule.propagateBranches=false" since it doesn't make sense to create a submodule branch when the submodule is always expected to be in detached HEAD. But, to be conservative, this commit does not change the behavior of "submodule.propagateBranches=false". "git submodule update" tries to create the branch as long as it is not currently checked out, thus it will fail if the submodule has the branch, but it is not checked out. This is fine because the main purpose of "git submodule update" is to clone new submodules (which have no branches, and will never have this problem). "git checkout" with "submodule.propagateBranches" will cover the use case of recursively checking out an existing branch. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 28 ++++++++++++++++++++++++++-- t/t5617-clone-submodules.sh | 34 ++++++++++++++++++++++++++++++++++ t/t7406-submodule-update.sh | 22 ++++++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index cbf6bda4850..7eb2c45900e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1695,6 +1695,9 @@ static int clone_submodule(struct module_clone_data *clone_data) strvec_push(&cp.args, clone_data->single_branch ? "--single-branch" : "--no-single-branch"); + if (the_repository->settings.submodule_propagate_branches) + strvec_push(&cp.args, "--detach"); + strvec_push(&cp.args, "--"); strvec_push(&cp.args, clone_data->url); @@ -1733,6 +1736,9 @@ static int clone_submodule(struct module_clone_data *clone_data) if (error_strategy) git_config_set_in_file(p, "submodule.alternateErrorStrategy", error_strategy); + if (the_repository->settings.submodule_propagate_branches) + git_config_set_in_file(p, "submodule.propagateBranches", + "true"); free(sm_alternate); free(error_strategy); @@ -1792,6 +1798,7 @@ static int module_clone(int argc, const char **argv, const char *prefix) memset(&filter_options, 0, sizeof(filter_options)); argc = parse_options(argc, argv, prefix, module_clone_options, git_submodule_helper_usage, 0); + prepare_repo_settings(the_repository); clone_data.dissociate = !!dissociate; clone_data.quiet = !!quiet; @@ -1872,6 +1879,7 @@ struct submodule_update_clone { struct update_data { const char *prefix; const char *displaypath; + const char *super_branch; enum submodule_update_type update_default; struct object_id suboid; struct string_list references; @@ -2206,6 +2214,8 @@ static int run_update_command(struct update_data *ud, int subforce) strvec_pushl(&cp.args, "checkout", "-q", NULL); if (subforce) strvec_push(&cp.args, "-f"); + if (ud->super_branch) + strvec_pushl(&cp.args, "-b", ud->super_branch, NULL); break; case SM_UPDATE_REBASE: cp.git_cmd = 1; @@ -2456,6 +2466,7 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * static int update_submodule(struct update_data *update_data) { int submodule_up_to_date; + const char *submodule_head = NULL; ensure_core_worktree(update_data->sm_path); @@ -2469,7 +2480,7 @@ static int update_submodule(struct update_data *update_data) if (update_data->just_cloned) oidcpy(&update_data->suboid, null_oid()); else if (resolve_gitlink_ref(update_data->sm_path, "HEAD", - &update_data->suboid, NULL)) + &update_data->suboid, &submodule_head)) die(_("Unable to find current revision in submodule path '%s'"), update_data->displaypath); @@ -2493,7 +2504,13 @@ static int update_submodule(struct update_data *update_data) free(remote_ref); } - submodule_up_to_date = oideq(&update_data->oid, &update_data->suboid); + if (update_data->super_branch && + submodule_head && + !skip_prefix(submodule_head, "refs/heads/", &submodule_head)) + submodule_up_to_date = !strcmp(update_data->super_branch, submodule_head); + else + submodule_up_to_date = oideq(&update_data->oid, &update_data->suboid); + if (!submodule_up_to_date || update_data->force) if (run_update_procedure(update_data)) return 1; @@ -2551,6 +2568,12 @@ static int update_submodules(struct update_data *update_data) goto cleanup; } + if (the_repository->settings.submodule_propagate_branches) { + struct branch *current_branch = branch_get(NULL); + if (current_branch) + update_data->super_branch = current_branch->name; + } + for (i = 0; i < suc.update_clone_nr; i++) { struct update_clone_data ucd = suc.update_clone[i]; @@ -2634,6 +2657,7 @@ static int module_update(int argc, const char **argv, const char *prefix) memset(&filter_options, 0, sizeof(filter_options)); argc = parse_options(argc, argv, prefix, module_update_options, git_submodule_helper_usage, 0); + prepare_repo_settings(the_repository); if (opt.require_init) opt.init = 1; diff --git a/t/t5617-clone-submodules.sh b/t/t5617-clone-submodules.sh index b5c66cb18cb..215fb02e9fb 100755 --- a/t/t5617-clone-submodules.sh +++ b/t/t5617-clone-submodules.sh @@ -12,10 +12,17 @@ pwd=$(pwd) test_expect_success 'setup' ' git checkout -b main && test_commit commit1 && + mkdir subsub && + ( + cd subsub && + git init && + test_commit subsubcommit1 + ) && mkdir sub && ( cd sub && git init && + git submodule add "file://$pwd/subsub" subsub && test_commit subcommit1 && git tag sub_when_added_to_super && git branch other @@ -106,4 +113,31 @@ test_expect_success '--no-also-filter-submodules overrides clone.filterSubmodule test_cmp_config -C super_clone3/sub false --default false remote.origin.promisor ' +test_expect_success 'submodule.propagateBranches checks out branches at correct commits' ' + git -C sub checkout -b not-main && + git -C subsub checkout -b not-main && + git clone --recurse-submodules \ + -c submodule.propagateBranches=true \ + "file://$pwd/." super_clone4 && + + # Assert that each repo is pointing to "main" + for REPO in "super_clone4" "super_clone4/sub" "super_clone4/sub/subsub" + do + HEAD_BRANCH=$(git -C $REPO symbolic-ref HEAD) && + test $HEAD_BRANCH = "refs/heads/main" || return 1 + done && + + # Assert that the submodule branches are pointing to the right revs + EXPECT_SUB_OID="$(git -C super_clone4 rev-parse :sub)" && + ACTUAL_SUB_OID="$(git -C super_clone4/sub rev-parse refs/heads/main)" && + test $EXPECT_SUB_OID = $ACTUAL_SUB_OID && + EXPECT_SUBSUB_OID="$(git -C super_clone4/sub rev-parse :subsub)" && + ACTUAL_SUBSUB_OID="$(git -C super_clone4/sub/subsub rev-parse refs/heads/main)" && + test $EXPECT_SUBSUB_OID = $ACTUAL_SUBSUB_OID && + + # Assert that the submodules do not have branches from their upstream + test_must_fail git -C super_clone4/sub rev-parse not-main && + test_must_fail git -C super_clone4/sub/subsub rev-parse not-main +' + test_done diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 6cc07460dd2..00a6fec8912 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1178,4 +1178,26 @@ test_expect_success 'submodule update --recursive skip submodules with strategy= test_cmp expect.err actual.err ' +test_expect_success 'submodule update with submodule.propagateBranches checks out branches' ' + test_when_finished "rm -fr top-cloned" && + cp -r top-clean top-cloned && + + # Create a new upstream submodule + git init middle2 && + test_commit -C middle2 "middle2" && + git -C top submodule add ../middle2 middle2 && + git -C top commit -m "add middle2" && + + git -C top-cloned checkout -b "new-branch" && + git -C top-cloned pull origin main && + test_config -C top-cloned submodule.propagateBranches true && + git -C top-cloned submodule update --recursive && + + for REPO in "top-cloned/middle2" "top-cloned/middle" "top-cloned/middle/bottom" + do + HEAD_BRANCH=$(git -C $REPO symbolic-ref HEAD) && + test $HEAD_BRANCH = "refs/heads/new-branch" || return 1 + done +' + test_done