blob: bccb074fbcb6c2a6e56da03cc5fe1c761ac52fe8 [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
30that are subscribed to the the project and automatically updates those
31superprojects with a commit that updates the gilink 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 Bellerc62f9fe2016-03-21 12:14:58 -070089 refs = <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"]
107 refs = 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
150The RefSpec for defining the branch level access for subscriptions look similar
151to Git style RefSpecs used for pushing in Git. Regular expressions
152as found in the ACL configuration are not supported. The most restrictive
153RefSpec is allowing one specific branch of the submodule to be subscribed
154to one specific branch of the superproject via:
Michael Ochmannb99feab2016-07-06 14:10:22 +0200155----
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700156 [allowSuperproject "<superproject>"]
157 refs = refs/heads/<submodule-branch>:refs/heads/<superproject-branch>
Michael Ochmannb99feab2016-07-06 14:10:22 +0200158----
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200159
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700160If you want to allow for a 1:1 mapping, i.e. 'master' maps to 'master',
161'stable' maps to 'stable', but not allowing 'master' to be subscribed to
162'stable':
Michael Ochmannb99feab2016-07-06 14:10:22 +0200163----
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700164 [allowSuperproject "<superproject>"]
Stefan Bellerdb0359a2016-05-18 09:21:52 -0700165 refs = refs/heads/*:refs/heads/*
Michael Ochmannb99feab2016-07-06 14:10:22 +0200166----
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200167
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700168If you want to enable a branch to be subscribed to any other branch of
169the superproject, omit the second part of the RefSpec:
Michael Ochmannb99feab2016-07-06 14:10:22 +0200170----
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700171 [allowSuperproject "<superproject>"]
Stefan Bellerdb0359a2016-05-18 09:21:52 -0700172 refs = refs/heads/<submodule-branch>
Michael Ochmannb99feab2016-07-06 14:10:22 +0200173----
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200174
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800175=== Subscription Limitations
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200176
Peter Jönssonf6488f72013-05-02 20:42:29 +0200177Gerrit will only automatically update superprojects where the
178submodules are hosted on the same Gerrit instance as the
179superproject. Gerrit determines this by checking the hostname of the
180submodule specified in the .gitmodules file and comparing it to the
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700181hostname from the link:config-gerrit.html#gerrit.canonicalWebUrl[`gerrit.canonicalWebUrl`].
Peter Jönssonf6488f72013-05-02 20:42:29 +0200182
183It is currently not possible to use the submodule subscription feature
184with a canonical web URL hostname that differs from the hostname of
185the submodule. Instead relative submodules should be used.
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200186
187The Gerrit instance administrator group should always certify to
Peter Jönssonf6488f72013-05-02 20:42:29 +0200188provide the canonical web URL value in its configuration file. Users
189should certify to use the correct hostname of the running Gerrit
190instance to add/subscribe submodules.
191
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800192=== Relative submodules
Peter Jönssonf6488f72013-05-02 20:42:29 +0200193
194To enable easier usage of Gerrit mirrors and/or distribution over
195several protocols, such as plain git and HTTP(S) as well as SSH, one
196can use relative submodules. This means that instead of providing the
197entire URL to the submodule a relative path is stated in the
198.gitmodules file.
199
200Gerrit will try to match the entire project name of the submodule
201including directories. Therefore it is important to supply the full
202path name of the Gerrit project, not only relative to the super
203repository. See the following example:
204
205We have a super repository placed under a sub directory.
206
207 product/super_repository.git
208
209To this repository we wish add a submodule "deeper" into the directory
210structure.
211
212 product/framework/subcomponent.git
213
214Now we need to edit the .gitmodules to include the complete path to
215the Gerrit project. Observe that we need to use two "../" to include
216the complete Gerrit project path.
217
218 path = subcomponent.git
219 url = ../../product/framework/subcomponent.git
220 branch = master
221
222In contrast the following will not setup proper submodule
223subscription, even if the submodule will be successfully cloned by git
224from Gerrit.
225
226 path = subcomponent.git
227 url = ../framework/subcomponent.git
228 branch = master
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200229
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800230== Removing Subscriptions
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200231
Stefan Bellerc62f9fe2016-03-21 12:14:58 -0700232To remove a subscription, either disable the subscription from the
233submodules configuration or remove the submodule or information thereof
234(such as the branch field) in the superproject.
Rafael Rabelo Silvaf6d9e742012-01-06 11:32:32 -0200235
236GERRIT
237------
238Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700239
240SEARCHBOX
241---------