By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

 common.py

View raw Download
text/x-script.python • 729 B
Python script, ASCII text executable
        
            
1
import os
2
import subprocess
3
4
5
def git_command(repo, data, *args, return_err=False, return_exit=False):
6
if not os.path.isdir(repo):
7
raise FileNotFoundError(f"Repo {repo} not found")
8
env = os.environ.copy()
9
10
command = ["git", *args]
11
12
proc = subprocess.Popen(" ".join(command), cwd=repo, env=env, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
13
stdin=subprocess.PIPE)
14
15
if data:
16
proc.stdin.write(data)
17
18
out, err = proc.communicate()
19
exit_code = proc.returncode
20
21
result = (out,)
22
23
if return_err:
24
result = result + (err,)
25
if return_exit:
26
result = result + (exit_code,)
27
28
return result[0] if len(result) == 1 else result
29
30