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_REPO="{yadm_dir}/repo.git"
YADM_LEGACY_DIR="{legacy_dir}" YADM_LEGACY_DIR="{legacy_dir}"
GIT_PROGRAM="{git}" GIT_PROGRAM="{git}"
function cd {{ echo "$@";}}
upgrade upgrade
""" """
run = runner(command=['bash'], inp=script) run = runner(command=['bash'], inp=script)
@ -99,3 +100,5 @@ def test_upgrade(tmpdir, runner, yadm, condition):
f'{yadm_dir.join(lpath)}') f'{yadm_dir.join(lpath)}')
assert expected in run.out assert expected in run.out
assert 'files tracked by yadm have been renamed' 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 fi
# handle other legacy paths # handle other legacy paths
GIT_DIR="$YADM_REPO"
export GIT_DIR
for legacy_path in \ for legacy_path in \
"$YADM_LEGACY_DIR/config" \ "$YADM_LEGACY_DIR/config" \
"$YADM_LEGACY_DIR/encrypt" \ "$YADM_LEGACY_DIR/encrypt" \
@ -1106,14 +1108,23 @@ function upgrade() {
echo "Moving $legacy_path to $new_filename" echo "Moving $legacy_path to $new_filename"
assert_parent "$new_filename" assert_parent "$new_filename"
# test to see if path is "tracked" in repo, if so 'git mv' must be used # 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 if "$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 "$GIT_PROGRAM" mv "$legacy_path" "$new_filename" && repo_updates=1
else else
mv -i "$legacy_path" "$new_filename" mv -i "$legacy_path" "$new_filename"
fi fi
fi fi
done 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 ] && \ [ "$actions_performed" -eq 0 ] && \
echo "No legacy paths found. Upgrade is not necessary" echo "No legacy paths found. Upgrade is not necessary"