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