builtin/fmt-merge-message: convert to struct object_id
[gitweb.git] / builtin / grep.c
index 5918a264902fb5c2ddf1dbd9833d66bafd7d62ef..2c727ef499c0fa7b44c0cf1890cc44427dc8921f 100644 (file)
@@ -547,6 +547,7 @@ static int grep_submodule_launch(struct grep_opt *opt,
                name = gs->name;
 
        prepare_submodule_repo_env(&cp.env_array);
+       argv_array_push(&cp.env_array, GIT_DIR_ENVIRONMENT);
 
        /* Add super prefix */
        argv_array_pushf(&cp.args, "--super-prefix=%s%s/",
@@ -615,8 +616,23 @@ static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1,
 {
        if (!is_submodule_initialized(path))
                return 0;
-       if (!is_submodule_populated(path))
-               return 0;
+       if (!is_submodule_populated(path)) {
+               /*
+                * If searching history, check for the presense of the
+                * submodule's gitdir before skipping the submodule.
+                */
+               if (sha1) {
+                       const struct submodule *sub =
+                                       submodule_from_path(null_sha1, path);
+                       if (sub)
+                               path = git_path("modules/%s", sub->name);
+
+                       if (!(is_directory(path) && is_git_directory(path)))
+                               return 0;
+               } else {
+                       return 0;
+               }
+       }
 
 #ifndef NO_PTHREADS
        if (num_threads) {