Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkout: close views with deleted files #388

Open
wants to merge 2 commits into
base: python3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions repo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

import sublime
from .git import GitWindowCommand, git_root_exist
from .git import GitWindowCommand, git_root_exist, git_root


class GitInit(object):
Expand Down Expand Up @@ -32,6 +32,7 @@ class GitBranchCommand(GitWindowCommand):
extra_flags = []

def run(self):
self.close_removed = sublime.load_settings("Git.sublime-settings").get("close_removed_on_checkout")
self.run_command(['git', 'branch', '--no-color'] + self.extra_flags, self.branch_done)

def branch_done(self, result):
Expand All @@ -46,9 +47,34 @@ def panel_done(self, picked):
if picked_branch.startswith("*"):
return
picked_branch = picked_branch.strip()
self.run_command(['git'] + self.command_to_run_after_branch + [picked_branch], self.update_status)
self.delfiles = []
if self.close_removed:
self.run_command(['git', 'diff', '--name-only', '--diff-filter=D'] + ['..'+picked_branch], self.manage_diffs, branch=picked_branch)
else:
self.do_checkout(picked_branch)

def do_checkout(self, branch):
self.run_command(['git'] + self.command_to_run_after_branch + [branch], self.update_status)

def manage_diffs(self, result, branch):
if result:
self.delfiles = result.strip().split('\n')
if len(self.delfiles) > 0:
working_dir = self.get_working_dir()
root = git_root(working_dir)
views = [v for v in self.window.views() if not v.is_dirty() and v.file_name()]
for f in self.delfiles:
fullf = os.path.join(root, f)
for v in views:
if v.file_name() == fullf:
v.close()
self.do_checkout(branch)

def update_status(self, result):
if result.startswith("error: "):
sublime.error_message(result[7:])
# reopen closed views if failed?
return
global branch
branch = ""
for view in self.window.views():
Expand Down Expand Up @@ -103,7 +129,7 @@ def panel_done(self, picked):
return
picked_tag = self.results[picked]
picked_tag = picked_tag.strip()
if sublime.ok_cancel_dialog("Delete \"%s\" Tag?" % picked_tag, "Delete"):
if sublime.ok_cancel_dialog("Delete \"%s\" Tag?" % picked_tag, "Delete"):
self.run_command(['git', 'tag', '-d', picked_tag])


Expand Down