blob: a2a080b8871c96958cd090a837cee2596d123ecd [file] [log] [blame]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08001= Gerrit Code Review - Superproject subscription to submodules updates
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -02002
Stefan Bellerc62f9fe2016-03-21 12:14:58 -07003[[automatic_update]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08004== Description
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -02005Gerrit supports a custom git superproject feature for tracking submodules.
6This feature is useful for automatic updates on superprojects whenever
Stefan Bellerc62f9fe2016-03-21 12:14:58 -07007a change is merged on tracked submodules.
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -02008
Stefan Bellerc62f9fe2016-03-21 12:14:58 -07009When a superproject is subscribed to a submodule, it is not
10required to push/merge commits to this superproject to update the
11gitlink to the submodule. Whenever a commit is merged in a submodule,
12its subscribed superproject is updated by Gerrit.
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020013
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070014Imagine a superproject called 'super' having a branch called 'dev'
15having subscribed to a submodule 'sub' on a branch 'dev-of-sub'. When a commit
16is merged in branch 'dev-of-sub' of 'sub' project, Gerrit automatically
17creates a new commit on branch 'dev' of 'super' updating the gitlink
18to point to the just merged commit.
19
20To take advantage of this feature, one should:
21
22. ensure superproject subscriptions are enabled on the server via
23 link:config-gerrit.html#submodule.enableSuperProjectSubscriptions[submodule.enableSuperProjectSubscriptions]
24. configure the submodule to allow having a superproject subscribed
25. ensure the .gitmodules file of the superproject includes
26.. a branch field
27.. a url that starts with the link:config-gerrit.html#gerrit.canonicalWebUrl[`gerrit.canonicalWebUrl`]
28
29When a commit in a project is merged, Gerrit checks for superprojects
Maxime Guerreirodb9c8ad2018-04-19 07:10:25 +000030that are subscribed to the project and automatically updates those
Eryk Szymanski2b93eb02016-11-15 17:56:28 -080031superprojects with a commit that updates the gitlink for the project.
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020032
Stefan Beller8cc252e2016-03-10 10:06:53 -080033This feature is enabled by default and can be disabled
34via link:config-gerrit.html#submodule.enableSuperProjectSubscriptions[submodule.enableSuperProjectSubscriptions]
35in the server configuration.
36
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070037== Git submodules overview
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020038
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070039Submodules are a Git feature that allows an external repository to be
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020040attached inside a repository at a specific path. The objective here
41is to provide a brief overview, further details can be found
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070042in the official Git submodule documentation.
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020043
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070044Imagine a repository called 'super' and another one called 'sub'.
45Also consider 'sub' available in a running Gerrit instance on "server".
46With this feature, one could attach 'sub' inside of 'super' repository
47at path 'sub' by executing the following command when being inside
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020048'super':
Michael Ochmannb99feab2016-07-06 14:10:22 +020049----
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070050git submodule add ssh://server/sub sub
Michael Ochmannb99feab2016-07-06 14:10:22 +020051----
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020052
53Still considering the above example, after its execution notice that
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070054inside the local repository 'super' the 'sub' folder is considered a
55gitlink to the external repository 'sub'. Also notice a file called
Peter Jönssonf6488f72013-05-02 20:42:29 +020056.gitmodules is created (it is a configuration file containing the
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070057subscription of 'sub'). To provide the SHA-1 each gitlink points to in
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020058the external repository, one should use the command:
Michael Ochmannb99feab2016-07-06 14:10:22 +020059----
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020060git submodule status
Michael Ochmannb99feab2016-07-06 14:10:22 +020061----
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020062
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070063In the example provided, if 'sub' is updated and 'super' is supposed
64to see the latest SHA-1 (considering here 'sub' has only the master
65branch), one should then commit the modified gitlink for 'sub' in
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020066the 'super' project. Actually it would not even need to be an
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070067external update, one could move to 'sub' folder (inside 'super'),
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020068modify its content, commit, then move back to 'super' and
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070069commit the modified gitlink for 'sub'.
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020070
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070071== Creating a new subscription
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020072
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070073=== Ensure the subscription is allowed
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -020074
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070075Gerrit has a complex access control system, where different repositories
76can be accessed by different groups of people. To ensure that the submodule
77related information is allowed to be exposed in the superproject,
78the submodule needs to be configured to enable the superproject subscription.
79In a submodule client, checkout the refs/meta/config branch and edit
80the subscribe capabilities in the 'project.config' file:
Michael Ochmannb99feab2016-07-06 14:10:22 +020081----
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070082 git fetch <remote> refs/meta/config:refs/meta/config
83 git checkout refs/meta/config
84 $EDITOR project.config
Michael Ochmannb99feab2016-07-06 14:10:22 +020085----
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070086and add the following lines:
Michael Ochmannb99feab2016-07-06 14:10:22 +020087----
Zhen Chenc6119c32016-05-18 15:46:56 -070088 [allowSuperproject "<superproject>"]
Stefan Bellerbb444172016-08-04 16:13:11 -070089 matching = <refspec>
Michael Ochmannb99feab2016-07-06 14:10:22 +020090----
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070091where the 'superproject' should be the exact project name of the superproject.
92The refspec defines which branches of the submodule are allowed to be
93subscribed to which branches of the superproject. See below for
94link:#acl_refspec[details]. Push the configuration for review and
95submit the change:
Michael Ochmannb99feab2016-07-06 14:10:22 +020096----
Stefan Bellerc62f9fe2016-03-21 12:14:58 -070097 git add project.config
98 git commit -m "Allow <superproject> to subscribe"
99 git push <remote> HEAD:refs/for/refs/meta/config
Michael Ochmannb99feab2016-07-06 14:10:22 +0200100----
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700101After the change is integrated a superproject subscription is possible.
102
Stefan Beller5a49ca02016-05-18 14:13:28 -0700103The configuration is inherited from parent projects, such that you can have
104a configuration in the "All-Projects" project like:
Michael Ochmannb99feab2016-07-06 14:10:22 +0200105----
Stefan Beller5a49ca02016-05-18 14:13:28 -0700106 [allowSuperproject "my-only-superproject"]
Stefan Bellerbb444172016-08-04 16:13:11 -0700107 matching = refs/heads/*:refs/heads/*
Michael Ochmannb99feab2016-07-06 14:10:22 +0200108----
Stefan Beller5a49ca02016-05-18 14:13:28 -0700109and then you don't have to worry about configuring the individual projects
110any more. Child projects cannot negate the parent's configuration.
111
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700112=== Defining the submodule branch
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200113
Peter Jönssonf6488f72013-05-02 20:42:29 +0200114Since Gerrit manages subscriptions in the branch scope, we could have
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200115a scenario having a project called 'super' having a branch 'integration'
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700116subscribed to a project called 'sub' in branch 'integration', and also
117having the same 'super' project but in branch 'dev' subscribed to the 'sub'
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200118project in a branch called 'local-dev'.
119
120After adding the git submodule to a super project, one should edit
121the .gitmodules file to add a branch field to each submodule
122section which is supposed to be subscribed.
123
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700124As the branch field is a Gerrit-specific field it will not be filled
Peter Jönssonf6488f72013-05-02 20:42:29 +0200125automatically by the git submodule command, so one needs to edit it
126manually. Its value should indicate the branch of a submodule project
127that when updated will trigger automatic update of its registered
128gitlink.
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200129
Peter Jönssonf6488f72013-05-02 20:42:29 +0200130The branch value could be "'.'" if the submodule project branch
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200131has the same name as the destination branch of the commit having
132gitlinks/.gitmodules file.
133
Peter Jönssonf6488f72013-05-02 20:42:29 +0200134If the intention is to make use of the Gerrit feature described
135here, one should always be sure to update the .gitmodules file after
136adding submodules to a super project.
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200137
Peter Jönssonf6488f72013-05-02 20:42:29 +0200138If a git submodule is added but the branch field is not added to the
139.gitmodules file, Gerrit will not create a subscription for the
140submodule and there will be no automatic updates to the superproject.
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200141
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700142Whenever a commit is merged to a project, its project config is checked
143to see if any potential superprojects are allowed to subscribe to it.
144If so, the superproject is checked if a valid subscription exists
145by checking the .gitmodules file for the a submodule which includes
146a `branch` field and a url pointing to this server.
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200147
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700148[[acl_refspec]]
149=== The RefSpec in the allowSuperproject section
Stefan Bellerbb444172016-08-04 16:13:11 -0700150There are two options for specifying which branches can be subscribed
151to. The most common is to set `allowSuperproject.<superproject>.matching`
152to a Git-style refspec, which has the same syntax as the refspecs used
153for pushing in Git. Regular expressions as found in the ACL configuration
154are not supported.
155
156The most restrictive refspec is allowing one specific branch of the
157submodule to be subscribed to one specific branch of the superproject:
Michael Ochmannb99feab2016-07-06 14:10:22 +0200158----
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700159 [allowSuperproject "<superproject>"]
Stefan Bellerbb444172016-08-04 16:13:11 -0700160 matching = refs/heads/<submodule-branch>:refs/heads/<superproject-branch>
Michael Ochmannb99feab2016-07-06 14:10:22 +0200161----
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200162
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700163If you want to allow for a 1:1 mapping, i.e. 'master' maps to 'master',
164'stable' maps to 'stable', but not allowing 'master' to be subscribed to
165'stable':
Michael Ochmannb99feab2016-07-06 14:10:22 +0200166----
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700167 [allowSuperproject "<superproject>"]
Stefan Bellerbb444172016-08-04 16:13:11 -0700168 matching = refs/heads/*:refs/heads/*
Michael Ochmannb99feab2016-07-06 14:10:22 +0200169----
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200170
Stefan Bellerbb444172016-08-04 16:13:11 -0700171To allow all refs matching one pattern to subscribe to all refs
172matching another pattern, set `allowSuperproject.<superproject>.all`
173to the patterns concatenated with a colon. For example, to make a
174single branch available for subscription from all branches of the
175superproject:
Michael Ochmannb99feab2016-07-06 14:10:22 +0200176----
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700177 [allowSuperproject "<superproject>"]
Stefan Bellerbb444172016-08-04 16:13:11 -0700178 all = refs/heads/<submodule-branch>:refs/heads/*
179----
180
181To make all branches available for subscription from all branches of
182the superproject:
183----
184 [allowSuperproject "<superproject>"]
185 all = refs/heads/*:refs/heads/*
Michael Ochmannb99feab2016-07-06 14:10:22 +0200186----
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200187
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800188=== Subscription Limitations
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200189
Peter Jönssonf6488f72013-05-02 20:42:29 +0200190Gerrit will only automatically update superprojects where the
191submodules are hosted on the same Gerrit instance as the
Björn Pedersen11afe4d2016-09-01 11:20:35 +0200192superproject. Gerrit determines this by checking that the URL of the
193submodule specified in the .gitmodules file starts with
194link:config-gerrit.html#gerrit.canonicalWebUrl[`gerrit.canonicalWebUrl`].
195The protocol part is ignored in this check.
Peter Jönssonf6488f72013-05-02 20:42:29 +0200196
197It is currently not possible to use the submodule subscription feature
Björn Pedersen11afe4d2016-09-01 11:20:35 +0200198with a canonical web URL that differs from the first part of
199the submodule URL. Instead relative submodules should be used.
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200200
David Pursehouse2cecb462016-09-01 10:39:27 +0900201The Gerrit instance administrator should ensure that the canonical web
202URL value is specified in its configuration file. Users should ensure
203that they use the correct hostname of the running Gerrit instance when
204adding submodule subscriptions.
Peter Jönssonf6488f72013-05-02 20:42:29 +0200205
David Pursehousee23c9312016-09-01 10:40:03 +0900206When converting an existing submodule to use subscription by adding
David Pursehousedfb44b7c2016-09-02 09:58:13 +0900207a `branch` field into the .gitmodules file, Gerrit does not change
208the revision of the submodule (i.e. update the superproject's gitlink)
209until the next time the branch of the submodule advances. In other words,
210if the currently used revision of the submodule is not the branch's head,
211adding a subscription will not cause an immediate update to the head. In
212this case the revision must be manually updated at the same time as adding
213the subscription.
David Pursehousee23c9312016-09-01 10:40:03 +0900214
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800215=== Relative submodules
Peter Jönssonf6488f72013-05-02 20:42:29 +0200216
217To enable easier usage of Gerrit mirrors and/or distribution over
218several protocols, such as plain git and HTTP(S) as well as SSH, one
219can use relative submodules. This means that instead of providing the
220entire URL to the submodule a relative path is stated in the
221.gitmodules file.
222
223Gerrit will try to match the entire project name of the submodule
224including directories. Therefore it is important to supply the full
225path name of the Gerrit project, not only relative to the super
226repository. See the following example:
227
228We have a super repository placed under a sub directory.
229
230 product/super_repository.git
231
232To this repository we wish add a submodule "deeper" into the directory
233structure.
234
235 product/framework/subcomponent.git
236
237Now we need to edit the .gitmodules to include the complete path to
238the Gerrit project. Observe that we need to use two "../" to include
239the complete Gerrit project path.
240
241 path = subcomponent.git
242 url = ../../product/framework/subcomponent.git
243 branch = master
244
245In contrast the following will not setup proper submodule
246subscription, even if the submodule will be successfully cloned by git
247from Gerrit.
248
249 path = subcomponent.git
250 url = ../framework/subcomponent.git
251 branch = master
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200252
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800253== Removing Subscriptions
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200254
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700255To remove a subscription, either disable the subscription from the
256submodules configuration or remove the submodule or information thereof
257(such as the branch field) in the superproject.
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200258
259GERRIT
260------
261Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700262
263SEARCHBOX
264---------