DataAnalyticsLab/Sorvad
0
1import subprocess2 3from huggingface_hub.repository import _lfs_log_progress4 5 6def force_git_push(7 repo,8):9 """10 force a simple git push11 Blocking. Will return url to commit on remote12 repo.13 """14 command = "git push --force"15 16 try:17 with _lfs_log_progress():18 process = subprocess.Popen(19 command.split(),20 stderr=subprocess.PIPE,21 stdout=subprocess.PIPE,22 encoding="utf-8",23 cwd=repo.local_dir,24 )25 26 stdout, stderr = process.communicate()27 return_code = process.poll()28 process.kill()29 30 if len(stderr):31 print(stderr)32 33 if return_code:34 raise subprocess.CalledProcessError(return_code, process.args, output=stdout, stderr=stderr)35 36 except subprocess.CalledProcessError as exc:37 raise EnvironmentError(exc.stderr)38 39 return repo.git_head_commit_url()40 