Skip to content

Commit

Permalink
Enhancement: consolidate checkout related code
Browse files Browse the repository at this point in the history
  • Loading branch information
randy3k committed Aug 18, 2017
1 parent 7c9dbd7 commit eea7d31
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 36 deletions.
8 changes: 0 additions & 8 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -937,14 +937,6 @@
{ "key": "setting.git_savvy.branch_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["o"],
"command": "gs_branches_checkout_as_local",
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.branch_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["b"],
"command": "gs_branches_create_new",
Expand Down
41 changes: 13 additions & 28 deletions core/interfaces/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ class BranchInterface(ui.Interface, GitCommand):
#############
[c] checkout [p] push selected to remote
[b] create new branch (from HEAD) [P] push all branches to remote
[b] create from selected branch [P] push all branches to remote
[d] delete [h] fetch remote branches
[D] delete (force) [m] merge selected into active branch
[R] rename (local) [M] fetch and merge into active branch
[t] configure tracking
[o] checkout remote as local
[f] diff against active [l] show branch log
[H] diff history against active [g] show branch log graph
Expand Down Expand Up @@ -232,18 +231,16 @@ def run_async(self):
return

if remote_name:
self.checkout_ref("{}/{}".format(remote_name, branch_name))
ref = "{}/{}".format(remote_name, branch_name)
else:
self.checkout_ref(branch_name)
ref = branch_name
self.view.window().run_command("gs_checkout_branch", {"branch": ref})

util.view.refresh_gitsavvy(self.view, refresh_sidebar=True)


class GsBranchesCheckoutAsLocalCommand(TextCommand, GitCommand):
class GsBranchesCreateNewCommand(TextCommand, GitCommand):

"""
Create a new local branch that shares HEAD with the selected remote branch,
then check it out.
Create a new branch from selected branch and checkout.
"""

def run(self, edit):
Expand All @@ -252,27 +249,15 @@ def run(self, edit):
def run_async(self):
interface = ui.get_interface(self.view.id())
remote_name, branch_name = interface.get_selected_branch()
if not branch_name or not remote_name:
if not branch_name:
return

self.git(
"checkout",
"-b",
branch_name,
"--track",
"{}/{}".format(remote_name, branch_name)
)
util.view.refresh_gitsavvy(self.view, refresh_sidebar=True)


class GsBranchesCreateNewCommand(TextCommand, GitCommand):

"""
Create a new branch from HEAD and checkout.
"""

def run(self, edit):
self.view.window().run_command("gs_checkout_new_branch")
if remote_name:
ref = "{}/{}".format(remote_name, branch_name)
self.view.window().run_command("gs_checkout_remote_branch", {"remote_branch": ref})
else:
ref = branch_name
self.view.window().run_command("gs_checkout_new_branch", {"base_branch": ref})


class GsBranchesDeleteCommand(TextCommand, GitCommand):
Expand Down

0 comments on commit eea7d31

Please sign in to comment.