From 30a94bdd17ad7ea84053ff514e5e010de7a52c60 Mon Sep 17 00:00:00 2001 From: johannesa Date: Wed, 22 Mar 2017 13:16:04 +0100 Subject: [PATCH 1/3] Added rendering for submodules With the global switch git_respect_submodules = True it is possible to have the history log of every added submodule rendered. This is useful if you are compiling a documentation from several different git repositories. --- docs/getting-started.rst | 9 ++++++++- sphinx_git/__init__.py | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/getting-started.rst b/docs/getting-started.rst index 06856f3..facb4ab 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -30,6 +30,13 @@ underscore):: extensions = ['sphinx_git'] +There is one global switch that changes the behavior of sphinx-git when +processing git submodules. Default behavior is that sphing-git renders +the git history of the sphinx directory. If you want sphinx-git to +render the history of the submodule instead you can add:: + + git_respect_submodules = True + Add A git Changelog To Your Project ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -58,4 +65,4 @@ was compiled with the ``git_commit_detail`` directive:: .. git_commit_detail:: :branch: - :commit: \ No newline at end of file + :commit: diff --git a/sphinx_git/__init__.py b/sphinx_git/__init__.py index acedcc0..bab2d1e 100644 --- a/sphinx_git/__init__.py +++ b/sphinx_git/__init__.py @@ -27,8 +27,11 @@ class GitDirectiveBase(Directive): def _find_repo(self): env = self.state.document.settings.env - repo = Repo(env.srcdir, search_parent_directories=True) - return repo + if env.config.git_respect_submodules: + srcdir = env.doc2path(env.docname) + else: + srcdir = env.srcdir + return Repo(srcdir, search_parent_directories=True) # pylint: disable=too-few-public-methods @@ -195,3 +198,4 @@ def _build_markup(self, commits): def setup(app): app.add_directive('git_changelog', GitChangelog) app.add_directive('git_commit_detail', GitCommitDetail) + app.add_config_value('git_respect_submodules', False, 'env') From 18e695a6eae49c6a98436f56dcb9b31dc3851a38 Mon Sep 17 00:00:00 2001 From: johannesa Date: Wed, 22 Mar 2017 13:45:50 +0100 Subject: [PATCH 2/3] Fixed indentation is not a multiple of four --- sphinx_git/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx_git/__init__.py b/sphinx_git/__init__.py index bab2d1e..68fc8a2 100644 --- a/sphinx_git/__init__.py +++ b/sphinx_git/__init__.py @@ -28,9 +28,9 @@ class GitDirectiveBase(Directive): def _find_repo(self): env = self.state.document.settings.env if env.config.git_respect_submodules: - srcdir = env.doc2path(env.docname) + srcdir = env.doc2path(env.docname) else: - srcdir = env.srcdir + srcdir = env.srcdir return Repo(srcdir, search_parent_directories=True) From a9f1e34a833833a8eb39bef34de60f6afd08a16a Mon Sep 17 00:00:00 2001 From: johannesa Date: Wed, 22 Mar 2017 15:13:56 +0100 Subject: [PATCH 3/3] Cleaned path output to match old behaviour Added os.path to strip out last component. There is no difference in the rendered document, but it matches old behaviour of just returning directory not document. --- sphinx_git/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx_git/__init__.py b/sphinx_git/__init__.py index 68fc8a2..2fcbb44 100644 --- a/sphinx_git/__init__.py +++ b/sphinx_git/__init__.py @@ -21,14 +21,14 @@ from docutils.parsers.rst import directives from git import Repo from sphinx.util.compat import Directive - +from os import path # pylint: disable=too-few-public-methods, abstract-method class GitDirectiveBase(Directive): def _find_repo(self): env = self.state.document.settings.env if env.config.git_respect_submodules: - srcdir = env.doc2path(env.docname) + srcdir = path.dirname(env.doc2path(env.docname, base=True)) else: srcdir = env.srcdir return Repo(srcdir, search_parent_directories=True)