vpcom commited on
Commit
9caa5c6
1 Parent(s): 2cd869b

file: utils for git push

Browse files
Files changed (1) hide show
  1. utils.py +39 -0
utils.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+
3
+ from huggingface_hub.repository import _lfs_log_progress
4
+
5
+
6
+ def force_git_push(
7
+ repo,
8
+ ):
9
+ """
10
+ force a simple git push
11
+ Blocking. Will return url to commit on remote
12
+ 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()