Esempio n. 1
0
    def run(self, edit, commitish):
        # type: (sublime.Edit, str) -> None
        if not self.commit_is_ancestor_of_head(commitish):
            flash(self.view,
                  "Selected commit is not part of the current branch.")
            return

        def program():
            self.rebase('--interactive',
                        "--autostash",
                        "--autosquash",
                        "{}".format(commitish),
                        custom_environ={"GIT_SEQUENCE_EDITOR": ":"})

        run_on_new_thread(program)
Esempio n. 2
0
def extract_symbol_from_graph(self, done):
    # type: (GsCommand, Kont) -> None
    view = get_view_for_command(self)
    if not view:
        return
    sel = log_graph.get_simple_selection(view)
    if sel is None:
        flash(view, "Only single cursors are supported.")
        return

    line = log_graph.line_from_pt(view, sel.b)
    info = log_graph.describe_graph_line(line.text, remotes=[])
    if info is None:
        flash(view, "Not on a line with a commit.")
        return

    symbol = commitish_from_info(info)
    done(symbol)
Esempio n. 3
0
    def run(self, edit, commit_hash):
        # type: (sublime.Edit, str) -> None
        action = self.action  # type: ignore[misc]
        if action is None:
            raise NotImplementedError("action must be defined")

        if not self.commit_is_ancestor_of_head(commit_hash):
            flash(self.view, "Selected commit is not part of the current branch.")
            return

        def program():
            with await_todo_list(action):  # type: ignore[arg-type]  # mypy bug
                self.rebase(
                    '--interactive',
                    "--autostash",
                    "--autosquash" if self.autosquash else "--no-autosquash",
                    "{}^".format(commit_hash),
                )

        run_on_new_thread(program)
Esempio n. 4
0
    def run(self):
        # type: () -> None
        view = self.window.active_view()
        if not view:
            return

        sel = log_graph.get_simple_selection(view)
        if sel is None:
            flash(view, "Only single cursors are supported.")
            return

        line = log_graph.line_from_pt(view, sel.b)
        info = log_graph.describe_graph_line(line.text, remotes=[])
        if info is None:
            flash(view, "Not on a line with a commit.")
            return

        commit_hash = info["commit"]
        commitish = commitish_from_info(info)
        parent_commitish = "{}^".format(commitish)
        commit_message = commit_message_from_line(view, line)
        on_head = "HEAD" in info
        actions = []  # type: List[Tuple[str, Callable[[], None]]]

        if commit_message and is_fixup_or_squash_message(commit_message):
            base_commit = find_base_commit_for_fixup(view, line, commit_message)
            if base_commit:
                fixup_commit = Commit(commit_hash, commit_message)
                actions += [
                    (
                        "Apply fix to '{}'".format(base_commit)
                        if is_fixup(fixup_commit)
                        else "Squash with '{}'".format(base_commit),
                        partial(self.apply_fixup, view, base_commit, [fixup_commit])
                    )
                ]

        actions += [
            (
                "Re[W]ord commit message",
                partial(self.reword, view, commit_hash)
            ),
            (
                "[E]dit commit",
                partial(self.edit, view, commit_hash)
            ),
            (
                "Drop commit",
                partial(self.drop, view, commit_hash)
            ),
            SEPARATOR,
        ]

        # `HEAD^..HEAD` only selects one commit which is not enough
        # for autosquashing.
        if not on_head:
            head_info = log_graph.describe_head(view, [])
            good_head_name = (
                "HEAD"
                if not head_info or head_info["HEAD"] == head_info["commit"]
                else head_info["HEAD"]
            )
            actions += [
                (
                    "Apply fixes and squashes {}..{}".format(parent_commitish, good_head_name),
                    partial(self.autosquash, view, parent_commitish),
                ),
            ]

        actions += [
            (
                "[R]ebase from {} on interactive".format(parent_commitish),
                partial(self.rebase_interactive, view, parent_commitish)
            ),
            (
                "Rebase {} --onto <branch>".format(parent_commitish),
                partial(self.rebase_onto, view, parent_commitish)
            ),
            (
                "Rebase on <branch>",
                partial(self.rebase_on, view)
            ),
        ]

        def on_action_selection(index):
            if index == -1:
                return

            self.selected_index = index
            description, action = actions[index]
            action()

        self.window.show_quick_panel(
            [a[0] for a in actions],
            on_action_selection,
            flags=sublime.MONOSPACE_FONT,
            selected_index=self.selected_index,
        )
Esempio n. 5
0
 def run(self, edit):
     view = self.view
     if not jump_to_hunk(view, False):
         flash(view, "No hunk to jump to")