<s> from command import Command , AggregatedCommand , CommandException <EOL> from utils . git_utils import get_repo , check_repo_is_clean <EOL> from git import GitCommandError <EOL> import feature <EOL> def _pop ( ) : <EOL> repo = get_repo ( ) <EOL> check_repo_is_clean ( repo ) <EOL> if repo . git . stash ( '<STR_LIT:list>' ) == '<STR_LIT>' : <EOL> raise CommandException ( '<STR_LIT>' ) <EOL> try : <EOL> repo . git . stash ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> except GitCommandError as e : <EOL> if '<STR_LIT>' in e . stderr : <EOL> try : <EOL> repo . git . stash ( '<STR_LIT>' ) <EOL> except GitCommandError : <EOL> raise CommandException ( '<STR_LIT>' ) <EOL> else : <EOL> raise e <EOL> _pop_finish ( ) <EOL> def _pop_finish ( repo = None ) : <EOL> repo = get_repo ( repo ) <EOL> commit_message = repo . git . stash ( '<STR_LIT:list>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> commit_message = '<STR_LIT>' . join ( commit_message . split ( '<STR_LIT>' ) [ <NUM_LIT:2> : ] ) <EOL> repo . index . commit ( _unescape_new_lines ( commit_message ) ) <EOL> repo . git . stash ( '<STR_LIT>' ) <EOL> def _push ( ) : <EOL> repo = get_repo ( ) <EOL> check_repo_is_clean ( repo ) <EOL> feature_config = feature . configuration ( repo ) <EOL> base = '<STR_LIT>' % ( feature_config . working_remote , feature_config . target_branch ) <EOL> if repo . head . commit == repo . commit ( base ) : <EOL> raise CommandException ( '<STR_LIT>' % base ) <EOL> commit_message = repo . head . commit . message <EOL> repo . git . reset ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> repo . git . stash ( '<STR_LIT>' , _escape_new_lines ( commit_message ) ) <EOL> def _list ( ) : <EOL> repo = get_repo ( ) <EOL> return repo . git . stash ( '<STR_LIT:list>' ) <EOL> def _escape_new_lines ( commit_message ) : <EOL> """<STR_LIT>""" <EOL> return commit_message . replace ( '<STR_LIT:\n>' , '<STR_LIT>' ) <EOL> def _unescape_new_lines ( commit_message ) : <EOL> """<STR_LIT>""" <EOL> return commit_message . replace ( '<STR_LIT>' , '<STR_LIT:\n>' ) <EOL> command = AggregatedCommand ( '<STR_LIT>' , '<STR_LIT>' , [ <EOL> Command ( '<STR_LIT>' , '<STR_LIT>' , _pop ) , <EOL> Command ( '<STR_LIT>' , "<STR_LIT>" , _pop_finish ) , <EOL> Command ( '<STR_LIT>' , '<STR_LIT>' , _push ) , <EOL> Command ( '<STR_LIT:list>' , '<STR_LIT>' , _list ) <EOL> ] ) </s>
