diff --git a/pubs/plugs/git/git.py b/pubs/plugs/git/git.py index 5be9221..3bff3d6 100644 --- a/pubs/plugs/git/git.py +++ b/pubs/plugs/git/git.py @@ -16,11 +16,13 @@ GITIGNORE = """# files or directories for the git plugin to ignore class GitPlugin(PapersPlugin): - """The git plugin creates a git repository in the pubs directory and commit the changes - to the pubs repository everytime a paper is modified. + """Make the pubs repository also a git repository. - It also add the `pubs git` subcommand, so git commands can be executed in the git repository - from the command line. + The git plugin creates a git repository in the pubs directory + and commit the changes to the pubs repository. + + It also add the `pubs git` subcommand, so git commands can be executed + in the git repository from the command line. """ name = 'git' @@ -28,10 +30,10 @@ class GitPlugin(PapersPlugin): def __init__(self, conf, ui): self.ui = ui - self.pubsdir = os.path.expanduser(conf['main']['pubsdir']) - self.manual = conf['plugins'].get('git', {}).get('manual', False) + self.pubsdir = os.path.expanduser(conf['main']['pubsdir']) + self.manual = conf['plugins'].get('git', {}).get('manual', False) self.force_color = conf['plugins'].get('git', {}).get('force_color', True) - self.quiet = conf['plugins'].get('git', {}).get('quiet', True) + self.quiet = conf['plugins'].get('git', {}).get('quiet', True) self.list_of_changes = [] self._gitinit() @@ -72,17 +74,18 @@ class GitPlugin(PapersPlugin): """ colorize = ' -c color.ui=always' if self.force_color else '' git_cmd = 'git -C {}{} {}'.format(self.pubsdir, colorize, cmd) - #print(git_cmd) p = Popen(git_cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT, shell=True) output, err = p.communicate(input_stdin) p.wait() if p.returncode != 0: - raise RuntimeError('The git plugin encountered an error when running the git command:\n' + - '{}\n\nReturned output:\n{}\n'.format(git_cmd, output.decode('utf-8')) + - 'If needed, you may fix the state of the {} git repository '.format(self.pubsdir) + - 'manually.\nIf relevant, you may submit a bug report at ' + - 'https://github.com/pubs/pubs/issues') + raise RuntimeError(( + 'The git plugin encountered an error when running the git command:\n' + '{}\n\n' + 'Returned output:\n{}\n' + 'If needed, you may fix the state of the {} git repository manually.\n' + 'If relevant, you may submit a bug report at https://github.com/pubs/pubs/issues' + ).format(git_cmd, output.decode('utf-8'), self.pubsdir)) elif command: self.ui.message(output.decode('utf-8'), end='') elif not self.quiet: @@ -97,10 +100,11 @@ def paper_change_event(event): git = GitPlugin.get_instance() if not git.manual: event_desc = event.description - for a, b in [('\\','\\\\'), ('"','\\"'), ('$','\\$'), ('`','\\`')]: + for a, b in [('\\', '\\\\'), ('"', '\\"'), ('$', '\\$'), ('`', '\\`')]: event_desc = event_desc.replace(a, b) git.list_of_changes.append(event_desc) + @PostCommandEvent.listen() def git_commit(event): if GitPlugin.is_loaded(): diff --git a/tests/test_git.py b/tests/test_git.py index 9eb60f8..192c042 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -31,7 +31,7 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase): self.execute_cmds([('pubs rename Page99a ABC',)]) hash_c = git_hash(self.default_pubs_dir) - self.execute_cmds([('pubs remove ABC', ['y']),]) + self.execute_cmds([('pubs remove ABC', ['y'])]) hash_d = git_hash(self.default_pubs_dir) self.execute_cmds([('pubs doc add testrepo/doc/Page99.pdf Page99',)]) @@ -101,6 +101,5 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase): self.assertNotEqual(hash_l, hash_m) - if __name__ == '__main__': unittest.main()