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

[RFC PATCH 0/2] set remote/HEAD with fetch

From
Bence Ferdinandy <bence@ferdinandy.com>
Date
Sep 10, 2024, 20:24 UTC
Message-ID
<20240910203129.2251090-1-bence@ferdinandy.com>
Hi,

these two patches attempt to solve the issue raised in https://lore.kernel.org/git/D3HBD7C1FR14.74FL1Q1S9UCB@ferdinandy.com/

As a quick summary: `clone` sets `refs/remotes/[remote]/HEAD` while going init -> remote add -> fetch does not, one has to manually run `remote set-head -a [remote]`.

The first patch adds a `--set-head` flag to `fetch` and `remote update` which runs `remote set-head -a` for us. Unfortunately, with the current behaviour of set-head this will always print a message, even though a no-op fetch doesn't print anything, and I think this is also confusing for people who do not care about remote/HEAD, so the second patch removes the print if `set-head -a` is a no-op (and actually makes it into a no-op, instead of just idempotent).

Another way could of course be duplicating some of the code from remote set-head in fetch.c instead of calling directly, but it didn't look like an anti-pattern in the code-base and it felt the best way to insure identical behaviour between a `git fetch --all --set-head` and a `git fetch --all && git remote | xargs -i git remote set-head -a {}`.

What is missing for sure is:
- documentation
- tests (if needed)
- settings
For settings, my idea would be a fetch/remote.set_head that could take three values:
    * never
    * missing: run it only if the ref is missing, this setting would basically
      allow replicating the result of a clone
    * always (with the other patch, this would still be a no-op if it didn't change)

This would probably also require a --no-set-head flag, to disable an always/missing setting. A --missing-set-head or something of the like also may or may not make sense. Alternatively, only two behaviours might be enough (missing and always) since clone already sort of does this.

I'm not sure if the general approach is fine or not, nor am I sure the code itself is any good, but it "works on my computer" :) I'm also hoping that I managed to read all the relevant parts for sending a patch.

Feedback would be highly appreciated!

Thanks, Bence

Bence Ferdinandy (2):
  fetch: set-head with --set-head option
  set-head: do not update if there is no change
 builtin/fetch.c  | 29 ++++++++++++++++++++++++-----
 builtin/remote.c | 15 +++++++++++----
 2 files changed, 35 insertions(+), 9 deletions(-)
-- 
2.46.0
Next: Bence Ferdinandy
Message 1 of 5 in “set remote/HEAD with fetch”
  1. 0/2 set remote/HEAD with fetchBence Ferdinandy, Sep 10, 2024
  2. 1/2 fetch: set-head with --set-head optionBence Ferdinandy, Sep 10, 2024
  3. Jeff KingSep 11, 2024
  4. Bence FerdinandySep 11, 2024
  5. 2/2 set-head: do not update if there is no changeBence Ferdinandy, Sep 10, 2024

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.