Skip to content

Commit

Permalink
Merge pull request #1835 from timbrel/fixup-pull
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste authored Dec 8, 2023
2 parents 4f4cd5b + 89c40ee commit c999d63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
4 changes: 2 additions & 2 deletions core/base_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class GsWindowCommand(

# COMMON INPUT HANDLERS

KnownKeys = Union[Literal["last_local_branch_for_rebase"]]
KnownKeys = Literal["last_local_branch_for_rebase", "last_branch_used_to_pull_from"]


def ask_for_branch(memorize_key=None, **kw):
Expand All @@ -179,7 +179,7 @@ def handler(self, args, done):
# type: (GsCommand, Args, Kont) -> None
def on_done(branch):
if memorize_key:
store.update_state(self.repo_path, {memorize_key: branch})
store.update_state(self.repo_path, {memorize_key: branch}) # type: ignore[misc]
done(branch)

selected_branch = (
Expand Down
26 changes: 8 additions & 18 deletions core/commands/pull.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from ...common import util
from ..ui_mixins.quick_panel import show_branch_panel
from GitSavvy.core.base_commands import Args, GsCommand, GsWindowCommand, Kont
from GitSavvy.core.base_commands import GsWindowCommand, ask_for_branch
from GitSavvy.core.fns import flatten, unique
from GitSavvy.core.runtime import on_worker
from GitSavvy.core import store
Expand Down Expand Up @@ -43,35 +42,26 @@ def run(self, rebase=None):
self.window.run_command("gs_pull_from_branch", {"rebase": rebase})


def ask_for_branch(self, args, done):
# type: (GsCommand, Args, Kont) -> None
last_used_branch = store.current_state(self.repo_path).get("last_branch_used_to_pull_from")

def _done(branch):
store.update_state(self.repo_path, {"last_branch_used_to_pull_from": branch})
done(branch)

show_branch_panel(
_done,
ask_remote_first=False,
ignore_current_branch=True,
selected_branch=last_used_branch
)
ask_for_branch_ = ask_for_branch(
ask_remote_first=False,
ignore_current_branch=True,
memorize_key="last_branch_used_to_pull_from"
)


class gs_pull_from_branch(GsPullBase):
"""
Through a series of panels, allow the user to pull from a branch.
"""
defaults = {
"branch": ask_for_branch
"branch": ask_for_branch_
}

@on_worker
def run(self, branch, rebase=None):
# type: (str, bool) -> None
sources: Sequence[Callable[[], List[Branch]]] = (
# Typically, `ask_for_branch`s `show_branch_panel` has just called
# Typically, `ask_for_branch_`s `show_branch_panel` has just called
# `get_branches` so the cached value in the store should be fresh
# and good to go.
lambda: store.current_state(self.repo_path).get("branches", []),
Expand Down

0 comments on commit c999d63

Please sign in to comment.