From 176b21b53c071ce259dd74efee88b23738d35312 Mon Sep 17 00:00:00 2001 From: Alex Suraci Date: Fri, 12 Apr 2019 16:14:16 -0400 Subject: [PATCH] refactor/simplify submodule deepening don't bother restoring config; it should be empty, as the repo was freshly cloned. just unset it after so the implementation detail doesn't leak to builds. moved init to --init on the update command, and made it so everything looks at .gitmodules, rather than relying on 'git submodule init' to populate repo config. Signed-off-by: Alex Suraci --- assets/in | 43 +++++++++++-------------------------------- test/get.sh | 37 ------------------------------------- 2 files changed, 11 insertions(+), 69 deletions(-) diff --git a/assets/in b/assets/in index efe1737f..9ec6d568 100755 --- a/assets/in +++ b/assets/in @@ -124,51 +124,30 @@ fi submodule_parameters="" if [ "$submodule_remote" != "false" ]; then - submodule_parameters+=" --remote " + submodule_parameters+=" --remote " fi if [ "$submodule_recursive" != "false" ]; then - submodule_parameters+=" --recursive " + submodule_parameters+=" --recursive " fi if [ "$submodules" != "none" ]; then - if [ "$submodules" == "all" ]; then - git submodule init - - submodules="$(git config --list --name-only | sed -ne 's/^submodule\.\(.*\)\.url$/\1/p' | sort -u)" - else - submodules=$( - echo $submodules | jq -r '.[]' | while read path; do - git config --file .gitmodules --name-only --get-regexp '\.path$' $path | - sed -e 's/^submodule\.\(.\+\)\.path$/\1/' - done - ) - - git submodule init $submodules + value_regexp="." + if [ "$submodules" != "all" ]; then + value_regexp="$(echo $submodules | jq -r 'map(. + "$") | join("|")')" fi - for submodule in $submodules; do - submodule_path=$(git config --file .gitmodules --get "submodule.${submodule}.path") + git config --file .gitmodules --name-only --get-regexp '\.path$' "$value_regexp" | + sed -e 's/^submodule\.\(.\+\)\.path$/\1/' | while read submodule_name; do + submodule_path=$(git config --file .gitmodules --get "submodule.${submodule_name}.path") if [ "$depth" -gt 0 ]; then - # remember submodule update config - update_conf_was_set=0 - if update_conf="$(git config --get "submodule.${submodule}.update")"; then - update_conf_was_set=1 - fi - - # temporarily set to our shallow clone deepening shell script - git config "submodule.${submodule}.update" "!$bin_dir/deepen_shallow_clone_until_ref_is_found_then_check_out $depth" + git config "submodule.${submodule_name}.update" "!$bin_dir/deepen_shallow_clone_until_ref_is_found_then_check_out $depth" fi - git submodule update --no-fetch $depthflag $submodule_parameters $submodule_path + git submodule update --init --no-fetch $depthflag $submodule_parameters $submodule_path if [ "$depth" -gt 0 ]; then - # restore submodule update config - if [ "$update_conf_was_set" != 0 ]; then - git config "submodule.${submodule}.update" "$update_conf" - else - git config --unset "submodule.${submodule}.update" - fi + git config --unset "submodule.${submodule_name}.update" fi done fi diff --git a/test/get.sh b/test/get.sh index 9afaf35e..178c71c4 100755 --- a/test/get.sh +++ b/test/get.sh @@ -374,42 +374,6 @@ it_fails_if_the_ref_cannot_be_found_while_deepening_a_submodule() { echo "${output}" | grep "fatal: reference is not a tree: $submodule_last_commit_id" } -# the submodule incremental deepening depends on overwriting the update method -# of the submodule, so we should test if it's properly restored -it_preserves_the_submodule_update_method() { - local repo_with_submodule_info=$(init_repo_with_submodule) - local main_repo=${repo_with_submodule_info%,*} - local submodule_repo=${repo_with_submodule_info#*,} - local submodule_name=${submodule_repo##*/} - local main_repo_last_commit_id=$(git -C $main_repo rev-parse HEAD) - - local dest=$TMPDIR/destination - - get_uri_with_submodules_all "file://$main_repo" 1 $dest | jq -e " - .version == {ref: $(echo $main_repo_last_commit_id | jq -R .)} - " - - # "git config ..." returns false if the key is not found (unset) - ! git -C "$dest" config "submodule.${submodule_name}.update" - - - rm -rf "$dest" - - - git -C "$main_repo" config --file .gitmodules --replace-all "submodule.${submodule_name}.update" merge - git -C "$main_repo" add .gitmodules - git -C "$main_repo" commit -m 'Add .gitmodules' >/dev/null - - local main_repo_last_commit_id=$(git -C $main_repo rev-parse HEAD) - local submodule_repo_last_commit_id=$(git -C $submodule_repo rev-parse HEAD) - - get_uri_with_submodules_all "file://$main_repo" 1 $dest | jq -e " - .version == {ref: $(echo $main_repo_last_commit_id | jq -R .)} - " - - test "$(git -C "$dest" config "submodule.${submodule_name}.update")" == "merge" -} - it_honors_the_parameter_flags_for_submodules() { local repo_info=$(init_repo_with_submodule_of_nested_submodule) local project_folder=$(echo $repo_info | cut -d "," -f1) @@ -739,7 +703,6 @@ run it_can_use_submodules_without_perl_warning run it_honors_the_depth_flag_for_submodules run it_falls_back_to_deep_clone_of_submodule_if_ref_not_found run it_fails_if_the_ref_cannot_be_found_while_deepening_a_submodule -run it_preserves_the_submodule_update_method run it_honors_the_parameter_flags_for_submodules run it_can_get_from_url run it_can_get_from_url_at_ref