Skip to content

Commit cce6c08

Browse files
committed
Merge pull request #333 from Starli0n/master
Add three features
2 parents 5d1ede8 + 6e3aa11 commit cce6c08

File tree

7 files changed

+86
-10
lines changed

7 files changed

+86
-10
lines changed

Default.sublime-commands

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
"caption": "Git: Diff Tool All",
5555
"command": "git_diff_tool_all"
5656
}
57+
,{
58+
"caption": "Git: Diff Tool Current File Staged",
59+
"command": "git_diff_tool_commit"
60+
}
61+
,{
62+
"caption": "Git: Diff Tool Staged",
63+
"command": "git_diff_tool_commit_all"
64+
}
5765
,{
5866
"caption": "Git: Commit",
5967
"command": "git_commit"
@@ -159,7 +167,7 @@
159167
"command": "git_custom"
160168
}
161169
,{
162-
"caption": "Git Flow: Feature Start",
170+
"caption": "Git Flow: Feature Start",
163171
"command": "git_flow_feature_start"
164172
}
165173
,{
@@ -226,4 +234,12 @@
226234
"caption": "Git: Commit history",
227235
"command": "git_commit_history"
228236
}
237+
,{
238+
"caption": "Git: Open Config File",
239+
"command": "git_open_config_file"
240+
}
241+
,{
242+
"caption": "Git: Open Config Url",
243+
"command": "git_open_config_url", "args": { "url_param": "remote.origin.url" }
244+
}
229245
]

Git.sublime-settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@
3939
// Symbols for quick git status in status bar
4040
,"statusbar_status": true
4141
,"statusbar_status_symbols" : {"modified": "", "added": "+", "deleted": "×", "untracked": "?", "conflicts": "", "renamed":"R", "copied":"C", "clean": "", "separator": " "}
42+
43+
// Use diff tool configured in Git config
44+
,"diff_tool": false
4245
}

Main.sublime-menu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
,{ "caption": "Amend Last Commit", "command": "git_commit_amend" }
5252
,{ "caption": "-" }
5353
,{ "caption": "Open...", "command": "git_open_file" }
54+
,{ "caption": "Open Config", "command": "git_open_config_file" }
55+
,{ "caption": "Open Url", "command": "git_open_config_url", "args": { "url_param": "remote.origin.url" } }
5456
]
5557
}
5658
,{

config.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
import re
3+
4+
import sublime
5+
from git import GitWindowCommand, git_root
6+
7+
8+
class GitOpenConfigFileCommand(GitWindowCommand):
9+
def run(self):
10+
working_dir = git_root(self.get_working_dir())
11+
config_file = os.path.join(working_dir, '.git/config')
12+
if os.path.exists(config_file):
13+
self.window.open_file(config_file)
14+
else:
15+
sublime.status_message("No config found")
16+
17+
18+
class GitOpenConfigUrlCommand(GitWindowCommand):
19+
def run(self, url_param):
20+
self.run_command(['git', 'config', url_param], self.url_done)
21+
22+
def url_done(self, result):
23+
results = [r for r in result.rstrip().split('\n') if r.startswith("http")]
24+
if len(results):
25+
url = results[0]
26+
user_end = url.index('@')
27+
if user_end > -1:
28+
# Remove user and pass from url
29+
user_start = url.index('//') + 1
30+
user = url[user_start+1:user_end+1]
31+
url = url.replace(user, '')
32+
self.window.run_command('open_url', {"url": url})
33+
else:
34+
sublime.status_message("No url to open")

diff.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ def run(self):
8080
self.run_command(['git', 'difftool'])
8181

8282

83+
class GitDiffToolCommit(GitTextCommand):
84+
def run(self, edit=None):
85+
self.run_command(['git', 'difftool', '--cached', '--', self.get_file_name()])
86+
87+
88+
class GitDiffToolCommitAll(GitWindowCommand):
89+
def run(self):
90+
self.run_command(['git', 'difftool', '--cached'])
91+
92+
8393
class GitGotoDiff(sublime_plugin.TextCommand):
8494
def run(self, edit):
8595
v = self.view

git.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,19 +306,25 @@ def get_window(self):
306306
class GitCustomCommand(GitWindowCommand):
307307
may_change_files = True
308308

309-
def run(self):
310-
self.get_window().show_input_panel("Git command", "",
309+
def run(self, command=None):
310+
if command is None:
311+
self.get_window().show_input_panel("Git command", "",
311312
self.on_input, None, None)
313+
else:
314+
self.on_input(command)
315+
312316

313317
def on_input(self, command):
314318
command = str(command) # avoiding unicode
315319
if command.strip() == "":
316320
self.panel("No git command provided")
317321
return
318322
import shlex
319-
command_splitted = ['git'] + shlex.split(command)
320-
print command_splitted
321-
self.run_command(command_splitted)
323+
cmds = [c.strip() for c in command.split(';') if c.strip() != '']
324+
for cmd in cmds:
325+
command_splitted = ['git'] + shlex.split(cmd)
326+
print command_splitted
327+
self.run_command(command_splitted)
322328

323329

324330
class GitGuiCommand(GitTextCommand):

status.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ def panel_followup(self, picked_status, picked_file, picked_index):
4343
s = sublime.load_settings("Git.sublime-settings")
4444
root = git_root(self.get_working_dir())
4545
if picked_status == '??' or s.get('status_opens_file') or self.force_open:
46-
if(os.path.isfile(os.path.join(root, picked_file))):
47-
self.window.open_file(os.path.join(root, picked_file))
46+
file_name = os.path.join(os.path.realpath(root), picked_file)
47+
if os.path.isfile(file_name):
48+
self.window.open_file(file_name)
4849
else:
49-
self.run_command(['git', 'diff', '--no-color', '--', picked_file.strip('"')],
50-
self.diff_done, working_dir=root)
50+
if s.get('diff_tool'):
51+
self.run_command(['git', 'difftool', '--', picked_file.strip('"')],
52+
working_dir=root)
53+
else:
54+
self.run_command(['git', 'diff', '--no-color', '--', picked_file.strip('"')],
55+
self.diff_done, working_dir=root)
5156

5257
def diff_done(self, result):
5358
if not result.strip():

0 commit comments

Comments
 (0)