Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 171 lines (120 sloc) 5.157 kB
d4d444b @kemayo Rearrange a lot of code
authored
1 import os
2
3 import sublime
4 from git import GitTextCommand, GitWindowCommand, git_root_exist
5
6
7 class GitInit(object):
8 def git_init(self, directory):
9 if os.path.exists(directory):
10 self.run_command(['git', 'init'], self.git_inited, working_dir=directory)
11 else:
12 sublime.status_message("Directory does not exist.")
13
14 def git_inited(self, result):
15 sublime.status_message(result)
16
17
18 class GitInitCommand(GitInit, GitWindowCommand):
19 def run(self):
20 self.get_window().show_input_panel("Git directory", self.get_working_dir(), self.git_init, None, None)
21
22 def is_enabled(self):
23 if not git_root_exist(self.get_working_dir()):
24 return True
25 else:
26 return False
27
28
29 class GitBranchCommand(GitWindowCommand):
30 may_change_files = True
31 command_to_run_after_branch = ['checkout']
32 extra_flags = []
33
34 def run(self):
35 self.run_command(['git', 'branch', '--no-color'] + self.extra_flags, self.branch_done)
36
37 def branch_done(self, result):
38 self.results = result.rstrip().split('\n')
39 self.quick_panel(self.results, self.panel_done,
40 sublime.MONOSPACE_FONT)
41
42 def panel_done(self, picked):
43 if 0 > picked < len(self.results):
44 return
45 picked_branch = self.results[picked]
46 if picked_branch.startswith("*"):
47 return
48 picked_branch = picked_branch.strip()
49 self.run_command(['git'] + self.command_to_run_after_branch + [picked_branch], self.update_status)
50
51 def update_status(self, result):
49e59a6 @SpyMaster356 Show result of branch command in panel
SpyMaster356 authored
52 self.panel(result)
d4d444b @kemayo Rearrange a lot of code
authored
53 global branch
54 branch = ""
55 for view in self.window.views():
56 view.run_command("git_branch_status")
57
58
59 class GitMergeCommand(GitBranchCommand):
60 command_to_run_after_branch = ['merge']
61 extra_flags = ['--no-merge']
62
63
64 class GitDeleteBranchCommand(GitBranchCommand):
65 command_to_run_after_branch = ['branch', '-d']
66
67
68 class GitNewBranchCommand(GitWindowCommand):
69 def run(self):
70 self.get_window().show_input_panel("Branch name", "",
71 self.on_input, None, None)
72
73 def on_input(self, branchname):
74 if branchname.strip() == "":
75 self.panel("No branch name provided")
76 return
77 self.run_command(['git', 'checkout', '-b', branchname])
78
79
e9717d7 add command for checkout remote branch
Airwin authored
80 class GitTrackRemoteBranchCommand(GitBranchCommand):
81 command_to_run_after_branch = ['checkout', '-t']
82 extra_flags = ['-r']
83
84
d4d444b @kemayo Rearrange a lot of code
authored
85 class GitNewTagCommand(GitWindowCommand):
86 def run(self):
87 self.get_window().show_input_panel("Tag name", "", self.on_input, None, None)
88
89 def on_input(self, tagname):
90 if not tagname.strip():
91 self.panel("No branch name provided")
92 return
93 self.run_command(['git', 'tag', tagname])
94
95
96 class GitShowTagsCommand(GitWindowCommand):
97 def run(self):
98 self.run_command(['git', 'tag'], self.fetch_tag)
99
100 def fetch_tag(self, result):
101 self.results = result.rstrip().split('\n')
102 self.quick_panel(self.results, self.panel_done)
103
104 def panel_done(self, picked):
105 if 0 > picked < len(self.results):
106 return
107 picked_tag = self.results[picked]
108 picked_tag = picked_tag.strip()
109 self.run_command(['git', 'show', picked_tag])
110
111
112 class GitPushTagsCommand(GitWindowCommand):
113 def run(self):
114 self.run_command(['git', 'push', '--tags'])
115
116
117 class GitCheckoutCommand(GitTextCommand):
118 may_change_files = True
119
120 def run(self, edit):
121 self.run_command(['git', 'checkout', self.get_file_name()])
122
123
124 class GitFetchCommand(GitWindowCommand):
125 def run(self):
126 self.run_command(['git', 'fetch'], callback=self.panel)
127
128
129 class GitPullCommand(GitWindowCommand):
130 def run(self):
131 self.run_command(['git', 'pull'], callback=self.panel)
132
133
278d13f @mahmoudhossam Add git pull using rebase. Fixes #277
mahmoudhossam authored
134 class GitPullRebaseCommand(GitWindowCommand):
135 def run(self):
136 self.run_command(['git', 'pull', '--rebase'], callback=self.panel)
137
138
d4d444b @kemayo Rearrange a lot of code
authored
139 class GitPullCurrentBranchCommand(GitWindowCommand):
140 command_to_run_after_describe = 'pull'
141
142 def run(self):
143 self.run_command(['git', 'describe', '--contains', '--all', 'HEAD'], callback=self.describe_done)
144
145 def describe_done(self, result):
146 self.current_branch = result.strip()
147 self.run_command(['git', 'remote'], callback=self.remote_done)
148
149 def remote_done(self, result):
150 self.remotes = result.rstrip().split('\n')
151 if len(self.remotes) == 1:
152 self.panel_done()
153 else:
154 self.quick_panel(self.remotes, self.panel_done, sublime.MONOSPACE_FONT)
155
156 def panel_done(self, picked=0):
157 if picked < 0 or picked >= len(self.remotes):
158 return
159 self.picked_remote = self.remotes[picked]
160 self.picked_remote = self.picked_remote.strip()
161 self.run_command(['git', self.command_to_run_after_describe, self.picked_remote, self.current_branch])
162
163
164 class GitPushCommand(GitWindowCommand):
165 def run(self):
166 self.run_command(['git', 'push'], callback=self.panel)
167
168
169 class GitPushCurrentBranchCommand(GitPullCurrentBranchCommand):
170 command_to_run_after_describe = 'push'
Something went wrong with that request. Please try again.