Skip to content

Commit

Permalink
Make empty repo sync work
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Yikun committed Mar 11, 2021
1 parent e58def8 commit bef2120
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/verify-on-ubuntu-org.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
debug: true
10 changes: 10 additions & 0 deletions hub-mirror/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit bef2120

Please sign in to comment.