Skip to content

Commit

Permalink
has_sha1_file: don't bother if we are not in a repository
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
jrn authored and gitster committed Apr 14, 2017
1 parent 3e98919 commit 3e8b7d3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 3e8b7d3

Please sign in to comment.