1
0
Fork 0
mirror of synced 2024-12-13 02:45:45 -05:00

Reinitialize submodules during upgrade

This commit is contained in:
Tim Byrne 2019-11-05 16:36:05 -06:00
parent a217537b26
commit f2b2d505a2
No known key found for this signature in database
GPG key ID: 14DB4FC2465A4B12
2 changed files with 16 additions and 2 deletions

View file

@ -75,6 +75,7 @@ def test_upgrade(tmpdir, runner, yadm, condition):
YADM_REPO="{yadm_dir}/repo.git"
YADM_LEGACY_DIR="{legacy_dir}"
GIT_PROGRAM="{git}"
function cd {{ echo "$@";}}
upgrade
"""
run = runner(command=['bash'], inp=script)
@ -99,3 +100,5 @@ def test_upgrade(tmpdir, runner, yadm, condition):
f'{yadm_dir.join(lpath)}')
assert expected in run.out
assert 'files tracked by yadm have been renamed' in run.out
assert 'submodule deinit -f .' in run.out
assert 'submodule update --init --recursive' in run.out

15
yadm
View file

@ -1091,6 +1091,8 @@ function upgrade() {
fi
# handle other legacy paths
GIT_DIR="$YADM_REPO"
export GIT_DIR
for legacy_path in \
"$YADM_LEGACY_DIR/config" \
"$YADM_LEGACY_DIR/encrypt" \
@ -1106,14 +1108,23 @@ function upgrade() {
echo "Moving $legacy_path to $new_filename"
assert_parent "$new_filename"
# test to see if path is "tracked" in repo, if so 'git mv' must be used
if GIT_DIR="$YADM_REPO" "$GIT_PROGRAM" ls-files --error-unmatch "$legacy_path" >/dev/null 2>&1; then
GIT_DIR="$YADM_REPO" "$GIT_PROGRAM" mv "$legacy_path" "$new_filename" && repo_updates=1
if "$GIT_PROGRAM" ls-files --error-unmatch "$legacy_path" >/dev/null 2>&1; then
"$GIT_PROGRAM" mv "$legacy_path" "$new_filename" && repo_updates=1
else
mv -i "$legacy_path" "$new_filename"
fi
fi
done
# handle submodules, which need to be reinitialized
if [ "$actions_performed" -ne 0 ]; then
cd_work "Upgrade submodules"
if "$GIT_PROGRAM" ls-files --error-unmatch .gitmodules >/dev/null 2>&1; then
"$GIT_PROGRAM" submodule deinit -f .
"$GIT_PROGRAM" submodule update --init --recursive
fi
fi
[ "$actions_performed" -eq 0 ] && \
echo "No legacy paths found. Upgrade is not necessary"