Skip to content

Commit

Permalink
Merge pull request #255 from concourse/simplify-submodule-deepening
Browse files Browse the repository at this point in the history
refactor/simplify submodule deepening
  • Loading branch information
vito committed Apr 16, 2019
2 parents 9129dd9 + 176b21b commit 0e00373
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 69 deletions.
43 changes: 11 additions & 32 deletions assets/in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 0 additions & 37 deletions test/get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0e00373

Please sign in to comment.