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