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

Re: [PATCH] submodule: Allow tracking of the newest revision of a branch in a submodule

From
LHLars Hjemli <hjemli@gmail.com>
Date
Dec 9, 2008, 09:23 UTC
Message-ID
<8c5c35580812090123k2c6ed479odf8b625177a07005@mail.gmail.com>
In-Reply-To
<1228784261-18637-1-git-send-email-git@fabian-franz.de>
On Tue, Dec 9, 2008 at 01:57, Fabian Franz <git@fabian-franz.de> wrote:
> Technically the gitlink code was changed to read .git/HEAD.gitlink
> if it exists instead of the normal HEAD. If you add 0000* as sha1
> sum to .git/HEAD.gitlink the submodule code will always fetch HEAD.

This feels like the porcelain "fooling" the plumbing. How about something like this instead:

diff --git a/read-cache.c b/read-cache.c
index 8579663..cfacea7 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -137,6 +137,8 @@ static int ce_compare_gitlink(struct cache_entry *ce)
         */
        if (resolve_gitlink_ref(ce->name, "HEAD", sha1) < 0)
                return 0;
+       if (is_null_sha1(ce->sha1))
+               return 0;
        return hashcmp(sha1, ce->sha1);
 }

This should make the plumbing happy no matter which commit is actually
checked out in the submodule (not actually tested...). Then,
cmd_update() can check if the requested sha1 is all '0' and
fetch+checkout latest HEAD (or some branch) without playing games with
.git/HEAD.gitlink. Finally, cmd_add() needs to update the index in the
containing repository with the magic '0*' sha1 if '--track' is
specifed. This can be achieved by replacing 'git add $path' with 'echo
$mode $sha1\t$path | git update-index --index-info'.

What do you think?

> @@ -327,10 +335,14 @@ cmd_update()
>                        say "Maybe you want to use 'update --init'?"
>                        continue
>                fi
> +               track=$(git config -f .gitmodules submodule."$name".track)

I'm pretty certain that we don't want to use info from .gitmodules in
cmd_update(). Instead, cmd_init() probably should move the info from
.gitmodules into .git/config and cmd_update() should check the latter.

Btw: cmd_status() probably also needs some modifications to handle
this special case.

--
larsh
Previous: Fabian Franz
Message 2 of 2 in “submodule: Allow tracking of the newest revision of a branch in a submodule”
  1. submodule: Allow tracking of the newest revision of a branch in a submoduleFabian Franz, Dec 9, 2008
  2. Lars HjemliDec 9, 2008

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.