Example #1
0
 def __init__(self, *args, **kwargs):
     """Initialize GitGutterCommand object."""
     sublime_plugin.TextCommand.__init__(self, *args, **kwargs)
     self.git_handler = GitGutterHandler(self.view)
     self.show_diff_handler = GitGutterShowDiff(self.git_handler)
     # Last enabled state for change detection
     self._enabled = False
Example #2
0
    def run(self, edit, **kwargs):
        if not self.git_handler:
            self.git_handler = GitGutterHandler(self.view)
        if not self.show_diff_handler:
            self.show_diff_handler = GitGutterShowDiff(self.view,
                                                       self.git_handler)

        if not self.git_handler.on_disk() or not self.git_handler.git_dir:
            return

        if kwargs:
            self._handle_subcommand(**kwargs)
            return

        self.show_diff_handler.run()
Example #3
0
class GitGutterCommand(sublime_plugin.TextCommand):
    def __init__(self, *args, **kwargs):
        sublime_plugin.TextCommand.__init__(self, *args, **kwargs)
        self.is_valid_view = self.view.settings().get('is_widget') is not True
        self.git_handler = None
        self.show_diff_handler = None

    def is_enabled(self, **kwargs):
        return self.is_valid_view and bool(settings.git_binary_path)

    def run(self, edit, **kwargs):
        if not self.git_handler:
            self.git_handler = GitGutterHandler(self.view)
        if not self.show_diff_handler:
            self.show_diff_handler = GitGutterShowDiff(self.view,
                                                       self.git_handler)

        if not self.git_handler.on_disk() or not self.git_handler.git_dir:
            return

        if kwargs:
            self._handle_subcommand(**kwargs)
            return

        self.show_diff_handler.run()

    def _handle_subcommand(self, **kwargs):
        view = self.view
        git_handler = self.git_handler
        action = kwargs['action']
        if action == 'jump_to_next_change':
            GitGutterJumpToChanges(view, git_handler).jump_to_next_change()
        elif action == 'jump_to_prev_change':
            GitGutterJumpToChanges(view, git_handler).jump_to_prev_change()
        elif action == 'compare_against_commit':
            GitGutterCompareCommit(view, git_handler).run()
        elif action == 'compare_against_branch':
            GitGutterCompareBranch(view, git_handler).run()
        elif action == 'compare_against_tag':
            GitGutterCompareTag(view, git_handler).run()
        elif action == 'compare_against_head':
            GitGutterCompareHead(view, git_handler).run()
        elif action == 'compare_against_origin':
            GitGutterCompareOrigin(view, git_handler).run()
        elif action == 'show_compare':
            GitGutterShowCompare(view, git_handler).run()
        elif action == 'show_diff_popup':
            point = kwargs['point']
            highlight_diff = kwargs['highlight_diff']
            flags = kwargs['flags']
            show_diff_popup(view,
                            point,
                            git_handler,
                            highlight_diff=highlight_diff,
                            flags=flags)
        else:
            assert False, 'Unhandled sub command "%s"' % action
Example #4
0
 def add(view):
     key = ViewCollection.get_key(view)
     try:
         from .git_gutter_handler import GitGutterHandler
     except (ImportError, ValueError):
         from git_gutter_handler import GitGutterHandler
     handler = ViewCollection.views[key] = GitGutterHandler(view)
     handler.reset()
     return handler
Example #5
0
class GitGutterCommand(sublime_plugin.TextCommand):
    region_names = ['deleted_top', 'deleted_bottom',
                    'deleted_dual', 'inserted', 'changed',
                    'untracked', 'ignored']

    def __init__(self, *args, **kwargs):
        sublime_plugin.TextCommand.__init__(self, *args, **kwargs)
        self.settings = GitGutterSettings()
        self.settings.load_settings()
        self.git_handler = GitGutterHandler(self.view, self.settings)
        self.show_diff_handler = GitGutterShowDiff(self.view, self.git_handler, self.settings)

    def run(self, edit_permit, **kwargs):
        if not self.git_handler.on_disk() or not self.git_handler.git_dir:
            return

        if kwargs and 'action' in kwargs:
            action = kwargs['action']
            if action == 'jump_to_next_change':
                GitGutterJumpToChanges(self.view, self.git_handler, self.settings).jump_to_next_change()
            elif action == 'jump_to_prev_change':
                GitGutterJumpToChanges(self.view, self.git_handler, self.settings).jump_to_prev_change()
            elif action == 'show_compare':
                sublime.message_dialog("GitGutter is comparing against: " + self.settings.get_compare_against(self.git_handler.git_dir))
            elif action == 'compare_against_commit':
                GitGutterCompareCommit(self.view, self.git_handler, self.settings).run()
            elif action == 'compare_against_branch':
                GitGutterCompareBranch(self.view, self.git_handler, self.settings).run()
            elif action == 'compare_against_tag':
                GitGutterCompareTag(self.view, self.git_handler, self.settings).run()
            elif action == 'compare_against_head':
                GitGutterCompareHead(self.view, self.git_handler, self.settings).run()
            elif action == 'compare_against_origin':
                GitGutterCompareOrigin(self.view, self.git_handler, self.settings).run()
        else:
            self.show_diff_handler.run()
Example #6
0
class GitGutterCommand(sublime_plugin.TextCommand):
    def __init__(self, *args, **kwargs):
        """Initialize GitGutterCommand object."""
        sublime_plugin.TextCommand.__init__(self, *args, **kwargs)
        self.git_handler = GitGutterHandler(self.view)
        self.show_diff_handler = GitGutterShowDiff(self.git_handler)
        # Last enabled state for change detection
        self._enabled = False

    def is_enabled(self, **kwargs):
        """Determine if `git_gutter` command is _enabled to execute."""
        view = self.view
        valid = True

        # Keep idle, if git binary is not set
        if not settings.git_binary_path:
            valid = False
        # Don't handle unattached views
        elif not view.window():
            valid = False
        # Don't handle scratch or readonly views
        elif view.is_scratch() or view.is_read_only():
            valid = False
        # Don't handle widgets
        elif view.settings().get('is_widget'):
            valid = False
        # Don't handle SublimeREPL views
        elif view.settings().get("repl"):
            valid = False
        # Don't handle binary files
        elif view.encoding() == 'Hexadecimal':
            valid = False
        else:
            # Validate work tree on certain events only
            validate = any(event in ('load', 'activated', 'post-save')
                           for event in kwargs.get('event_type', []))
            # Don't handle files outside a repository
            if not self.git_handler.work_tree(validate):
                valid = False

        # Handle changed state
        if valid != self._enabled:
            # File moved out of work-tree or repository gone
            if not valid:
                self.show_diff_handler.clear()
            # Save state for use in other modules
            view.settings().set('git_gutter_enabled', valid)
            # Save state for internal use
            self._enabled = valid
        return valid

    def run(self, edit, **kwargs):
        """API entry point to run the `git_gutter` command."""
        if 'action' in kwargs:
            self._handle_subcommand(**kwargs)
        else:
            self._handle_event(**kwargs)

    def _handle_event(self, **kwargs):
        events = kwargs.get('event_type', [])
        if any(event not in ('load', 'modified') for event in events):
            # On 'load' the git file is not yet valid anyway.
            # On 'modified' is sent when user is typing.
            # The git repository will most likely not change then.
            self.git_handler.invalidate_git_file()
        self.show_diff_handler.run()

    def _handle_subcommand(self, **kwargs):
        action = kwargs['action']
        if action == 'jump_to_next_change':
            GitGutterJumpToChanges(self.git_handler).jump_to_next_change()
        elif action == 'jump_to_prev_change':
            GitGutterJumpToChanges(self.git_handler).jump_to_prev_change()
        elif action == 'compare_against_commit':
            GitGutterCompareCommit(self.git_handler).run()
        elif action == 'compare_against_file_commit':
            GitGutterCompareFileCommit(self.git_handler).run()
        elif action == 'compare_against_branch':
            GitGutterCompareBranch(self.git_handler).run()
        elif action == 'compare_against_tag':
            GitGutterCompareTag(self.git_handler).run()
        elif action == 'compare_against_head':
            GitGutterCompareHead(self.git_handler).run()
        elif action == 'compare_against_origin':
            GitGutterCompareOrigin(self.git_handler).run()
        elif action == 'show_compare':
            GitGutterShowCompare(self.git_handler).run()
        elif action == 'show_diff_popup':
            point = kwargs['point']
            highlight_diff = kwargs['highlight_diff']
            flags = kwargs['flags']
            show_diff_popup(point,
                            self.git_handler,
                            highlight_diff=highlight_diff,
                            flags=flags)
        else:
            assert False, 'Unhandled sub command "%s"' % action
Example #7
0
 def add(view):
     key = ViewCollection.get_key(view)
     from git_gutter_handler import GitGutterHandler
     ViewCollection.views[key] = GitGutterHandler(view)
     ViewCollection.views[key].reset()
Example #8
0
 def __init__(self, *args, **kwargs):
     TextCommand.__init__(self, *args, **kwargs)
     self.git_handler = GitGutterHandler(self.view)
     self.show_diff_handler = GitGutterShowDiff(self.view, self.git_handler)
Example #9
0
class GitGutterCommand(TextCommand):
    def __init__(self, *args, **kwargs):
        TextCommand.__init__(self, *args, **kwargs)
        self.git_handler = GitGutterHandler(self.view)
        self.show_diff_handler = GitGutterShowDiff(self.view, self.git_handler)

    def is_enabled(self, **kwargs):
        """Determine if `git_gutter` command is _enabled to execute."""
        view = self.view
        valid = True
        # Keep idle, if git binary is not set
        if not settings.git_binary_path:
            valid = False
        # Don't handle unattached views
        elif not view.window():
            valid = False
        # Don't handle scratch or readonly views
        elif view.is_scratch() or view.is_read_only():
            valid = False
        # Don't handle widgets
        elif view.settings().get('is_widget'):
            valid = False
        # Don't handle SublimeREPL views
        elif view.settings().get("repl"):
            valid = False
        # Don't handle binary files
        elif view.encoding() in ('Hexadecimal'):
            valid = False
        # Don't handle views without valid file
        elif not self.git_handler.on_disk():
            valid = False
        # Don't handle files outside a repository
        elif not self.git_handler.git_dir:
            valid = False
        # Save state for use in other modules
        view.settings().set('git_gutter_enabled', valid)
        return valid

    def run(self, edit, **kwargs):
        """API entry point to run the `git_gutter` command."""
        if kwargs:
            self._handle_subcommand(**kwargs)
        else:
            self.show_diff_handler.run()

    def _handle_subcommand(self, **kwargs):
        view = self.view
        git_handler = self.git_handler
        action = kwargs['action']
        if action == 'jump_to_next_change':
            GitGutterJumpToChanges(view, git_handler).jump_to_next_change()
        elif action == 'jump_to_prev_change':
            GitGutterJumpToChanges(view, git_handler).jump_to_prev_change()
        elif action == 'compare_against_commit':
            GitGutterCompareCommit(view, git_handler).run()
        elif action == 'compare_against_branch':
            GitGutterCompareBranch(view, git_handler).run()
        elif action == 'compare_against_tag':
            GitGutterCompareTag(view, git_handler).run()
        elif action == 'compare_against_head':
            GitGutterCompareHead(view, git_handler).run()
        elif action == 'compare_against_origin':
            GitGutterCompareOrigin(view, git_handler).run()
        elif action == 'show_compare':
            GitGutterShowCompare(view, git_handler).run()
        elif action == 'show_diff_popup':
            point = kwargs['point']
            highlight_diff = kwargs['highlight_diff']
            flags = kwargs['flags']
            show_diff_popup(
                view, point, git_handler, highlight_diff=highlight_diff,
                flags=flags)
        else:
            assert False, 'Unhandled sub command "%s"' % action
Example #10
0
 def __init__(self, *args, **kwargs):
     sublime_plugin.TextCommand.__init__(self, *args, **kwargs)
     self.settings = GitGutterSettings()
     self.settings.load_settings()
     self.git_handler = GitGutterHandler(self.view, self.settings)
     self.show_diff_handler = GitGutterShowDiff(self.view, self.git_handler, self.settings)