Skip to content

Commit

Permalink
Merge 76bacdb into 35491ce
Browse files Browse the repository at this point in the history
  • Loading branch information
randy3k committed Jul 11, 2018
2 parents 35491ce + 76bacdb commit 0f31603
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
5 changes: 5 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@
"command": "gs_push",
"args": { "force": true }
},
{
"caption": "git: push (force-with-lease)",
"command": "gs_push",
"args": { "force_with_lease": true }
},
{
"caption": "git: push all tags",
"command": "gs_tags_push",
Expand Down
36 changes: 25 additions & 11 deletions core/commands/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,32 @@
PUSH_TO_BRANCH_NAME_PROMPT = "Enter remote branch name:"
SET_UPSTREAM_PROMPT = ("You have not set an upstream for the active branch. "
"Would you like to set one?")
CONFIRM_FORCE_PUSH = ("You are about to `git push --force`. Would you "
CONFIRM_FORCE_PUSH = ("You are about to `git push {}`. Would you "
"like to proceed?")


class PushBase(GitCommand):
set_upstream = False

def do_push(self, remote, branch, force=False, remote_branch=None):
def do_push(self, remote, branch, force=False, force_with_lease=False, remote_branch=None):
"""
Perform `git push remote branch`.
"""
if force and self.savvy_settings.get("confirm_force_push"):
if not sublime.ok_cancel_dialog(CONFIRM_FORCE_PUSH):
return
if self.savvy_settings.get("confirm_force_push"):
if force:
if not sublime.ok_cancel_dialog(CONFIRM_FORCE_PUSH.format("--force")):
return
elif force_with_lease:
if not sublime.ok_cancel_dialog(CONFIRM_FORCE_PUSH.format("--force--with-lease")):
return

self.window.status_message(START_PUSH_MESSAGE)
self.push(
remote,
branch,
set_upstream=self.set_upstream,
force=force,
force_with_lease=force_with_lease,
remote_branch=remote_branch
)
self.window.status_message(END_PUSH_MESSAGE)
Expand All @@ -44,8 +49,9 @@ class GsPushCommand(WindowCommand, PushBase):
Push current branch.
"""

def run(self, local_branch_name=None, force=False):
def run(self, local_branch_name=None, force=False, force_with_lease=False):
self.force = force
self.force_with_lease = force_with_lease
self.local_branch_name = local_branch_name
sublime.set_timeout_async(self.run_async)

Expand All @@ -59,20 +65,26 @@ def run_async(self):
if upstream:
remote, remote_branch = upstream.split("/", 1)
self.do_push(
remote, self.local_branch_name, remote_branch=remote_branch, force=self.force)
remote,
self.local_branch_name,
remote_branch=remote_branch,
force=self.force,
force_with_lease=self.force_with_lease)
elif self.savvy_settings.get("prompt_for_tracking_branch"):
if sublime.ok_cancel_dialog(SET_UPSTREAM_PROMPT):
self.window.run_command("gs_push_to_branch_name", {
"set_upstream": True,
"force": self.force
"force": self.force,
"force_with_lease": self.force_with_lease
})
else:
# if `prompt_for_tracking_branch` is false, ask for a remote and perform
# push current branch to a remote branch with the same name
self.window.run_command("gs_push_to_branch_name", {
"branch_name": self.local_branch_name,
"set_upstream": False,
"force": self.force
"force": self.force,
"force_with_lease": self.force_with_lease
})


Expand Down Expand Up @@ -104,10 +116,11 @@ class GsPushToBranchNameCommand(WindowCommand, PushBase):
Prompt for remote and remote branch name, then push.
"""

def run(self, branch_name=None, set_upstream=False, force=False):
def run(self, branch_name=None, set_upstream=False, force=False, force_with_lease=False):
self.branch_name = branch_name
self.set_upstream = set_upstream
self.force = force
self.force_with_lease = force_with_lease
sublime.set_timeout_async(self.run_async)

def run_async(self):
Expand Down Expand Up @@ -143,5 +156,6 @@ def on_entered_branch_name(self, branch):
sublime.set_timeout_async(lambda: self.do_push(
self.selected_remote,
self.get_current_branch_name(),
self.force,
force=self.force,
force_with_lease=self.force_with_lease,
remote_branch=branch))
10 changes: 9 additions & 1 deletion core/git_mixins/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,22 @@ def pull(self, remote=None, remote_branch=None, rebase=False):
remote_branch if remote and remote_branch else None
)

def push(self, remote=None, branch=None, force=False, remote_branch=None, set_upstream=False):
def push(
self,
remote=None,
branch=None,
force=False,
force_with_lease=False,
remote_branch=None,
set_upstream=False):
"""
Push to the specified remote and branch if provided, otherwise
perform default `git push`.
"""
return self.git(
"push",
"--force" if force else None,
"--force-with-lease" if force_with_lease else None,
"--set-upstream" if set_upstream else None,
remote,
branch if not remote_branch else "{}:{}".format(branch, remote_branch)
Expand Down

0 comments on commit 0f31603

Please sign in to comment.