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

index-pack outside of repository?

From
Jeff King <peff@peff.net>
Date
Dec 15, 2016, 20:40 UTC
Message-ID
<20161215204000.avlcfaqjwstkptu2@sigill.intra.peff.net>
Running git on 'next', you can trigger a BUG:
  $ cd /some/repo
  $ git pack-objects --all --stdout </dev/null >/tmp/foo.pack
  $ cd /not-a-git-repo
  $ git index-pack --stdin </tmp/foo.pack
  fatal: BUG: setup_git_env called without repository

This obviously comes from my b1ef400eec (setup_git_env: avoid blind fall-back to ".git", 2016-10-20). What's going on is that index-pack uses RUN_SETUP_GENTLY, but never actually handles the out-of-repo case. When we use the internal git_dir to make "objects/pack/pack-xxx.pack", it barfs.

In older versions of git will just blindly write into ".git/objects/pack", even though there's no repository there.

So I think complaining to the user is the right thing to do here. I started to write a patch to have index-pack notice when it needs a repo and doesn't have one, but the logic is actually a bit unclear. Do we need to complain early _just_ when --stdin is specified, or does that miss somes cases? Likewise, are there cases where --stdin can operate without a repo? I couldn't think of any.

I'm actually wondering if the way it calls die() in 'next' is a pretty reasonable way for things to work in general. It happens when we lazily try to ask for the repository directory. So we don't have to replicate logic to say "are we going to need a repo"; at the moment we need it, we notice we don't have it and die. The only problem is that it says "BUG" and not "this operation must be run in a git repository".

That strategy _might_ be a problem for some programs, which would want to notice the issue early before doing work. But it seems like a reasonable outcome for index-pack. Thoughts?

-Peff
Next: Junio C Hamano
Message 1 of 14 in “index-pack outside of repository?”
  1. Jeff KingDec 15, 2016
  2. Junio C HamanoDec 16, 2016
  3. Jeff KingDec 16, 2016
  4. Jeff KingDec 16, 2016
  5. 1/3 t5000: extract nongit function to test-lib-functions.shJeff King, Dec 16, 2016
  6. 2/3 index-pack: complain when --stdin is used outside of a repoJeff King, Dec 16, 2016
  7. 3/3 t: use nongit() function where applicableJeff King, Dec 16, 2016
  8. Junio C HamanoDec 16, 2016
  9. Junio C HamanoDec 16, 2016
  10. Junio C HamanoDec 16, 2016
  11. Jeff KingDec 16, 2016
  12. Junio C HamanoDec 16, 2016
  13. Junio C HamanoDec 16, 2016
  14. Jeff KingDec 16, 2016

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.