Commit 4847cca148b9969c7270f53e12008d8be7dd01a7

Stefan Sperling 2018-03-12T20:56:31

make is_git_repo() check for a usable HEAD reference

diff --git a/lib/repository.c b/lib/repository.c
index 96fa4ce..1dc1c5a 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -108,6 +108,7 @@ is_git_repo(struct got_repository *repo)
 	char *path_head = get_path_head(repo);
 	int ret = 0;
 	struct stat sb;
+	struct got_reference *head_ref;
 
 	if (lstat(path_git, &sb) == -1)
 		goto done;
@@ -128,6 +129,12 @@ is_git_repo(struct got_repository *repo)
 		goto done;
 	if (!S_ISREG(sb.st_mode))
 		goto done;
+
+	/* Check if the HEAD reference can be opened. */
+	if (got_ref_open(&head_ref, repo, GOT_REF_HEAD) != NULL)
+		goto done;
+	got_ref_close(head_ref);
+
 	ret = 1;
 done:
 	free(path_git);