-
Notifications
You must be signed in to change notification settings - Fork 0
/
git3.py
48 lines (39 loc) · 1.1 KB
/
git3.py
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
41
42
43
44
45
46
47
48
#!/usr/bin/env -S uv run python
import sys
import subprocess
def run_cmd(
cmd,
print_stdout=False,
exit_on_err=False
):
result = subprocess.run(
cmd,
shell=True,
capture_output=True,
text=True,
)
if result.returncode != 0:
print('\n[ERR_IN_COMMAND]')
print('command:',cmd,'\n')
print(result.stderr)
if result.stdout:
print('output:')
print(result.stdout)
sys.exit()
else:
if print_stdout:
print(result.stdout)
return None, result.stdout
n_arg = len(sys.argv) - 1
msg = sys.argv[2]
if ' ' not in msg:
msg = msg.replace('-',' ')
if n_arg == 2 :
run_cmd(f'git add {sys.argv[1]}', print_stdout=True,exit_on_err=True)
run_cmd(f'git commit -m "{msg}"', print_stdout=True, exit_on_err=True)
run_cmd(f'git push', print_stdout=True)
else:
print('\ngit3 needs exactly 2 arguments',end=' ')
print('first arg will passed to git add',end=' ')
print('and second argument is commit message')
print(' ',n_arg,'argument instead of 2')