-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit.py
executable file
·144 lines (112 loc) · 4.69 KB
/
commit.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess
import sys
class BColors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
p = subprocess.Popen(['git', 'status'], stdout=subprocess.PIPE)
q = subprocess.Popen(['git', 'status'], stdout=subprocess.PIPE)
push = False
last_commit_title = ""
last_commit_desc = ""
description = ""
somethingToCommit = False
print BColors.BOLD + "\nList of files that can be actioned upon:" + BColors.ENDC
while True:
line = q.stdout.readline()
if 'modified:' in line or 'new file:' in line or 'renamed:' in line or 'deleted:' in line or '.orig' in line:
print BColors.BOLD + BColors.OKBLUE + line.strip() + BColors.ENDC
somethingToCommit = True
if line == '':
q.kill()
if somethingToCommit is False:
print "Nothing to commit. Quiting..."
quit()
confirm = raw_input("\nPlease Enter to continue.(q to quit):\t")
if confirm.strip() == 'q' or confirm.strip() == 'Q':
print "Quiting..."
quit()
break
while True:
new_msg = True
line = p.stdout.readline()
# sys.stdout.write(line)
sys.stdout.flush()
if ".orig" in line:
inp = raw_input("Merging process residual files found: "
+ BColors.BOLD + BColors.OKBLUE + line.strip() + BColors.ENDC +
"\nDo you want to delete it? Press N to NOT DELETE it: ")
if inp.strip() != "n" or inp.strip() != "N":
os.system("rm " + line.strip())
continue
if 'modified:' in line or 'new file:' in line or 'renamed:' in line or 'deleted:' in line:
print BColors.BOLD + BColors.OKBLUE + line.strip() + BColors.ENDC
mfile = ''
if 'modified:' in line:
mfile = line.split("modified: ", 1)[1].strip("\n")
os.system("git diff " + mfile)
if 'new file:' in line:
mfile = line.split("new file: ", 1)[1].strip("\n")
if 'renamed:' in line:
mfile = line.split("renamed: ", 1)[1].strip("\n")
if 'deleted:' in line:
mfile = line.split("deleted: ", 1)[1].strip("\n")
commit_msg = raw_input(
"\nShortcuts\n a: Added new File <file name>\n " +
BColors.WARNING + "c: Checkout this file" + BColors.ENDC +
"\n d: Deleted file <file name>\n "
"i: ignore this file from commit\n "
"p: Performance Optimization\n "
"q: Quit Committing\n "
"r: Renamed file <file name>\n "
"s: Same as last file\n"
"Enter Commit Title: ")
if commit_msg.strip() != "i" and commit_msg.strip() != '':
if commit_msg.strip() == "a":
commit_msg = "Added new File: " + mfile
if commit_msg.strip() == "c":
os.system("git checkout " + mfile)
new_msg = False
continue
if commit_msg.strip() == "d":
commit_msg = "Deleted File: " + mfile
if commit_msg.strip() == "p":
commit_msg = "Performance Optimization"
if commit_msg.strip() == "s":
commit_msg = last_commit_title
description = last_commit_desc
new_msg = False
if commit_msg.strip() == "r":
commit_msg = "Renamed file: " + mfile
if commit_msg.strip() == "q":
print "Quiting..."
quit()
if new_msg:
push = True
description = raw_input("\nEnter Commit Description(Optional):")
last_commit_title = commit_msg.strip()
last_commit_desc = description
if description == "":
os.system("git commit " + mfile + " -m \"" + commit_msg + "\"")
else:
os.system("git commit " + mfile + " -m \"" + commit_msg + "\"" + " -m \"" + description + "\"")
if line == '':
break
if push is True:
print BColors.OKGREEN + "\n☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺" + BColors.ENDC
print BColors.OKBLUE + "Finished Committing all Files." + BColors.ENDC
print BColors.OKGREEN + "☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ \n" + BColors.ENDC
confirm = raw_input('\n\nEnter Y to push to remote: ')
if confirm.strip() == 'Y' or confirm.strip() == 'y':
os.system("git push")
print BColors.BOLD + "\nGit Status Now:" + BColors.ENDC
os.system("git status")
p.kill()