git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] submodule: improve remote lookup logic
@ 2025-06-11  0:52 Jacob Keller
  2025-06-11  0:52 ` [PATCH 1/6] dir: move starts_with_dot(_dot)_slash to dir.h Jacob Keller
                   ` (6 more replies)
  0 siblings, 7 replies; 17+ messages in thread
From: Jacob Keller @ 2025-06-11  0:52 UTC (permalink / raw)
  To: git; +Cc: Jacob Keller, Junio C Hamano, Patrick Steinhardt

This series improves the git submodule remote lookup logic implemented in
submodule--helper.

A few cleanups are done first:

* The starts_with_dot(_dot)_slash helper functions are moved to dir.h for
  re-use, as these are used both within submodule--helper.c and
  submodule-config.c

* Several remote.c helper functions are refactored to take repository
  pointers, enabling use with a submodule repository pointer.

* The branch_release logic is fixed so that it won't dereference
  branch->merge if it was never setup. This appeared to trigger in some
  cases if a submodule repository was passed into the read_config()
  function.

Next, the submodule--helper.c logic in repo_get_default_remote() is
refactored to remote.c helper functions. A new repo_default_remote() helper
function is added which will try to find a default remote. This helper
first tries to look up the remote from the checked out branch, then falls
back to the only remote (if there is exactly one remote) before finally
falling back to "origin".

This improved logic is a good first step, but won't handle cases where
there are multiple remotes, and when remotes have been renamed.

For the final improvement, notice that the parent project already stores
the URL for the submodule in its .git/config or .gitmodules file. This URL
is what we use to set the remote in the first place when cloning.

Add a repo_remote_from_url() helper which will iterate through the remotes
and find the first remote with that URL. Use this in
repo_get_default_remote() to first try and find a remote by its URL. If
unsuccessful, we still keep the original fallback logic, in the off chance
that the user has changed the URL from within the submodule.

This method is more robust as it is less likely that the user has manually
changed the submodule URL within the submodule but not also within the
.git/config.

With this change, all commands which need the submodule remote will first
look up by URL before trying to use the fallback logic, and should now be
able to find a suitable remote regardless of now they are renamed.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
Jacob Keller (6):
      dir: move starts_with_dot(_dot)_slash to dir.h
      remote: remove the_repository from some functions
      remote: check branch->merge before access in branch_release
      submodule--helper: improve logic for fallback remote name
      submodule: move get_default_remote_submodule()
      submodule: look up remotes by URL first

 dir.h                       |  23 ++++++++++
 remote.h                    |   3 ++
 builtin/submodule--helper.c | 101 ++++++++++++++++++++++--------------------
 remote.c                    | 104 ++++++++++++++++++++++++++++----------------
 submodule-config.c          |  12 -----
 t/t7406-submodule-update.sh |  61 ++++++++++++++++++++++++++
 6 files changed, 207 insertions(+), 97 deletions(-)
---
base-commit: 4c0e625c091d4c648cec7319bafaed3cc81658e5
change-id: 20250610-jk-submodule-helper-use-url-e55d3c379faf

Best regards,
-- 
Jacob Keller <jacob.keller@gmail.com>


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2025-06-17 21:29 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-11  0:52 [PATCH 0/6] submodule: improve remote lookup logic Jacob Keller
2025-06-11  0:52 ` [PATCH 1/6] dir: move starts_with_dot(_dot)_slash to dir.h Jacob Keller
2025-06-11  0:52 ` [PATCH 2/6] remote: remove the_repository from some functions Jacob Keller
2025-06-11  0:52 ` [PATCH 3/6] remote: check branch->merge before access in branch_release Jacob Keller
2025-06-11  0:52 ` [PATCH 4/6] submodule--helper: improve logic for fallback remote name Jacob Keller
2025-06-17  2:58   ` Lidong Yan
2025-06-17 17:53     ` Jacob Keller
2025-06-17 18:57     ` Jacob Keller
2025-06-17 13:30   ` Junio C Hamano
2025-06-11  0:52 ` [PATCH 5/6] submodule: move get_default_remote_submodule() Jacob Keller
2025-06-11  0:52 ` [PATCH 6/6] submodule: look up remotes by URL first Jacob Keller
2025-06-16 22:27 ` [PATCH 0/6] submodule: improve remote lookup logic Jacob Keller
2025-06-16 22:41   ` Junio C Hamano
2025-06-16 23:20     ` Jacob Keller
2025-06-17 15:09       ` Junio C Hamano
2025-06-17 16:16         ` Junio C Hamano
2025-06-17 21:28         ` Jacob Keller

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).