From 3809b4d42430b1efe7c77b6c72e5a95ee4ffacef Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sat, 12 Jun 2021 09:09:55 +0200 Subject: [PATCH] Ignore git submodule failure in gotorevisionx gotorevisionx tries to clean up the git repo before checking out a new revision. In b848b99ba this was changed to reset and clean any submodule as well. In case upstream has a broken submodule configuration this could fail and we can't checkout the new revision. As we are doing a reset and clean after checking out the new revision anyhow, this change ignores submodule errors before the checkout and only makes sure that the main repo is reset and clean. This broke checkupdates for apps where old versions had broken submodules. It checkout out the old version and got stuck, not able to checkout any other version. --- fdroidserver/common.py | 6 ++++++ tests/run-tests | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 32cb1859..dad4c16d 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1103,12 +1103,18 @@ class vcs_git(vcs): # Discard any working tree changes p = FDroidPopen(['git', 'submodule', 'foreach', '--recursive', 'git', 'reset', '--hard'], cwd=self.local, output=False) + if p.returncode != 0: + logging.debug("Git submodule reset failed (ignored) {output}".format(output=p.output)) + p = FDroidPopen(['git', 'reset', '--hard'], cwd=self.local, output=False) if p.returncode != 0: raise VCSException(_("Git reset failed"), p.output) # Remove untracked files now, in case they're tracked in the target # revision (it happens!) p = FDroidPopen(['git', 'submodule', 'foreach', '--recursive', 'git', 'clean', '-dffx'], cwd=self.local, output=False) + if p.returncode != 0: + logging.debug("Git submodule cleanup failed (ignored) {output}".format(output=p.output)) + p = FDroidPopen(['git', 'clean', '-dffx'], cwd=self.local, output=False) if p.returncode != 0: raise VCSException(_("Git clean failed"), p.output) if not self.refreshed: diff --git a/tests/run-tests b/tests/run-tests index ccf1bd40..42374742 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -1295,6 +1295,44 @@ else echo "WARNING: wget not installed, skipping" fi +#------------------------------------------------------------------------------# +echo_header "Test recovering from from broken git submodules" + +if have_git_2_3; then + ROOT=$(create_test_dir) + cd "$ROOT" + mkdir foo bar + cd foo + git init + echo a > a + git add a + GIT_COMMITTER_NAME="Test" GIT_COMMITTER_EMAIL="no@mail" git commit -m "a" --author "Author " + + cd ../bar + git init + git submodule add "file://$(pwd)/../foo" baz + rm .gitmodules + GIT_COMMITTER_NAME="Test" GIT_COMMITTER_EMAIL="no@mail" git commit -am "a" --author "Author " + rm -rf baz + git checkout baz + git tag 2 + + cd .. + mkdir repo + mkdir metadata + echo "RepoType: git" >> metadata/fake.yml + echo "Repo: file://$(pwd)/bar" >> metadata/fake.yml + echo "AutoUpdateMode: Version" >> metadata/fake.yml + echo "UpdateCheckMode: Tags" >> metadata/fake.yml + echo "UpdateCheckData: '|||'" >> metadata/fake.yml + echo "CurrentVersion: 1" >> metadata/fake.yml + echo "CurrentVersionCode: 1" >> metadata/fake.yml + + $fdroid checkupdates --allow-dirty + grep "CurrentVersionCode: 2" metadata/fake.yml +fi + + #------------------------------------------------------------------------------# # remove this to prevent git conflicts and complaining