From f2b2d505a230e17c847714791aaafe576ad45753 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Tue, 5 Nov 2019 16:36:05 -0600 Subject: [PATCH] Reinitialize submodules during upgrade --- test/test_unit_upgrade.py | 3 +++ yadm | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/test/test_unit_upgrade.py b/test/test_unit_upgrade.py index 9b57828..affd641 100644 --- a/test/test_unit_upgrade.py +++ b/test/test_unit_upgrade.py @@ -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 diff --git a/yadm b/yadm index f4f07ee..57898f7 100755 --- a/yadm +++ b/yadm @@ -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"