-
Notifications
You must be signed in to change notification settings - Fork 0
/
Noogit.py
146 lines (123 loc) · 5.25 KB
/
Noogit.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/python3
import sys
import os
class Noogit():
def __init__(self):
super().__init__()
self.args = sys.argv
self.getCommand()
def getCommand(self):
while (True):
try:
print('1. Initialize repository here')
print('2. Get a repository')
print('3. Check Status')
print('4. Update branch')
print('5. Add a remote')
print('6. Remove a remote')
print('7. Upstream a branch')
print('8. Change to a new branch')
print('9. Delete a branch')
print('10. Upload changes to remote branch')
print('0. Exit')
command = input('\nSelect a command you want to perform: ')
if (command == '1'):
self.runCommand('git init')
elif (command == '2'):
self.handleGet()
elif (command == '3'):
self.runCommand('git status')
elif (command == '4'):
self.handleUpdate()
elif (command == '5'):
self.handleRemoteAdd()
elif (command == '6'):
self.handleRemoteDel()
elif (command == '7'):
self.handleUpstreamAdd()
elif (command == '8'):
self.handleNewBranch()
elif (command == '9'):
self.handleBranchDel()
elif (command == '10'):
self.handleBranchUpload()
elif (command == '0'):
exit()
else:
print('\nInvalid command number! Please select from the list.\n')
except KeyboardInterrupt:
print('\nProgram terminated by user!')
exit()
def handleGet(self):
repository = input('Please enter git repo link: ')
if (repository):
self.runCommand('git clone {}'.format(repository))
else:
self.handleGet()
def handleUpdate(self):
remote = input('Enter the remote to update from(Leave blank for \'upstream\'): ')
branchFrom = input('Enter the branch to get updates from(Leave blank to update from \'master\'): ')
branchTo = input('Enter branch to update(Leave blank to update current branch): ')
if (not remote):
remote = 'upstream'
if (not branchFrom):
branchFrom = 'master'
self.runCommand('git pull {} {}:{}'.format(remote, branchFrom, branchTo))
def handleRemoteAdd(self):
remoteName = input('Enter remote name: ')
remoteUrl = input('Enter remote url: ')
if (remoteUrl and remoteName):
self.runCommand('git remote add {} {}'.format(remoteName, remoteUrl),
additionOut='Remote added.')
else:
print('Please enter both remote name and remote url!')
self.handleRemoteAdd()
def handleRemoteDel(self):
remote = input('Enter remote to remove: ')
if (remote):
self.runCommand('git remote remove {}'.format(remote),
additionOut='Command Completed')
else:
self.handleRemoteDel()
def handleUpstreamAdd(self):
remote = input('Enter the remote to set upstream from(Leave black for \'upstream\'): ')
branchFrom = input('Enter branch to set upstream changes from(Leave black for \'master\'): ')
branchTo = input('Enter branch which has to be set upstream(Leave blank to use the upstream branch): ')
if (not remote):
remote = 'upstream'
if (not branchFrom):
branchFrom = 'master'
if (not branchTo):
branchTo = branchTo
self.runCommand('git branch -u {}/{} {}'.format(remote, branchFrom, branchTo))
def handleNewBranch(self):
branch = input('Enter new name of branch: ')
if (branch):
self.runCommand('git checkout -b {}'.format(branch))
else:
self.handleNewBranch()
def handleBranchDel(self):
branch = input('Enter name of branch to delete: ')
if (branch):
self.runCommand('git branch -d {}'.format(branch))
else:
self.handleNewBranch()
def handleBranchUpload(self):
remote = input('Enter remote name to upload changes to(Leave blank for origin): ')
branchFrom = input('Enter local branch from which the updates will be sent(Leave blank to use current branch): ')
branchTo = input('Enter remote branch name(Leave blank to use same name as local branch): ')
if (not branchTo):
branchTo = branchFrom
if (not remote):
remote = 'origin'
if (branchFrom):
self.runCommand('git push {} {}:{}'.format(remote, branchFrom, branchTo))
else:
self.runCommand('git push {}'.format(remote))
def runCommand(self, cmd, additionOut=''):
print('\n===========================================\n')
os.system(cmd)
if (additionOut):
print(additionOut)
print('\n===========================================\n')
Noogit()