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 <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Apr 11, 2017 at 15:47 UTC
3e8b7d3c77c464b29f7f3e0627ca7354f7de433a
1 file changed
+2
sha1_file.c
+2
@@ -3320,6 +3320,8 @@ int has_sha1_file_with_flags(const unsigned char *sha1, int flags)
3320
{
3321
struct pack_entry e;
3322
3323
+ if (!startup_info->have_repository)
3324
+ return 0;
3325
if (find_pack_entry(sha1, &e))
3326
return 1;
3327
if (has_loose_object(sha1))