From: "Jan Alexander Steffens (heftig)" <heftig@archlinux.org>
To: git@vger.kernel.org
Cc: "Jan Alexander Steffens (heftig)" <heftig@archlinux.org>
Subject: [PATCH 1/6] submodule--helper: use submodule_from_path in set-{url,branch}
Date: Tue, 3 Oct 2023 20:50:42 +0200 [thread overview]
Message-ID: <20231003185047.2697995-1-heftig@archlinux.org> (raw)
In-Reply-To: <0a0a157f88321d25fdb0be771a454b3410a449f3.camel@archlinux.org>
The commands need a path to a submodule but treated it as the name when
modifying the .gitmodules file, leading to confusion when a submodule's
name does not match its path.
Because calling submodule_from_path initializes the submodule cache, we
need to manually trigger a reread before syncing, as the cache is
missing the config change we just made.
Signed-off-by: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
---
builtin/submodule--helper.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index f6871efd95..f376466a5e 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2902,19 +2902,26 @@ static int module_set_url(int argc, const char **argv, const char *prefix)
N_("git submodule set-url [--quiet] <path> <newurl>"),
NULL
};
+ const struct submodule *sub;
argc = parse_options(argc, argv, prefix, options, usage, 0);
if (argc != 2 || !(path = argv[0]) || !(newurl = argv[1]))
usage_with_options(usage, options);
- config_name = xstrfmt("submodule.%s.url", path);
+ sub = submodule_from_path(the_repository, null_oid(), path);
+ if (!sub)
+ die(_("no submodule mapping found in .gitmodules for path '%s'"),
+ path);
+
+ config_name = xstrfmt("submodule.%s.url", sub->name);
config_set_in_gitmodules_file_gently(config_name, newurl);
- sync_submodule(path, prefix, NULL, quiet ? OPT_QUIET : 0);
+
+ repo_read_gitmodules (the_repository, 0);
+ sync_submodule(sub->path, prefix, NULL, quiet ? OPT_QUIET : 0);
free(config_name);
-
return 0;
}
@@ -2942,19 +2949,26 @@ static int module_set_branch(int argc, const char **argv, const char *prefix)
N_("git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>"),
NULL
};
+ const struct submodule *sub;
argc = parse_options(argc, argv, prefix, options, usage, 0);
if (!opt_branch && !opt_default)
die(_("--branch or --default required"));
if (opt_branch && opt_default)
die(_("options '%s' and '%s' cannot be used together"), "--branch", "--default");
if (argc != 1 || !(path = argv[0]))
usage_with_options(usage, options);
- config_name = xstrfmt("submodule.%s.branch", path);
+ sub = submodule_from_path(the_repository, null_oid(), path);
+
+ if (!sub)
+ die(_("no submodule mapping found in .gitmodules for path '%s'"),
+ path);
+
+ config_name = xstrfmt("submodule.%s.branch", sub->name);
ret = config_set_in_gitmodules_file_gently(config_name, opt_branch);
free(config_name);
--
2.42.0
next prev parent reply other threads:[~2023-10-03 18:51 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-24 4:21 git submodule set-url does not sync when name != path Jan Alexander Steffens (heftig)
2023-09-09 22:26 ` Bug: git submodule set-url does not handle name != path correctly Jan Alexander Steffens (heftig)
2023-10-03 18:50 ` Jan Alexander Steffens (heftig) [this message]
2023-10-03 18:50 ` [PATCH 2/6] submodule--helper: return error from set-url when modifying failed Jan Alexander Steffens (heftig)
2023-10-03 23:10 ` Junio C Hamano
2023-10-03 18:50 ` [PATCH 3/6] t7419: Actually test the branch switching Jan Alexander Steffens (heftig)
2023-10-04 0:20 ` Junio C Hamano
2023-10-03 18:50 ` [PATCH 4/6] t7419, t7420: Use test_cmp_config instead of grepping .gitmodules Jan Alexander Steffens (heftig)
2023-10-03 18:50 ` [PATCH 5/6] t7419: Test that we correctly handle renamed submodules Jan Alexander Steffens (heftig)
2023-10-03 18:50 ` [PATCH 6/6] t7420: " Jan Alexander Steffens (heftig)
2023-10-04 1:10 ` [PATCH 1/6] submodule--helper: use submodule_from_path in set-{url,branch} Junio C Hamano
2023-11-21 20:32 ` [PATCH v2 " Jan Alexander Steffens (heftig)
2023-11-21 20:32 ` [PATCH v2 2/6] submodule--helper: return error from set-url when modifying failed Jan Alexander Steffens (heftig)
2023-11-21 20:32 ` [PATCH v2 3/6] t7419: actually test the branch switching Jan Alexander Steffens (heftig)
2023-11-21 20:32 ` [PATCH v2 4/6] t7419, t7420: use test_cmp_config instead of grepping .gitmodules Jan Alexander Steffens (heftig)
2023-11-21 20:32 ` [PATCH v2 5/6] t7419: test that we correctly handle renamed submodules Jan Alexander Steffens (heftig)
2023-11-21 20:32 ` [PATCH v2 6/6] t7420: " Jan Alexander Steffens (heftig)
2023-11-22 7:54 ` [PATCH v2 1/6] submodule--helper: use submodule_from_path in set-{url,branch} Junio C Hamano
2023-11-22 9:50 ` Jan Alexander Steffens (heftig)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231003185047.2697995-1-heftig@archlinux.org \
--to=heftig@archlinux.org \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).