From 66a340fe897aa5154b888708c1c447c683a52f57 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 28 Jun 2022 17:31:40 +0200 Subject: [PATCH] checkupdates: add --verbose progress to push_commits() --- fdroidserver/checkupdates.py | 16 +++++++++++++++- tests/checkupdates.TestCase | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/fdroidserver/checkupdates.py b/fdroidserver/checkupdates.py index f75e96da..bd5f812e 100644 --- a/fdroidserver/checkupdates.py +++ b/fdroidserver/checkupdates.py @@ -684,7 +684,7 @@ def get_last_build_from_app(app: metadata.App) -> metadata.Build: return metadata.Build() -def push_commits(remote_name='origin'): +def push_commits(remote_name='origin', verbose=False): """Push commits using either appid or 'checkupdates' as branch name.""" git_repo = git.Repo.init('.') files = set() @@ -700,6 +700,20 @@ def push_commits(remote_name='origin'): if m: branch_name = m.group(1) # appid if len(files) > 0: + if verbose: + from clint.textui import progress + + bar = progress.Bar() + + class MyProgressPrinter(git.RemoteProgress): + def update(self, op_code, current, maximum=None, message=None): + if isinstance(maximum, float): + bar.show(current, maximum) + + progress = MyProgressPrinter() + else: + progress = None + git_repo.create_head(branch_name, force=True) remote = git_repo.remotes[remote_name] pushinfos = remote.push( diff --git a/tests/checkupdates.TestCase b/tests/checkupdates.TestCase index 402e3bb8..90da2666 100755 --- a/tests/checkupdates.TestCase +++ b/tests/checkupdates.TestCase @@ -379,6 +379,33 @@ class CheckupdatesTest(unittest.TestCase): self.assertNotIn('checkupdates', git_repo.branches) self.assertNotIn(appid, git_repo.remotes.upstream.refs) + def test_push_commits_verbose(self): + class Options: + verbose = True + + fdroidserver.checkupdates.options = Options + repos = self._get_test_git_repos() + git_repo = repos[0] + git_repo.remotes.origin.push(git_repo.active_branch) + git_repo.remotes.upstream.push(git_repo.active_branch) + + # make commit + appid = 'org.adaway' + app = fdroidserver.metadata.read_metadata({appid: -1})[appid] + build = fdroidserver.metadata.Build() + build.versionName = 'fake' + build.versionCode = 999999999 + app.Builds.append(build) + metadata_file = 'metadata/%s.yml' % appid + fdroidserver.metadata.write_metadata(metadata_file, app) + git_repo.index.add(metadata_file) + git_repo.index.commit('changed ' + appid) + + # and push the new commit to the dynamic branch + fdroidserver.checkupdates.push_commits() + self.assertIn(appid, git_repo.branches) + self.assertIn(appid, git_repo.remotes.origin.refs) + def test_prune_empty_appid_branches(self): git_repo, origin_repo, upstream_repo = self._get_test_git_repos() for remote in git_repo.remotes: