diff --git a/Default.sublime-commands b/Default.sublime-commands index 2adddd11..a2ea935e 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -117,6 +117,10 @@ ,{ "caption": "Git: Stash Drop", "command": "git_stash_drop" + } + ,{ + "caption": "Git: Stash List", + "command": "git_stash_list" } ,{ "caption": "Git: Add Current File", diff --git a/Main.sublime-menu b/Main.sublime-menu index a88db6e5..156c2380 100644 --- a/Main.sublime-menu +++ b/Main.sublime-menu @@ -63,6 +63,7 @@ ,{ "caption": "Pop", "command": "git_stash_pop" } ,{ "caption": "Apply", "command": "git_stash_apply" } ,{ "caption": "Drop", "command": "git_stash_drop" } + ,{ "caption": "List", "command": "git_stash_list" } ] } ,{ "caption": "-" } diff --git a/stash.py b/stash.py index d76fed89..46ddba4a 100644 --- a/stash.py +++ b/stash.py @@ -45,3 +45,35 @@ def stash_list_panel_done(self, picked=0): class GitStashDropCommand(GitStashApplyCommand): command_to_run_after_list = 'drop' + +class GitStashListCommand(GitWindowCommand): + command_to_run_after_list = 'show' + + def run(self): + self.run_command(['git', 'stash', 'list'], self.stash_list_done) + + def stash_list_done(self, result): + # No stash list at all + if not result: + self.panel('No stash found') + return + + self.results = result.rstrip().split('\n') + + # If there is only one, apply it + if len(self.results) == 1: + self.stash_list_panel_done() + else: + self.quick_panel(self.results, self.stash_list_panel_done) + + def stash_list_panel_done(self, picked=0): + if 0 > picked < len(self.results): + return + + # get the stash ref (e.g. stash@{3}) + self.stash = self.results[picked].split(':')[0] + self.run_command(['git', 'stash', self.command_to_run_after_list, '-p', self.stash], + self.show_diff, stash = self.stash); + + def show_diff(self, result, stash): + self.scratch(result, title="%s" % stash, syntax="Packages/Diff/Diff.tmLanguage") \ No newline at end of file