From bef21208e7c8fe692998e2567f00d3db97a7c540 Mon Sep 17 00:00:00 2001 From: Yikun Jiang Date: Wed, 10 Mar 2021 22:58:08 +0800 Subject: [PATCH] Make empty repo sync work If the repo is empty, the repo pushing will be skipped, that means, only empty repo will be created, and keep it empty like source repo. --- .github/workflows/verify-on-ubuntu-org.yml | 4 ++-- hub-mirror/mirror.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/verify-on-ubuntu-org.yml b/.github/workflows/verify-on-ubuntu-org.yml index 3b8cb6d8..06872402 100644 --- a/.github/workflows/verify-on-ubuntu-org.yml +++ b/.github/workflows/verify-on-ubuntu-org.yml @@ -17,6 +17,6 @@ jobs: account_type: org # Only sync normal repo black_list: 'test' - white_list: 'normal,test' + white_list: 'normal,test,empty' force_update: true - debug: true \ No newline at end of file + debug: true diff --git a/hub-mirror/mirror.py b/hub-mirror/mirror.py index 39235663..0814cee7 100644 --- a/hub-mirror/mirror.py +++ b/hub-mirror/mirror.py @@ -57,9 +57,19 @@ def create(self): print("(2/3) Creating...") self.hub.create_dst_repo(self.name) + def _check_empty(self, repo): + cmd = ["-n", "1", "--all"] + if repo.git.rev_list(*cmd): + return False + else: + return True + @retry(wait=wait_exponential(), reraise=True, stop=stop_after_attempt(3)) def push(self, force=False): local_repo = git.Repo(self.repo_path) + if self._check_empty(local_repo): + print("Empty repo %s, skip pushing." % self.src_url) + return cmd = ['set-head', 'origin', '-d'] local_repo.git.remote(*cmd) try: