From 3e8b7d3c77c464b29f7f3e0627ca7354f7de433a Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 11 Apr 2017 15:47:13 -0700 Subject: [PATCH 1/2] 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 --- sha1_file.c | 2 ++ 1 file changed, 2 insertions(+) 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)) From bccb22cbb15d45c940da4c54231949c722d4fe30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 6 Apr 2017 22:41:41 +0200 Subject: [PATCH 2/2] test-read-cache: setup git dir b1ef400e (setup_git_env: avoid blind fall-back to ".git") made programs that tried to access a repository without initializing properly die with a diagnostic message. One offender is test-read-cache, which is used in p0002. Fix it by calling setup_git_directory() before accessing the index. Signed-off-by: Rene Scharfe Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- t/helper/test-read-cache.c | 1 + 1 file changed, 1 insertion(+) diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c index 2a7990efc3..48255eef31 100644 --- a/t/helper/test-read-cache.c +++ b/t/helper/test-read-cache.c @@ -5,6 +5,7 @@ int cmd_main(int argc, const char **argv) int i, cnt = 1; if (argc == 2) cnt = strtol(argv[1], NULL, 0); + setup_git_directory(); for (i = 0; i < cnt; i++) { read_cache(); discard_cache();