Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jimmy Aguilar Mena <kratsbinovish@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/3] worktree: add --recurse-submodules flag to worktree add
Date: Thu, 16 Apr 2026 10:27:24 -0700	[thread overview]
Message-ID: <xmqqpl3y24ub.fsf@gitster.g> (raw)
In-Reply-To: <aeEPk7m5gwPnmMUZ@RTX> (Jimmy Aguilar Mena's message of "Thu, 16 Apr 2026 18:35:36 +0200")

Jimmy Aguilar Mena <kratsbinovish@gmail.com> writes:

> +	/*
> +	 * If we are populating a submodule in a linked worktree and the main
> +	 * worktree already has this submodule cloned, reuse its objects via a
> +	 * local clone (hardlinks) instead of fetching from the network.  The
> +	 * common-dir path "$GIT_COMMON_DIR/modules/<name>" is where the main
> +	 * worktree stores the submodule gitdir; the per-worktree path returned
> +	 * by submodule_name_to_gitdir() diverges from it only in linked
> +	 * worktrees.
> +	 */
> +	{

I think you identified the right place to hook into.  But instead of
"clone --local", shoudln't you be running "git worktree add" here?

"clone --local" means you have two logically separate repositories
for this single submodule that are used by two worktrees of the
superproject.  If you add a new commit to one, shouldn't that commit
become available in the other?  Two separate repositories created by
"clone --local" will not allow you to do so.

> +		struct strbuf common_sm_gitdir = STRBUF_INIT;
> +		strbuf_addf(&common_sm_gitdir, "%s/modules/%s",
> +			    the_repository->commondir, clone_data->name);
> +
> +		if (!file_exists(sm_gitdir) &&
> +		    strcmp(sm_gitdir, common_sm_gitdir.buf) &&
> +		    is_git_directory(common_sm_gitdir.buf)) {
> +			/*
> +			 * Main worktree has the submodule; reuse it locally.
> +			 * git clone --local creates hardlinks for pack files so
> +			 * no extra disk space is needed for existing objects.
> +			 */
> +			if (clone_data->require_init && !stat(clone_data_path, &st) &&
> +			    !is_empty_dir(clone_data_path))
> +				die(_("directory not empty: '%s'"), clone_data_path);
> +
> +			if (safe_create_leading_directories_const(the_repository, sm_gitdir) < 0)
> +				die(_("could not create directory '%s'"), sm_gitdir);
> +
> +			strvec_push(&cp.args, "clone");
> +			strvec_push(&cp.args, "--local");
> +			strvec_push(&cp.args, "--no-checkout");
> +			if (clone_data->quiet)
> +				strvec_push(&cp.args, "--quiet");
> +			strvec_pushl(&cp.args, "--separate-git-dir", sm_gitdir, NULL);
> +			strvec_push(&cp.args, "--");
> +			strvec_push(&cp.args, common_sm_gitdir.buf);
> +			strvec_push(&cp.args, clone_data_path);
> +
> +			cp.git_cmd = 1;
> +			prepare_submodule_repo_env(&cp.env);
> +			cp.no_stdin = 1;
> +
> +			if (run_command(&cp))
> +				die(_("local clone of '%s' into submodule path '%s' failed"),
> +				    common_sm_gitdir.buf, clone_data_path);
> +
> +			strbuf_release(&common_sm_gitdir);
> +			goto connect_wt;
> +		}
> +		strbuf_release(&common_sm_gitdir);
> +	}
> +
>   	if (!file_exists(sm_gitdir)) {
>   		if (clone_data->require_init && !stat(clone_data_path, &st) &&
>   		    !is_empty_dir(clone_data_path))
> @@ -2005,6 +2058,7 @@ static int clone_submodule(const struct module_clone_data *clone_data,
>   		    sm_gitdir);
>   	}
>   
> +connect_wt:
>   	connect_work_tree_and_git_dir(clone_data_path, sm_gitdir, 0);
>   
>   	p = repo_submodule_path(the_repository, clone_data_path, "config");

      reply	other threads:[~2026-04-16 17:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-16 16:35 [PATCH 2/3] worktree: add --recurse-submodules flag to worktree add Jimmy Aguilar Mena
2026-04-16 17:27 ` Junio C Hamano [this message]

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=xmqqpl3y24ub.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=kratsbinovish@gmail.com \
    /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