@@ -22,6 +22,7 @@
#include "parse-options.h"
#include "object-store.h"
#include "commit-reach.h"
+#include "shallow.h"
static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
static int initialized_fetch_ref_tips;
@@ -901,6 +902,9 @@ static void collect_changed_submodules(struct repository *r,
save_warning = warn_on_object_refname_ambiguity;
warn_on_object_refname_ambiguity = 0;
+ /* make sure shallows are read */
+ is_repository_shallow(the_repository);
+
repo_init_revisions(r, &rev, NULL);
setup_revisions(argv->nr, argv->v, &rev, &s_r_opt);
warn_on_object_refname_ambiguity = save_warning;
@@ -1031,4 +1031,14 @@ test_expect_success 'recursive fetch after deinit a submodule' '
test_cmp expect actual
'
+test_expect_success 'recursive fetch does not fail with --update-shallow' '
+ git clone --no-local --depth=2 --recurse-submodules . shallow &&
+ git init notshallow &&
+ (
+ cd notshallow &&
+ git submodule add ../submodule sub &&
+ git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* --recurse-submodules
+ )
+'
+
test_done
In a repository with submodules, "git fetch --update-shallow" can fail. This happens because "git fetch" does not read shallows when rev walking the newly fetched commits to find changed submodules, thus the rev walk may try to read the parent of a shallow and fail. This can occur when --recurse-submodules is not passed, because the default behavior is to fetch changed submodules i.e. --recurse-submodules=on-demand. Fix this by reading shallows before the rev walk, and test for it. Signed-off-by: Glen Choo <chooglen@google.com> --- submodule.c | 4 ++++ t/t5526-fetch-submodules.sh | 10 ++++++++++ 2 files changed, 14 insertions(+)