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

[PATCH 0/2] checkout/fetch/pull/pack-objects: allow -h outside a repository again

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 7, 2022, 23:49 UTC
Message-ID
<pull.1139.git.1644277797.gitgitgadget@gmail.com>

As reported in https://github.com/git-for-windows/git/issues/3688, calling git fetch -h outside a repository now results in a very ugly

 BUG: repo-settings.c:23: Cannot add settings for uninitialized repository

The reason is that the prepare_repo_settings() calls (that we introduced to support sparse index) assume that there is a gitdir, but the hack to allow parse_options() to handle -h even outside a repository invalidates that assumption.

One strategy I considered was to move the prepare_repo_settings() calls after parse_options(). This would work because when parse_options() handles -h, it exits without returning.

However, this strategy failed in my tests because e.g. cmd_unpack_objects() does need the pack_use_sparse to be populated correctly before even parsing the options so that it can be overridden via --sparse/--no-sparse.

Hence the current strategy where the code that prepares the repo settings and then accesses them is guarded behind the condition that we must have a gitdir to do so.

Note: There are other instances where prepare_repo_settings() is called
before parse_options(), e.g. in cmd_status(), in seen there are even more
instances (e.g. cmd_checkout_index()). All of those instances that are not
touched by this here patch do have special code to handle -h early, though,
before calling prepare_repo_settings() let alone parse_options().
Johannes Schindelin (2):
  checkout/fetch/pull/pack-objects: allow `-h` outside a repository
  t0012: verify that built-ins handle `-h` even without gitdir
 builtin/checkout.c     | 7 ++++---
 builtin/fetch.c        | 7 +++++--
 builtin/pack-objects.c | 8 +++++---
 builtin/pull.c         | 6 ++++--
 t/t0012-help.sh        | 7 ++++++-
 5 files changed, 24 insertions(+), 11 deletions(-)
base-commit: 4c53a8c20f8984adb226293a3ffd7b88c3f4ac1a
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1139%2Fdscho%2Fprepare_repo_settings-after-parse_options-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1139/dscho/prepare_repo_settings-after-parse_options-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1139
-- 
gitgitgadget
Next: Johannes Schindelin via GitGitGadget
Message 1 of 8 in “checkout/fetch/pull/pack-objects: allow -h outside a repository again”
  1. 0/2 checkout/fetch/pull/pack-objects: allow -h outside a repository againJohannes Schindelin via GitGitGadget, Feb 7, 2022
  2. 2/2 t0012: verify that built-ins handle `-h` even without gitdirJohannes Schindelin via GitGitGadget, Feb 7, 2022
  3. 1/2 checkout/fetch/pull/pack-objects: allow `-h` outside a repositoryJohannes Schindelin via GitGitGadget, Feb 7, 2022
  4. Junio C HamanoFeb 8, 2022
  5. Johannes SchindelinFeb 8, 2022
  6. 0/2 checkout/fetch/pull/pack-objects: allow -h outside a repository againJohannes Schindelin via GitGitGadget, Feb 8, 2022
  7. 2/2 t0012: verify that built-ins handle `-h` even without gitdirJohannes Schindelin via GitGitGadget, Feb 8, 2022
  8. 1/2 checkout/fetch/pull/pack-objects: allow `-h` outside a repositoryJohannes Schindelin via GitGitGadget, Feb 8, 2022

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.