Skip to content

Commit

Permalink
Adds a quick panel for inserting commit messages
Browse files Browse the repository at this point in the history
  • Loading branch information
spadgos committed Jul 2, 2012
1 parent 0b0c29e commit 1246020
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Default.sublime-commands
Expand Up @@ -131,4 +131,8 @@
"caption": "Git: Gitk",
"command": "git_gitk"
}
,{
"caption": "Git: Commit history",
"command": "git_commit_history"
}
]
1 change: 1 addition & 0 deletions Main.sublime-menu
Expand Up @@ -49,6 +49,7 @@
,{ "caption": "Status...", "command": "git_status" }
,{ "caption": "Branches...", "command": "git_branch" }
,{ "caption": "Merge...", "command": "git_merge" }
,{ "caption": "See commit history...", "command": "git_commit_history"}
]
}
]
Expand Down
22 changes: 18 additions & 4 deletions git.py
Expand Up @@ -14,6 +14,8 @@
# Fun discovery: Sublime on windows still requires posix path separators.
PLUGIN_DIRECTORY = os.getcwd().replace(os.path.normpath(os.path.join(os.getcwd(), '..', '..')) + os.path.sep, '').replace(os.path.sep, '/')

history = []


def main_thread(callback, *args, **kwargs):
# sublime.set_timeout gets used to send things onto the main thread
Expand Down Expand Up @@ -483,7 +485,6 @@ def add_done(self, message, result):
# 6. `commit -F [tempfile]`
class GitCommitCommand(GitWindowCommand):
active_message = False
history = []

def run(self):
self.working_dir = self.get_working_dir()
Expand Down Expand Up @@ -513,9 +514,12 @@ def porcelain_status_done(self, result):
def diff_done(self, result):
settings = sublime.load_settings("Git.sublime-settings")
historySize = settings.get('history_size')
self.history = self.history[:historySize]

def format(line):
return '# ' + line.replace("\n", " ")

lines = [""]
lines.extend(self.history)
lines.extend(map(format, history[:historySize]))
lines.extend([
"# --------------",
"# Please enter the commit message for your changes. Everything below",
Expand All @@ -541,7 +545,7 @@ def message_done(self, message):
message = '\n'.join(lines).strip()

if len(message) and historySize:
self.history.insert(0, '# ' + message.replace("\n", " "))
history.insert(0, message)
# write the temp file
message_file = tempfile.NamedTemporaryFile(delete=False)
message_file.write(message)
Expand All @@ -567,6 +571,16 @@ def on_close(self, view):
command.message_done(message)


class GitCommitHistoryCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.edit = edit
self.view.window().show_quick_panel(history, self.panel_done, sublime.MONOSPACE_FONT)

def panel_done(self, index):
if index > -1:
self.view.replace(self.edit, self.view.sel()[0], history[index] + '\n')


class GitStatusCommand(GitWindowCommand):
def run(self):
self.run_command(['git', 'status', '--porcelain'], self.status_done)
Expand Down

0 comments on commit 1246020

Please sign in to comment.