Skip to content

Commit

Permalink
Force relative submodule paths if git prior to v1.7.10 is used
Browse files Browse the repository at this point in the history
  Older git versions create absolute paths, making it hard to move
  and rename directories for git projects
  • Loading branch information
antontsv committed Oct 25, 2016
1 parent edc0ae8 commit 70041bd
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/commands/pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ function pull {
err $EX_SOFTWARE "Unable to pull $repo. Git says:" "$git_out"
fi;

version_compare $GIT_VERSION 1.7.10
if [[ $?G == 2 ]];then
submodule_fix_out=$(cd "$repo"; submodule_force_relative_path "$repo" 2>&1)
[[ $? == 0 ]] || err $EX_SOFTWARE "Unable force relative path for submodules in $repo. Output says:" "$submodule_fix_out"
fi;

version_compare $GIT_VERSION 1.6.5
if [[ $? != 2 ]]; then
git_out=$(cd "$repo"; git submodule update --recursive --init 2>&1)
Expand Down Expand Up @@ -56,3 +62,23 @@ function symlink_new_files {
ask_symlink ${updated_castles[*]}
return $EX_SUCCESS
}

function submodule_force_relative_path {
if [ -f .gitmodules ];then
local modules=($(cat .gitmodules | grep 'path = ' | awk '{print $3}'))
local parent_separator=";"
for module in "${modules[@]}"; do
local module_full_path="${2//$parent_separator//}$module"
local only_slashes="${module_full_path//[^\/]}"
local module_path_level_count=$((${#only_slashes} + 1))
local prefix=$(printf "%0.s../" $(seq 1 $module_path_level_count))
echo "gitdir: ${prefix}.git/modules/${2//$parent_separator//modules/}$module" > "$module/.git"i
local parents="${2//[^$parent_separator]}"
# .git/module counts as 2 levels, plus one level for each nested parent
local prefix2=$(printf "%0.s../" $(seq 1 $(($module_path_level_count + 2 + ${#parents}))))
git config -f "${1}/.git/modules/${2//$parent_separator//modules/}$module/config" core.worktree "${prefix2}$module_full_path"
submodule_fix_out=$(cd "${1}/$module_full_path"; submodule_force_relative_path "$1" "${2:-}$module$parent_separator" 2>&1)
done
[[ $? == 0 ]] || err $EX_SOFTWARE "Unable force relative path for submodules in $repo. Output says:" "$submodule_fix_out"
fi;
}

0 comments on commit 70041bd

Please sign in to comment.