-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.py
149 lines (129 loc) · 4.86 KB
/
git.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
from Commando.plugin import CommandoRun, CommandoCmd
from .vcs import VcsRepoCommando, VcsFileCommando
from Commando import core as commando_core
import re
import os
class GitRepoCommando(VcsRepoCommando):
def is_enabled(self, context=None):
return self.get_type(context=context) == 'git'
class GitRepoCommando(VcsFileCommando):
def is_enabled(self, context=None):
return (
self.get_view(context=context) is not None
and self.get_view(context=context).file_name() is not None
and self.get_type(context=context) == 'git'
)
class CommandoGitStatusCommand(CommandoRun):
def commands(self):
return [
['commando_exec', {'cmd': ['git', 'status', '--porcelain']}],
'commando_git_parse_status',
'commando_quick_panel',
'commando_git_status_selected'
]
class CommandoGitDiffFileCommand(CommandoRun):
def commands(self):
return [
['commando_exec', {'cmd': ['git', 'diff', '$file']}],
['commando_new_file', {'syntax': 'Diff', 'readonly': True, 'scratch': True, 'name': 'GIT_DIFF_FILE'}]
]
class CommandoGitDiffRepoCommand(CommandoRun):
def commands(self):
return [
['commando_exec', {'cmd': ['git', 'diff']}],
['commando_new_file', {'syntax': 'Diff', 'readonly': True, 'scratch': True, 'name': 'GIT_DIFF_REPO'}]
]
class CommandoGitLogRepoCommand(CommandoRun):
def commands(self):
return [
['commando_exec', {'cmd': ['git', 'log']}],
['commando_new_file', {'syntax': 'Packages/CommandoVCS/GitLog.tmLanguage', 'readonly': True, 'scratch': True, 'name': 'GIT_LOG_REPO'}]
]
class CommandoGitCheckoutFileCommand(CommandoRun):
def commands(self):
return [
['commando_ok_cancel_dialog', {'msg': 'Are you sure?\n\nThis will wipe out all local changes and cannot be undone.'}],
['commando_exec', {'cmd': ['git', 'checkout', '$file']}]
]
class CommandoGitLogFileCommand(CommandoRun):
def commands(self):
return [
['commando_exec', {'cmd': ['git', 'log', '$file']}],
['commando_new_file', {'syntax': 'Packages/CommandoVCS/GitLog.tmLanguage', 'readonly': True, 'scratch': True, 'name': 'GIT_LOG_FILE'}]
]
class CommandoGitAddFileCommand(CommandoRun):
def commands(self):
return [
['commando_exec', {'cmd': ['git', 'add', '$file']}]
]
class CommandoGitResetFileCommand(CommandoRun):
def commands(self):
return [
['commando_exec', {'cmd': ['git', 'reset', '$file']}]
]
class CommandoGitCommitCommand(CommandoRun):
def commands(self):
return [
['commando_exec', {'cmd': ['git', 'diff', '--cached']}],
['commando_switch', {
'': [['commando_show_panel', {'input': 'No changes.'}]],
'default': [
['commando_exec', {'cmd': ['git', 'status']}],
'commando_git_prep_commit_prompt',
['commando_new_file', {
'scratch': True,
'name': 'GIT_COMMIT',
'on_close': [
'commando_git_prep_commit_message',
['commando_exec', {'cmd': ['git', 'commit', '-m', '$input']}],
'commando_show_panel'
]
}],
]
}]
]
class CommandoGitPushCommand(CommandoRun):
def commands(self):
return [
['commando_exec', {'cmd': ['git', 'push']}],
'commando_show_panel'
]
class CommandoGitPullCommand(CommandoRun):
def commands(self):
return [
['commando_exec', {'cmd': ['git', 'pull']}],
'commando_show_panel'
]
class CommandoGitBlameCommand(CommandoRun):
def commands(self):
return [
['commando_exec', {'cmd': ['git', 'blame', '--date=short', '-w', '$file']}],
['commando_new_file', {'syntax': 'Packages/CommandoVCS/GitBlame.tmLanguage', 'readonly': True, 'scratch': True, 'name': 'GIT_BLAME_FILE'}]
]
#
# Helpers
#
class CommandoGitParseStatus(CommandoCmd):
def cmd(self, context, input, args):
if not input:
context['commands'] = [
["commando_show_panel", {"input": "No changes."}]
]
else:
context['input'] = input.splitlines()
class CommandoGitStatusSelected(CommandoCmd):
def cmd(self, context, input, args):
tokens = re.split('\s+', input.strip())
if tokens and tokens[1] and os.path.exists(self.get_path(context, tokens[1])):
commando_core.open_file(context, self.get_path(context, tokens[1]))
class CommandoGitPrepCommitPrompt(CommandoCmd):
def cmd(self, context, input, args):
context['input'] = "\n" \
+ "# Enter a commit message above. Any lines beginning with # are ignored. A blank message will abort the commit.\n" \
+ "#\n" \
+ "\n".join(map(lambda l: "# "+l if not l or l[0] != "#" else l, input.strip().split("\n")))
class CommandoGitPrepCommitMessage(CommandoCmd):
def cmd(self, context, input, args):
context['input'] = "\n".join(map(lambda l: l if not l or l[0] != "#" else "", input.strip().split("\n"))).strip()
if not context['input']:
return False