From: Jonathan Nieder Date: Tue, 11 Apr 2017 22:47:13 +0000 (-0700) Subject: has_sha1_file: don't bother if we are not in a repository X-Git-Tag: v2.13.0-rc0~8^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3e8b7d3c77c464b29f7f3e0627ca7354f7de433a;p=thirdparty%2Fgit.git has_sha1_file: don't bother if we are not in a repository Most callers to this function already require that they are in a git repository, but there is an exception: "git apply" uses has_sha1_file to avoid work if the result of applying a binary patch is already present in the repository. When run outside any repository, this produces an error: fatal: BUG: setup_git_env called without repository Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- diff --git a/sha1_file.c b/sha1_file.c index 2eda9291ee..18bfb4f448 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -3320,6 +3320,8 @@ int has_sha1_file_with_flags(const unsigned char *sha1, int flags) { struct pack_entry e; + if (!startup_info->have_repository) + return 0; if (find_pack_entry(sha1, &e)) return 1; if (has_loose_object(sha1))