@@ -37,7 +37,8 @@ pip install git+git://github.com/ValentinFrancois/python-gitlab-submodule#egg=py
3737```
3838
3939## Usage example
40- - Iterate the submodules of the Gitlab [ Inkscape] ( https://gitlab.com/inkscape/inkscape ) project
40+ ### 1)
41+ - Iterate over the submodules of the Gitlab [ Inkscape] ( https://gitlab.com/inkscape/inkscape ) project
4142- For each submodule, print:
4243 - its path in the project
4344 - its own Gitlab project SSH URL
@@ -66,14 +67,41 @@ Output:
6667- share/themes (git@gitlab.com:inkscape/themes.git) -> 2fc6ece138323f905c9b475c3bcdef0d007eb233
6768```
6869
70+ ### 2)
71+ - Iterate over the submodules of the Gitlab [ Inkscape] ( https://gitlab.com/inkscape/inkscape ) project
72+ - For each submodule, print:
73+ - its path in the project
74+ - if its commit is up-to-date with the HEAD of the main branch of the
75+ subproject
76+ ``` diff
77+ for subproject in subprojects:
78+ print('- {} ({}) -> {}'.format(
79+ - subproject.submodule.path,
80+ - subproject.project.url,
81+ - subproject.commit.id))
82+ + head_subproject_commit = subproject.project.commits.list(
83+ + ref=subproject.project.default_branch)[0]
84+ + up_to_date = subproject.commit.id == head_subproject_commit.id
85+ + print('- {}: {}'.format(
86+ + subproject.submodule.path,
87+ + 'ok' if up_to_date else '/!\\ must update'))
88+
89+ ```
90+ Output:
91+ ```
92+ - share/extensions: /!\ must update
93+ - src/3rdparty/2geom: ok
94+ - share/themes: ok
95+ ```
96+
6997## Available functions and objects
7098
7199### ` iterate_subprojects(...) `
72100What you'll probably use most of the time.<br />
73- - Yields ` Subproject ` objects that describe the submodules.
101+ - Yields [ ` Subproject ` ] ( #class-subproject ) objects that describe the submodules.
74102- Ignores submodules that are not hosted on Gitlab. If you want to list all
75103 modules present in the ` .gitmodules ` file but without mapping them to
76- ` gitlab.v4.objects.Project ` objects, use list_submodules(...) instead.
104+ ` gitlab.v4.objects.Project ` objects, use [ ` list_submodules(...) ` ] ( #list_submodules ) instead.
77105``` python
78106iterate_subprojects(
79107 project: Project,
@@ -104,16 +132,16 @@ Parameters:
104132Returns: Generator of ` Subproject ` objects
105133
106134### ` list_subprojects(...) `
107- Same parameters as ` iterate_subprojects(...) ` but returns a ` list ` or
108- ` Subproject ` objects.
135+ Same parameters as [ ` iterate_subprojects(...) ` ] ( #iterate_subprojects ) but
136+ returns a ` list ` of [ ` Subproject ` ] ( #class-subproject ) objects.
109137
110138### class ` Subproject `
111139Basic objects that contain the info about a Gitlab subproject.
112140
113141Attributes:
114142- ` project: gitlab.v4.objects.Project ` : the Gitlab project that the submodule links to
115- - ` submodule ` : ` Submodule ` : a basic object that contains the info found in
116- the ` .gitmodules ` file (name, path, url).
143+ - ` submodule: ` [ ` Submodule ` ] ( #class-submodule ) : a basic object that contains
144+ the info found in the ` .gitmodules ` file (name, path, url).
117145- ` commit: gitlab.v4.objects.ProjectCommit ` : the commit that the submodule points to
118146- ` commit_is_exact: bool ` : ` True ` most of the time, ` False ` only if the commit
119147 had to be guessed via the ` get_latest_commit_possible_if_not_found ` option
@@ -159,7 +187,7 @@ Example `str()` output:
159187```
160188
161189### ` submodule_to_subproject(...) `
162- Converts a ` Submodule ` object to a ` Subproject ` object, assuming it's
190+ Converts a ` Submodule ` object to a [ ` Subproject ` ] ( #class-subproject ) object, assuming it's
163191hosted on Gitlab.
164192
165193``` python
@@ -170,4 +198,4 @@ submodule_to_subproject(
170198 get_latest_commit_possible_ref: Optional[str ] = None
171199) -> Subproject
172200```
173- Parameters: See ` iterate_subprojects(...) `
201+ Parameters: See [ ` iterate_subprojects(...) ` ] ( #iterate_subprojects )
0 commit comments