All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Trevor Saunders <tbsaunde@tbsaunde.org>
Cc: git@vger.kernel.org, Jens Lehmann <Jens.Lehmann@web.de>,
	Heiko Voigt <hvoigt@hvoigt.net>,
	Jonathan Nieder <jrnieder@gmail.com>
Subject: Re: [PATCH, RFC] checkout: Attempt to checkout submodules
Date: Thu, 19 Mar 2015 11:53:10 -0700	[thread overview]
Message-ID: <xmqqy4msizu1.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1426681643-7516-1-git-send-email-tbsaunde@tbsaunde.org> (Trevor Saunders's message of "Wed, 18 Mar 2015 08:27:23 -0400")

Trevor Saunders <tbsaunde@tbsaunde.org> writes:

> If a user does git checkout HEAD -- path/to/submodule they'd expect the
> submodule to be checked out to the commit that submodule is at in HEAD.

Hmmm.

Is it a good idea to do that unconditionally by hard-coding the
behaviour like this patch does?

Is it a good idea that hard-coded behaviour is "checkout [-f]"?

I think "git submodule update" is the command people use when they
want to "match" the working trees of submodules, and via the
configuration mechanism submodule.*.update, people can choose what
they mean by "match"ing.  Some people want to checkout the commit
specified in the superproject tree by detaching HEAD at it.  Some
people want to integrate by merging or rebasing.

> This is the most brute force possible way of try to do that, and so its
> probably broken in some cases.  However I'm not terribly familiar with
> git's internals and I'm not sure if this is even wanted so I'm starting
> simple.  If people want this to work I can try and do something better.
>
> Signed-off-by: Trevor Saunders <tbsaunde@tbsaunde.org>
> ---
>  entry.c | 22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/entry.c b/entry.c
> index 1eda8e9..2dbf5b9 100644
> --- a/entry.c
> +++ b/entry.c
> @@ -1,6 +1,8 @@
>  #include "cache.h"
> +#include "argv-array.h"
>  #include "blob.h"
>  #include "dir.h"
> +#include "run-command.h"
>  #include "streaming.h"
>  
>  static void create_directories(const char *path, int path_len,
> @@ -277,9 +279,25 @@ int checkout_entry(struct cache_entry *ce,
>  		 * just do the right thing)
>  		 */
>  		if (S_ISDIR(st.st_mode)) {
> -			/* If it is a gitlink, leave it alone! */
> -			if (S_ISGITLINK(ce->ce_mode))
> +			if (S_ISGITLINK(ce->ce_mode)) {
> +				struct argv_array args = ARGV_ARRAY_INIT;
> +				char sha1[41];
> +
> +				argv_array_push(&args, "checkout");
> +
> +				if (state->force)
> +					argv_array_push(&args, "-f");
> +
> +				memcpy(sha1, sha1_to_hex(ce->sha1), 41);
> +				argv_array_push(&args, sha1);
> +				
> +				run_command_v_opt_cd_env(args.argv,
> +					       		 RUN_GIT_CMD, ce->name,
> +							 NULL);
> +				argv_array_clear(&args);
> +
>  				return 0;
> +			}
>  			if (!state->force)
>  				return error("%s is a directory", path.buf);
>  			remove_subtree(&path);

  reply	other threads:[~2015-03-19 18:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-18 12:27 [PATCH, RFC] checkout: Attempt to checkout submodules Trevor Saunders
2015-03-19 18:53 ` Junio C Hamano [this message]
2015-03-19 20:15   ` Trevor Saunders
2015-03-19 21:15     ` Junio C Hamano
2015-03-20  0:13       ` Trevor Saunders
2015-03-23 20:01         ` Jens Lehmann
2015-03-24 18:30           ` Trevor Saunders
2015-03-25 20:16             ` Jens Lehmann

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=xmqqy4msizu1.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=hvoigt@hvoigt.net \
    --cc=jrnieder@gmail.com \
    --cc=tbsaunde@tbsaunde.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.