File size: 978 Bytes
9caa5c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import subprocess

from huggingface_hub.repository import _lfs_log_progress


def force_git_push(
    repo,
):
    """
    force a simple git push
    Blocking. Will return url to commit on remote
    repo.
    """
    command = "git push --force"

    try:
        with _lfs_log_progress():
            process = subprocess.Popen(
                command.split(),
                stderr=subprocess.PIPE,
                stdout=subprocess.PIPE,
                encoding="utf-8",
                cwd=repo.local_dir,
            )

            stdout, stderr = process.communicate()
            return_code = process.poll()
            process.kill()

            if len(stderr):
                print(stderr)

            if return_code:
                raise subprocess.CalledProcessError(return_code, process.args, output=stdout, stderr=stderr)

    except subprocess.CalledProcessError as exc:
        raise EnvironmentError(exc.stderr)

    return repo.git_head_commit_url()