-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo.py
207 lines (156 loc) · 6.15 KB
/
repo.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import os
import sublime
from . import GitWindowCommand, git_root_exist
class GitInit(object):
def git_init(self, directory):
if os.path.exists(directory):
self.run_command(["git", "init"], self.git_inited, working_dir=directory)
else:
sublime.status_message("Directory does not exist.")
def git_inited(self, result):
sublime.status_message(result)
class GitInitCommand(GitInit, GitWindowCommand):
def run(self):
self.get_window().show_input_panel(
"Git directory", self.get_working_dir(), self.git_init, None, None
)
def is_enabled(self):
if not git_root_exist(self.get_working_dir()):
return True
else:
return False
class GitBranchCommand(GitWindowCommand):
may_change_files = True
command_to_run_after_branch = ["checkout"]
extra_flags = []
def run(self):
self.run_command(
["git", "branch", "--no-color"] + self.extra_flags, self.branch_done
)
def branch_done(self, result):
self.results = result.rstrip().split("\n")
self.quick_panel(self.results, self.panel_done, sublime.MONOSPACE_FONT)
def panel_done(self, picked):
if 0 > picked < len(self.results):
return
picked_branch = self.results[picked]
if picked_branch.startswith("*"):
return
picked_branch = picked_branch.strip()
self.run_command(
["git"] + self.command_to_run_after_branch + [picked_branch],
self.update_status,
)
def update_status(self, result):
self.panel(result)
global branch
branch = ""
for view in self.window.views():
view.run_command("git_branch_status")
class GitMergeCommand(GitBranchCommand):
command_to_run_after_branch = ["merge"]
extra_flags = ["--no-merge"]
class GitDeleteBranchCommand(GitBranchCommand):
command_to_run_after_branch = ["branch", "-d"]
class GitForceDeleteBranchCommand(GitDeleteBranchCommand):
command_to_run_after_branch = ["branch", "-D"]
class GitNewBranchCommand(GitWindowCommand):
def run(self):
self.get_window().show_input_panel("Branch name", "", self.on_input, None, None)
def on_input(self, branchname):
if branchname.strip() == "":
self.panel("No branch name provided")
return
self.run_command(["git", "checkout", "-b", branchname], self.branch_done)
def branch_done(self, result):
self.panel(result)
for view in self.window.views():
view.run_command("git_branch_status")
class GitTrackRemoteBranchCommand(GitBranchCommand):
command_to_run_after_branch = ["checkout", "--track"]
extra_flags = ["--remote"]
class GitSetUpstreamBranchCommand(GitBranchCommand):
command_to_run_after_branch = ["branch", "--set-upstream-to"]
extra_flags = ["--remote"]
class GitNewTagCommand(GitWindowCommand):
def run(self):
self.get_window().show_input_panel("Tag name", "", self.on_input, None, None)
def on_input(self, tagname):
if not tagname.strip():
self.panel("No branch name provided")
return
self.run_command(["git", "tag", tagname])
class GitDeleteTagCommand(GitWindowCommand):
def run(self):
self.run_command(["git", "tag"], self.fetch_tag)
def fetch_tag(self, result):
if result.strip() == "":
sublime.status_message("No Tags provided.")
return
self.results = result.rstrip().split("\n")
self.quick_panel(self.results, self.panel_done)
def panel_done(self, picked):
if 0 > picked < len(self.results):
return
picked_tag = self.results[picked]
picked_tag = picked_tag.strip()
if sublime.ok_cancel_dialog('Delete "%s" Tag?' % picked_tag, "Delete"):
self.run_command(["git", "tag", "-d", picked_tag])
class GitShowTagsCommand(GitWindowCommand):
def run(self):
self.run_command(["git", "tag"], self.fetch_tag)
def fetch_tag(self, result):
self.results = result.rstrip().split("\n")
self.quick_panel(self.results, self.panel_done)
def panel_done(self, picked):
if 0 > picked < len(self.results):
return
picked_tag = self.results[picked]
picked_tag = picked_tag.strip()
self.run_command(["git", "show", picked_tag])
class GitCheckoutTagCommand(GitWindowCommand):
def run(self):
self.run_command(["git", "tag"], self.fetch_tag)
def fetch_tag(self, result):
if result.strip() == "":
sublime.status_message("No Tags provided.")
return
self.results = result.rstrip().split("\n")
self.quick_panel(self.results, self.panel_done)
def panel_done(self, picked):
if 0 > picked < len(self.results):
return
picked_tag = self.results[picked]
picked_tag = picked_tag.strip()
self.run_command(["git", "checkout", "tags/%s" % picked_tag])
class GitPullCurrentBranchCommand(GitWindowCommand):
command_to_run_after_describe = "pull"
def run(self):
self.run_command(
["git", "describe", "--contains", "--all", "HEAD"],
callback=self.describe_done,
)
def describe_done(self, result):
self.current_branch = result.strip()
self.run_command(["git", "remote"], callback=self.remote_done)
def remote_done(self, result):
self.remotes = result.rstrip().split("\n")
if len(self.remotes) == 1:
self.panel_done()
else:
self.quick_panel(self.remotes, self.panel_done, sublime.MONOSPACE_FONT)
def panel_done(self, picked=0):
if picked < 0 or picked >= len(self.remotes):
return
self.picked_remote = self.remotes[picked]
self.picked_remote = self.picked_remote.strip()
self.run_command(
[
"git",
self.command_to_run_after_describe,
self.picked_remote,
self.current_branch,
]
)
class GitPushCurrentBranchCommand(GitPullCurrentBranchCommand):
command_to_run_after_describe = "push"