<s> '''<STR_LIT>''' <EOL> from sh import git <EOL> from markwiki . renderer import render_markdown_txt <EOL> class GitIntegration ( object ) : <EOL> GIT_MSG = '<STR_LIT>' <EOL> def __init__ ( self , wiki_path ) : <EOL> self . path = wiki_path <EOL> self . git = git . bake ( _cwd = self . path ) <EOL> self . git . init ( ) <EOL> self . _set_config ( ) <EOL> self . _bootstrap ( ) <EOL> def _bootstrap ( self ) : <EOL> self . _add_untracked ( ) <EOL> self . _add_local_change ( ) <EOL> def update_file ( self , path ) : <EOL> '''<STR_LIT>''' <EOL> self . _commit_file ( path ) <EOL> def _set_config ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . git . config ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:input>' ) <EOL> self . git . config ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . git . config ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def _add_untracked ( self ) : <EOL> '''<STR_LIT>''' <EOL> for f in self . git ( '<STR_LIT>' , '<STR_LIT>' ) . split ( '<STR_LIT:\n>' ) : <EOL> if f : <EOL> self . _commit_file ( f ) <EOL> def _add_local_change ( self ) : <EOL> '''<STR_LIT>''' <EOL> for f in self . git ( '<STR_LIT>' , '<STR_LIT>' ) . split ( '<STR_LIT:\n>' ) : <EOL> if f : <EOL> self . _commit_file ( f ) <EOL> def _commit_file ( self , path ) : <EOL> '''<STR_LIT>''' <EOL> self . git . add ( path ) <EOL> msg = self . GIT_MSG % ( path ) <EOL> self . git . commit ( '<STR_LIT>' , msg ) <EOL> def get_changes ( self , path ) : <EOL> '''<STR_LIT>''' <EOL> changes = [ ] <EOL> commits = self . git ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , path ) <EOL> for commit in list ( commits ) [ <NUM_LIT:1> : ] : <EOL> commit = commit . strip ( '<STR_LIT>' ) <EOL> change = { } <EOL> change [ '<STR_LIT>' ] = commit . split ( '<STR_LIT:U+002C>' ) [ <NUM_LIT:0> ] <EOL> change [ '<STR_LIT:date>' ] = commit . split ( '<STR_LIT:U+002C>' ) [ <NUM_LIT:1> ] <EOL> changes . append ( change ) <EOL> return changes <EOL> def view_history ( self , path , commit ) : <EOL> '''<STR_LIT>''' <EOL> content = self . git ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' % ( commit , path ) ) <EOL> return render_markdown_txt ( content ) <EOL> def revert_file ( self , path , commit ) : <EOL> '''<STR_LIT>''' <EOL> self . git . checkout ( commit , path ) <EOL> self . _commit_file ( path ) </s>
