git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [WIP/PATCH 9/9] submodule: teach unpack_trees() to update submodules

From
Jens Lehmann <jens.lehmann@web.de>
Date
Feb 7, 2014, 21:32 UTC
Message-ID
<52F550EC.20202@web.de>
In-Reply-To
<CACsJy8CiAPnatithenDKBBKVGFHQZsu4mJLEjuWFD2GXqO56Lw@mail.gmail.com>
Am 04.02.2014 01:11, schrieb Duy Nguyen:
Show 29 quoted lines
> On Tue, Feb 4, 2014 at 2:54 AM, Jens Lehmann <Jens.Lehmann@web.de> wrote:
>> Implement the functionality needed to enable work tree manipulating
>> commands so that an changed submodule does not only affect the index but
>> it also updates the work tree of any initialized submodule according to
>> the SHA-1 recorded in the superproject.
>>
>> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
>> ---
>>  entry.c        | 15 ++++++++--
>>  submodule.c    | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  submodule.h    |  3 ++
>>  unpack-trees.c | 69 ++++++++++++++++++++++++++++++++++++----------
>>  unpack-trees.h |  1 +
>>  5 files changed, 157 insertions(+), 17 deletions(-)
>>
>> diff --git a/entry.c b/entry.c
>> index d1bf6ec..61a2767 100644
>> --- a/entry.c
>> +++ b/entry.c
>> @@ -265,7 +265,7 @@ int checkout_entry(struct cache_entry *ce,
>>
>>         if (!check_path(path, len, &st, state->base_dir_len)) {
>>                 unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
>> -               if (!changed)
>> +               if (!changed && (!S_ISDIR(st.st_mode) || !S_ISGITLINK(ce->ce_mode)))
>>                         return 0;
> 
> Should we report something when ce is a gitlink, but path is not a
> directory, instead of siliently exit?
Good point.
Show 18 quoted lines
>> diff --git a/submodule.c b/submodule.c
>> index 3907034..83e7595 100644
>> --- a/submodule.c
>> +++ b/submodule.c
>> @@ -520,6 +520,42 @@ int depopulate_submodule(const char *path)
>>         return 0;
>>  }
>>
>> +int update_submodule(const char *path, const unsigned char sha1[20], int force)
>> +{
>> +       struct strbuf buf = STRBUF_INIT;
>> +       struct child_process cp;
>> +       const char *hex_sha1 = sha1_to_hex(sha1);
>> +       const char *argv[] = {
>> +               "checkout",
>> +               force ? "-fq" : "-q",
> 
> respect "state->quiet" in checkout_entry() as well?
See below.
Show 26 quoted lines
>> +               hex_sha1,
>> +               NULL,
>> +       };
>> +       const char *git_dir;
>> +
>> +       strbuf_addf(&buf, "%s/.git", path);
>> +       git_dir = read_gitfile(buf.buf);
>> +       if (!git_dir)
>> +               git_dir = buf.buf;
>> +       if (!is_directory(git_dir)) {
>> +               strbuf_release(&buf);
>> +               /* The submodule is not populated, so we can't check it out */
>> +               return 0;
>> +       }
>> +       strbuf_release(&buf);
>> +
>> +       memset(&cp, 0, sizeof(cp));
>> +       cp.argv = argv;
>> +       cp.env = local_repo_env;
>> +       cp.git_cmd = 1;
>> +       cp.no_stdin = 1;
>> +       cp.dir = path;   /* GIT_WORK_TREE doesn't work for git checkout */
> 
> And if we do respect --quiet and it's not specified, paths printed by
> this process is relative to "dir", not to user cwd. Could be
> confusing.

That's the reason I'm currently always passing -q to checkout. While checkout would have to learn a "--prefix=" option to be able to print the path relative to the superproject, some (most?) users don't want to see this detailed information from inside the submodule. After all git status and diff currently also only show a condensed view of the submodule state and don't print any detailed information about files inside the submodule. We might want to add means to enable that later, and then we'd have to conditionally provide --quiet (and --prefix) here.

Show 6 quoted lines
>> +       if (run_command(&cp))
>> +               return error("Could not checkout submodule %s", path);
>> +
>> +       return 0;
>> +}
>> +
Previous: Duy Nguyen
Message 35 of 35 in “What's cooking in git.git (Jan 2014, #01; Mon, 6)”
  1. Junio C HamanoJan 6, 2014
  2. Francesco PrettoJan 6, 2014
  3. Junio C HamanoJan 6, 2014
  4. Francesco PrettoJan 6, 2014
  5. Jens LehmannJan 7, 2014
  6. 0/9 v2 submodule recursive checkout]Jens Lehmann, Feb 3, 2014
  7. 1/9 submodule: prepare for recursive checkout of submodulesJens Lehmann, Feb 3, 2014
  8. Junio C HamanoFeb 3, 2014
  9. Jens LehmannFeb 7, 2014
  10. Jonathan NiederFeb 4, 2014
  11. Jens LehmannFeb 7, 2014
  12. 2/9 Teach reset the --[no-]recurse-submodules optionJens Lehmann, Feb 3, 2014
  13. Junio C HamanoFeb 3, 2014
  14. Jens LehmannFeb 7, 2014
  15. 3/9 Teach checkout the --[no-]recurse-submodules optionJens Lehmann, Feb 3, 2014
  16. Junio C HamanoFeb 3, 2014
  17. Jens LehmannFeb 7, 2014
  18. 4/9 Teach merge the --[no-]recurse-submodules optionJens Lehmann, Feb 3, 2014
  19. Junio C HamanoFeb 3, 2014
  20. Jens LehmannFeb 7, 2014
  21. Junio C HamanoFeb 7, 2014
  22. W. Trevor KingFeb 7, 2014
  23. 5/9 Teach bisect--helper the --[no-]recurse-submodules optionJens Lehmann, Feb 3, 2014
  24. 6/9 Teach bisect the --[no-]recurse-submodules optionJens Lehmann, Feb 3, 2014
  25. W. Trevor KingFeb 3, 2014
  26. Jens LehmannFeb 3, 2014
  27. 7/9 submodule: teach unpack_trees() to remove submodule contentsJens Lehmann, Feb 3, 2014
  28. W. Trevor KingFeb 3, 2014
  29. Jens LehmannFeb 7, 2014
  30. 8/9 submodule: teach unpack_trees() to repopulate submodulesJens Lehmann, Feb 3, 2014
  31. 9/9 submodule: teach unpack_trees() to update submodulesJens Lehmann, Feb 3, 2014
  32. W. Trevor KingFeb 3, 2014
  33. Jens LehmannFeb 7, 2014
  34. Duy NguyenFeb 4, 2014
  35. Jens LehmannFeb 7, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.