Repository navigation
Expand file tree
/
Copy pathgitc.py
More file actions
executable file
·59 lines (43 loc) · 1.43 KB
/
Copy pathgitc.py
File metadata and controls
executable file
·59 lines (43 loc) · 1.43 KB
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
#!/usr/bin/env python3
import subprocess
import sys
def getResults(filters):
results = subprocess.run(['git', 'branch', '-r'], stdout=subprocess.PIPE).stdout.decode('utf-8').split(" ")
results = [result[0 : len(result) - 1] for result in results]
filteredResults = results
if len(filters) == 0:
return results
filteredResults = []
for result in results:
if result == '':
continue
matches_filter = True
for filter in filters:
matches_filter &= filter in result
if matches_filter:
filteredResults.append(result)
return filteredResults
filters = ['']
if (len(sys.argv) > 1):
filters = sys.argv[1:]
# create new branch option
if len(filters) == 2 and filters[0] == "-b":
subprocess.run(['git', 'checkout', '-b', filters[1]], stdout=subprocess.PIPE)
exit(0)
# search branches
user_input = filters
results = []
while (user_input[0] == '' and len(results) != 1) or (len(user_input) != 1 and user_input[0] != "!q" and user_input[0] != "!Q" and (len(user_input[0]) < 1) or (len(user_input[0]) > 0 and user_input[0][-1] != "!")):
results = getResults(user_input)
if (len(results) == 0):
print("-")
for i in range(0, len(results)):
print("%d\t%s" % (i, results[i]))
user_input = input(">> ").split(" ")
if user_input[0] in ("q!", "Q!"):
exit (0)
if user_input[0] == '':
user_input[0] = "0!"
index = user_input[0][0 : -1]
branch = results[int(index)][7:]
subprocess.run(['git', 'checkout', branch], stdout=subprocess.PIPE)