-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgit_push.py
More file actions
113 lines (99 loc) · 3.49 KB
/
git_push.py
File metadata and controls
113 lines (99 loc) · 3.49 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
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
import os
import sys
import re
""" Committing and Pushing the changes """
def commit_process():
commit = ['y','Y','yes','Yes','YES']
leave = ['n','N','no','No','NO']
option = raw_input("Do you want to commit the changes(y/n):")
if option in commit:
os.system('git commit -m "updated the feauture"')
os.system('git push origin master')
print("committing and pushing are done")
elif option in leave:
print("Changes are made but not committed")
else:
print("Invalid option- Try again")
commit_process()
""" To make list of lists into a single list """
def list_of_lists_to_single_list(list1):
list2 = []
for x in list1:
if type(x) == type([]):
for l in x:
list2.append(l)
else:
list2.append(x)
list2 = set(list2)
list2 = list(list2)
return list2
""" Adding the files to the Staging area """
def adding_changes(list1):
z = "\t"
list2 = []
list3 = []
list4 = []
list5 = []
list6 = []
for line in list1:
if z in line:
list2.append(line)
a = "modified:"
b = "deleted:"
for line in list2:
if a in line:
line = line.split(" ")
elif b in line:
line = line.split(" ")
list5.append(line)
list3.append(line)
list4 = list_of_lists_to_single_list(list3)
if "\tmodified:" in list4:
list4.remove("\tmodified:")
if "\tdeleted:" in list4:
list4.remove("\tdeleted:")
if (len(list5)>0):
list6 = list_of_lists_to_single_list(list5)
list6.remove("\tdeleted:")
print("List of files removed from staging")
print(list6)
for x in list6:
list4.remove(x)
os.system('git rm %s' %(x))
print("List of files added for staging")
print(list4)
for x in list4:
os.system('git add %s' %(x))
commit_process()
""" Checking the status of the files in the git clone """
def check_status():
print("I am in check_status")
file_path = '%s/status.txt' %(path)
os.system('git status > %s' %(file_path))
file = open(file_path,"r")
stat_data = file.read()
os.system('rm -rf %s' %(file_path))
status1 = "nothing to commit"
status2 = "Changes not staged for commit:"
status3 = "Changes to be committed:"
status4 = "Untracked files:"
if status1 in stat_data:
print("up-to-date")
elif status2 in stat_data and not status3 in stat_data or status4 in stat_data:
list1 = stat_data.split('\n')
list1.remove('\tstatus.txt')
adding_changes(list1)
elif status2 in stat_data and status3 in stat_data:
list1 = stat_data.split('\n')
list1.remove('\tstatus.txt')
index1 = list1.index("Changes not staged for commit:")
list2 = list1[:index1]
list3 = list1[index1:]
adding_changes(list3)
elif status3 in stat_data:
commit_process()
else:
pass
path = raw_input("Enter the local git path to commit:\n")
os.chdir(path)
check_status()