-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcommands.py
114 lines (71 loc) · 2.42 KB
/
commands.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""
author: @endormi
Automated Git commands
Automate the process of using commands such as clone, commit, branch, pull, merge and blame
"""
import subprocess
from pyfiglet import figlet_format
from termcolor import cprint
logo = 'Git-Commands'
class color:
NOTICE = '\033[91m'
END = '\033[0m'
info = color.NOTICE + '''
Automate the process of using commands such as clone, commit, branch, pull, merge and blame.\n''' + color.END
dict = {}
def run(*args):
return subprocess.check_call(['git'] + list(args))
def clone():
print('\nYou will be asked for the user first and then the repository name.\n')
user = input('User: ')
repo = input('Repository: ')
subprocess.Popen(['git', 'clone', 'https://github.com/' + user + '/' + repo + '.git'])
def commit():
commit_message = input('\nType in your commit message: ')
run('commit', '-am', commit_message)
run('push', '-u', 'origin', 'master')
def branch():
branch = input('\nType in the name of the branch you want to make: ')
run('checkout', '-b', branch)
choice = input('\nDo you want to push the branch right now to GitHub? (y/n): ').lower()
if choice == 'y':
run('push', '-u', 'origin', branch)
else:
print('\nOkay, goodbye!\n')
def pull():
print('\nPulls changes from the current folder if *.git is initialized.')
choice = input('\nDo you want to pull the changes from GitHub? (y/n): ').lower()
if choice == 'y':
run('pull')
else:
print('\nOkay, goodbye!\n')
def fetch():
print('\nFetches changes from the current folder.')
run('fetch')
def merge():
branch = input('\nType in the name of your branch: ')
run('merge', branch)
def reset():
filename = input('\nType in the name of your file: ')
run('reset', filename)
def blame():
file = input('\nType in the name of the file: ')
run('blame', file)
def main():
cprint(figlet_format(logo, font='slant'), 'green')
print(f'{info} \n')
print('Commands to use: clone, commit, branch, pull, fetch, merge, reset and blame')
choose_command = input('Type in the command you want to use: ').lower()
dict = {
'clone': clone,
'commit': commit,
'branch': branch,
'pull': pull,
'fetch': fetch,
'merge': merge,
'reset': reset,
'blame': blame
}
dict.get(choose_command, lambda: "Invalid")()
if __name__ == '__main__':
main()