<s> import re <EOL> import sublime <EOL> from sublime_plugin import WindowCommand <EOL> from . . git_command import GitCommand <EOL> from ... common import util <EOL> NEW_BRANCH_PROMPT = "<STR_LIT>" <EOL> class GsCheckoutBranchCommand ( WindowCommand , GitCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self ) : <EOL> sublime . set_timeout_async ( self . run_async , <NUM_LIT:0> ) <EOL> def run_async ( self ) : <EOL> stdout = self . git ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> branch_entries = ( branch . strip ( ) for branch in stdout . split ( "<STR_LIT:\n>" ) if branch ) <EOL> self . local_inactive_branches = [ branch for branch in branch_entries if not branch [ <NUM_LIT:0> ] == "<STR_LIT:*>" ] <EOL> if not self . local_inactive_branches : <EOL> self . window . show_quick_panel ( [ "<STR_LIT>" ] , None ) <EOL> else : <EOL> self . window . show_quick_panel ( <EOL> self . local_inactive_branches , <EOL> self . on_selection , <EOL> flags = sublime . MONOSPACE_FONT <EOL> ) <EOL> def on_selection ( self , branch_name_index ) : <EOL> if branch_name_index == - <NUM_LIT:1> : <EOL> return <EOL> branch_name = self . local_inactive_branches [ branch_name_index ] <EOL> self . git ( "<STR_LIT>" , branch_name ) <EOL> sublime . status_message ( "<STR_LIT>" . format ( branch_name ) ) <EOL> util . view . refresh_gitsavvy ( self . window . active_view ( ) ) <EOL> class GsCheckoutNewBranchCommand ( WindowCommand , GitCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self ) : <EOL> sublime . set_timeout_async ( self . run_async ) <EOL> def run_async ( self , name = "<STR_LIT>" ) : <EOL> self . window . show_input_panel ( NEW_BRANCH_PROMPT , name , self . on_done , None , None ) <EOL> def on_done ( self , branch_name ) : <EOL> pattern = r"<STR_LIT>" <EOL> match = re . match ( pattern , branch_name ) <EOL> if not match : <EOL> sublime . error_message ( "<STR_LIT>" . format ( branch_name ) ) <EOL> sublime . set_timeout_async ( self . run_async ( branch_name ) ) <EOL> return None <EOL> self . git ( "<STR_LIT>" , "<STR_LIT>" , branch_name ) <EOL> sublime . status_message ( "<STR_LIT>" . format ( branch_name ) ) <EOL> util . view . refresh_gitsavvy ( self . window . active_view ( ) ) <EOL> class GsCheckoutRemoteBranchCommand ( WindowCommand , GitCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self ) : <EOL> sublime . set_timeout_async ( self . run_async ) <EOL> def run_async ( self ) : <EOL> self . remote_branches = self . list_remote_branches ( ) <EOL> self . window . show_quick_panel ( <EOL> self . remote_branches , <EOL> self . on_selection , <EOL> flags = sublime . MONOSPACE_FONT <EOL> ) <EOL> def on_selection ( self , remote_branch_index ) : <EOL> if remote_branch_index == - <NUM_LIT:1> : <EOL> return <EOL> remote_branch = self . remote_branches [ remote_branch_index ] <EOL> local_name = remote_branch . split ( "<STR_LIT:/>" , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> self . git ( "<STR_LIT>" , "<STR_LIT>" , local_name , "<STR_LIT>" , remote_branch ) <EOL> sublime . status_message ( "<STR_LIT>" . format ( remote_branch , local_name ) ) <EOL> util . view . refresh_gitsavvy ( self . window . active_view ( ) ) <EOL> class GsCheckoutCurrentFileCommand ( WindowCommand , GitCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self ) : <EOL> if self . file_path : <EOL> self . checkout_file ( self . file_path ) <EOL> sublime . status_message ( "<STR_LIT>" . format ( self . file_path ) ) </s>
