Skip to content

Commit

Permalink
Merge pull request #247 from concourse/fix-submodule-name-vs-path
Browse files Browse the repository at this point in the history
fix discrepancy between name/path with submodules
  • Loading branch information
vito committed Apr 10, 2019
2 parents 13949fa + 2e44dd1 commit 9129dd9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
11 changes: 9 additions & 2 deletions assets/in
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,19 @@ if [ "$submodules" != "none" ]; then

submodules="$(git config --list --name-only | sed -ne 's/^submodule\.\(.*\)\.url$/\1/p' | sort -u)"
else
submodules=$(echo $submodules | jq -r '(.[])')
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
fi

for submodule in $submodules; do
submodule_path=$(git config --file .gitmodules --get "submodule.${submodule}.path")

if [ "$depth" -gt 0 ]; then
# remember submodule update config
update_conf_was_set=0
Expand All @@ -153,7 +160,7 @@ if [ "$submodules" != "none" ]; then
git config "submodule.${submodule}.update" "!$bin_dir/deepen_shallow_clone_until_ref_is_found_then_check_out $depth"
fi

git submodule update --no-fetch $depthflag $submodule_parameters $submodule
git submodule update --no-fetch $depthflag $submodule_parameters $submodule_path

if [ "$depth" -gt 0 ]; then
# restore submodule update config
Expand Down
32 changes: 26 additions & 6 deletions test/get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ it_does_not_enter_an_infinite_loop_if_the_ref_cannot_be_found_and_depth_is_set()
echo "${output}" | grep "fatal: reference is not a tree: $ref2"
}

it_can_use_submodules_with_names_that_arent_paths() {
local repo_and_submodule=$(init_repo_with_named_submodule some-name some-path)

local repo=$(echo $repo_and_submodule | cut -d, -f1)
local ref=$(make_commit $repo)

local submodule=$(echo $repo_and_submodule | cut -d, -f2)
local submodule_ref=$(git -C $submodule rev-parse HEAD)

local dest=$TMPDIR/destination

get_uri_with_submodules_all "file://"$repo 1 $dest | jq -e "
.version == {ref: $(echo $ref | jq -R .)}
"

test "$(git -C $dest rev-parse HEAD)" = $ref
test "$(git -C $dest/some-path rev-parse HEAD)" = $submodule_ref
}

it_honors_the_depth_flag_for_submodules() {
local repo_with_submodule_info=$(init_repo_with_submodule)
local project_folder=$(echo $repo_with_submodule_info | cut -d "," -f1)
Expand Down Expand Up @@ -715,6 +734,13 @@ it_retains_tags_with_clean_tags_param() {
test "$(git -C $dest tag)" == $tag
}

run it_can_use_submodules_with_names_that_arent_paths
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
run it_can_get_from_url_at_branch
Expand All @@ -723,16 +749,10 @@ run it_omits_empty_branch_in_metadata
run it_returns_branch_in_metadata
run it_omits_empty_tags_in_metadata
run it_returns_list_of_tags_in_metadata
run it_can_use_submodules_without_perl_warning
run it_honors_the_depth_flag
run it_can_get_from_url_at_depth_at_ref
run it_falls_back_to_deep_clone_if_ref_not_found
run it_does_not_enter_an_infinite_loop_if_the_ref_cannot_be_found_and_depth_is_set
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_and_set_git_config
run it_returns_same_ref
run it_cant_get_commit_with_invalid_key
Expand Down
14 changes: 14 additions & 0 deletions test/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ init_repo_with_submodule() {
echo $project,$submodule
}

init_repo_with_named_submodule() {
local name=$1
local path=$2

local submodule=$(init_repo)
make_commit $submodule >/dev/null
make_commit $submodule >/dev/null

local project=$(init_repo)
git -C $project submodule add --name $1 "file://$submodule" $2 >/dev/null
git -C $project commit -m "Adding Submodule" >/dev/null
echo $project,$submodule
}

init_repo_with_submodule_of_nested_submodule() {
local submodule_and_nested_submodule=$(init_repo_with_submodule)
local nested_submodule=$(echo $submodule_and_nested_submodule | cut -d "," -f2)
Expand Down

0 comments on commit 9129dd9

Please sign in to comment.