summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-05-31 22:42:53 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-06-01 02:48:54 (GMT)
commit14a9bd2898b38449663644f862542d618f332952 (patch)
tree2ef15386854e782b2dc7e18904054fdd740af601 /commit.c
parentfc54c1af3ec09bab8b8ea09768c2da4069b7f53e (diff)
downloadgit-14a9bd2898b38449663644f862542d618f332952.zip
git-14a9bd2898b38449663644f862542d618f332952.tar.gz
git-14a9bd2898b38449663644f862542d618f332952.tar.bz2
prepare_commit_graft: treat non-repository as a noop
The parse_commit_buffer() function consults lookup_commit_graft() to see if we need to rewrite parents. The latter will look at $GIT_DIR/info/grafts. If you're outside of a repository, then this will trigger a BUG() as of b1ef400eec (setup_git_env: avoid blind fall-back to ".git", 2016-10-20). It's probably uncommon to actually parse a commit outside of a repository, but you can see it in action with: cd /not/a/git/repo git index-pack --strict /some/file.pack This works fine without --strict, but the fsck checks will try to parse any commits, triggering the BUG(). We can fix that by teaching the graft code to behave as if there are no grafts when we aren't in a repository. Arguably index-pack (and fsck) are wrong to consider grafts at all. So another solution is to disable grafts entirely for those commands. But given that the graft feature is deprecated anyway, it's not worth even thinking through the ramifications that might have. There is one other corner case I considered here. What should: cd /not/a/git/repo export GIT_GRAFT_FILE=/file/with/grafts git index-pack --strict /some/file.pack do? We don't have a repository, but the user has pointed us directly at a graft file, which we could respect. I believe this case did work that way prior to b1ef400eec. However, fixing it now would be pretty invasive. Back then we would just call into setup_git_env() even without a repository. But these days it actually takes a git_dir argument. So there would be a fair bit of refactoring of the setup code involved. Given the obscurity of this case, plus the fact that grafts are deprecated and probably shouldn't work under index-pack anyway, it's not worth pursuing further. This patch at least un-breaks the common case where you're _not_ using grafts, but we BUG() anyway trying to even find that out. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/commit.c b/commit.c
index 00c99c7..9e49c22 100644
--- a/commit.c
+++ b/commit.c
@@ -196,6 +196,9 @@ static void prepare_commit_graft(void)
if (commit_graft_prepared)
return;
+ if (!startup_info->have_repository)
+ return;
+
graft_file = get_graft_file();
read_graft_file(graft_file);
/* make sure shallows are read */