Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1 | = Gerrit Code Review - Superproject subscription to submodules updates |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 2 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 3 | [[automatic_update]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 4 | == Description |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 5 | Gerrit supports a custom git superproject feature for tracking submodules. |
| 6 | This feature is useful for automatic updates on superprojects whenever |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 7 | a change is merged on tracked submodules. |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 8 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 9 | When a superproject is subscribed to a submodule, it is not |
| 10 | required to push/merge commits to this superproject to update the |
| 11 | gitlink to the submodule. Whenever a commit is merged in a submodule, |
| 12 | its subscribed superproject is updated by Gerrit. |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 13 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 14 | Imagine a superproject called 'super' having a branch called 'dev' |
| 15 | having subscribed to a submodule 'sub' on a branch 'dev-of-sub'. When a commit |
| 16 | is merged in branch 'dev-of-sub' of 'sub' project, Gerrit automatically |
| 17 | creates a new commit on branch 'dev' of 'super' updating the gitlink |
| 18 | to point to the just merged commit. |
| 19 | |
| 20 | To 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 | |
| 29 | When a commit in a project is merged, Gerrit checks for superprojects |
| 30 | that are subscribed to the the project and automatically updates those |
| 31 | superprojects with a commit that updates the gilink for the project. |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 32 | |
Stefan Beller | 8cc252e | 2016-03-10 10:06:53 -0800 | [diff] [blame] | 33 | This feature is enabled by default and can be disabled |
| 34 | via link:config-gerrit.html#submodule.enableSuperProjectSubscriptions[submodule.enableSuperProjectSubscriptions] |
| 35 | in the server configuration. |
| 36 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 37 | == Git submodules overview |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 38 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 39 | Submodules are a Git feature that allows an external repository to be |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 40 | attached inside a repository at a specific path. The objective here |
| 41 | is to provide a brief overview, further details can be found |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 42 | in the official Git submodule documentation. |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 43 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 44 | Imagine a repository called 'super' and another one called 'sub'. |
| 45 | Also consider 'sub' available in a running Gerrit instance on "server". |
| 46 | With this feature, one could attach 'sub' inside of 'super' repository |
| 47 | at path 'sub' by executing the following command when being inside |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 48 | 'super': |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 49 | ---- |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 50 | git submodule add ssh://server/sub sub |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 51 | ---- |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 52 | |
| 53 | Still considering the above example, after its execution notice that |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 54 | inside the local repository 'super' the 'sub' folder is considered a |
| 55 | gitlink to the external repository 'sub'. Also notice a file called |
Peter Jönsson | f6488f7 | 2013-05-02 20:42:29 +0200 | [diff] [blame] | 56 | .gitmodules is created (it is a configuration file containing the |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 57 | subscription of 'sub'). To provide the SHA-1 each gitlink points to in |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 58 | the external repository, one should use the command: |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 59 | ---- |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 60 | git submodule status |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 61 | ---- |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 62 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 63 | In the example provided, if 'sub' is updated and 'super' is supposed |
| 64 | to see the latest SHA-1 (considering here 'sub' has only the master |
| 65 | branch), one should then commit the modified gitlink for 'sub' in |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 66 | the 'super' project. Actually it would not even need to be an |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 67 | external update, one could move to 'sub' folder (inside 'super'), |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 68 | modify its content, commit, then move back to 'super' and |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 69 | commit the modified gitlink for 'sub'. |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 70 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 71 | == Creating a new subscription |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 72 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 73 | === Ensure the subscription is allowed |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 74 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 75 | Gerrit has a complex access control system, where different repositories |
| 76 | can be accessed by different groups of people. To ensure that the submodule |
| 77 | related information is allowed to be exposed in the superproject, |
| 78 | the submodule needs to be configured to enable the superproject subscription. |
| 79 | In a submodule client, checkout the refs/meta/config branch and edit |
| 80 | the subscribe capabilities in the 'project.config' file: |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 81 | ---- |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 82 | git fetch <remote> refs/meta/config:refs/meta/config |
| 83 | git checkout refs/meta/config |
| 84 | $EDITOR project.config |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 85 | ---- |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 86 | and add the following lines: |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 87 | ---- |
Zhen Chen | c6119c3 | 2016-05-18 15:46:56 -0700 | [diff] [blame] | 88 | [allowSuperproject "<superproject>"] |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 89 | refs = <refspec> |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 90 | ---- |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 91 | where the 'superproject' should be the exact project name of the superproject. |
| 92 | The refspec defines which branches of the submodule are allowed to be |
| 93 | subscribed to which branches of the superproject. See below for |
| 94 | link:#acl_refspec[details]. Push the configuration for review and |
| 95 | submit the change: |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 96 | ---- |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 97 | git add project.config |
| 98 | git commit -m "Allow <superproject> to subscribe" |
| 99 | git push <remote> HEAD:refs/for/refs/meta/config |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 100 | ---- |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 101 | After the change is integrated a superproject subscription is possible. |
| 102 | |
Stefan Beller | 5a49ca0 | 2016-05-18 14:13:28 -0700 | [diff] [blame] | 103 | The configuration is inherited from parent projects, such that you can have |
| 104 | a configuration in the "All-Projects" project like: |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 105 | ---- |
Stefan Beller | 5a49ca0 | 2016-05-18 14:13:28 -0700 | [diff] [blame] | 106 | [allowSuperproject "my-only-superproject"] |
| 107 | refs = refs/heads/*:refs/heads/* |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 108 | ---- |
Stefan Beller | 5a49ca0 | 2016-05-18 14:13:28 -0700 | [diff] [blame] | 109 | and then you don't have to worry about configuring the individual projects |
| 110 | any more. Child projects cannot negate the parent's configuration. |
| 111 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 112 | === Defining the submodule branch |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 113 | |
Peter Jönsson | f6488f7 | 2013-05-02 20:42:29 +0200 | [diff] [blame] | 114 | Since Gerrit manages subscriptions in the branch scope, we could have |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 115 | a scenario having a project called 'super' having a branch 'integration' |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 116 | subscribed to a project called 'sub' in branch 'integration', and also |
| 117 | having the same 'super' project but in branch 'dev' subscribed to the 'sub' |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 118 | project in a branch called 'local-dev'. |
| 119 | |
| 120 | After adding the git submodule to a super project, one should edit |
| 121 | the .gitmodules file to add a branch field to each submodule |
| 122 | section which is supposed to be subscribed. |
| 123 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 124 | As the branch field is a Gerrit-specific field it will not be filled |
Peter Jönsson | f6488f7 | 2013-05-02 20:42:29 +0200 | [diff] [blame] | 125 | automatically by the git submodule command, so one needs to edit it |
| 126 | manually. Its value should indicate the branch of a submodule project |
| 127 | that when updated will trigger automatic update of its registered |
| 128 | gitlink. |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 129 | |
Peter Jönsson | f6488f7 | 2013-05-02 20:42:29 +0200 | [diff] [blame] | 130 | The branch value could be "'.'" if the submodule project branch |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 131 | has the same name as the destination branch of the commit having |
| 132 | gitlinks/.gitmodules file. |
| 133 | |
Peter Jönsson | f6488f7 | 2013-05-02 20:42:29 +0200 | [diff] [blame] | 134 | If the intention is to make use of the Gerrit feature described |
| 135 | here, one should always be sure to update the .gitmodules file after |
| 136 | adding submodules to a super project. |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 137 | |
Peter Jönsson | f6488f7 | 2013-05-02 20:42:29 +0200 | [diff] [blame] | 138 | If 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 |
| 140 | submodule and there will be no automatic updates to the superproject. |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 141 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 142 | Whenever a commit is merged to a project, its project config is checked |
| 143 | to see if any potential superprojects are allowed to subscribe to it. |
| 144 | If so, the superproject is checked if a valid subscription exists |
| 145 | by checking the .gitmodules file for the a submodule which includes |
| 146 | a `branch` field and a url pointing to this server. |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 147 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 148 | [[acl_refspec]] |
| 149 | === The RefSpec in the allowSuperproject section |
| 150 | The RefSpec for defining the branch level access for subscriptions look similar |
| 151 | to Git style RefSpecs used for pushing in Git. Regular expressions |
| 152 | as found in the ACL configuration are not supported. The most restrictive |
| 153 | RefSpec is allowing one specific branch of the submodule to be subscribed |
| 154 | to one specific branch of the superproject via: |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 155 | ---- |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 156 | [allowSuperproject "<superproject>"] |
| 157 | refs = refs/heads/<submodule-branch>:refs/heads/<superproject-branch> |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 158 | ---- |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 159 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 160 | If 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 Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 163 | ---- |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 164 | [allowSuperproject "<superproject>"] |
Stefan Beller | db0359a | 2016-05-18 09:21:52 -0700 | [diff] [blame] | 165 | refs = refs/heads/*:refs/heads/* |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 166 | ---- |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 167 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 168 | If you want to enable a branch to be subscribed to any other branch of |
| 169 | the superproject, omit the second part of the RefSpec: |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 170 | ---- |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 171 | [allowSuperproject "<superproject>"] |
Stefan Beller | db0359a | 2016-05-18 09:21:52 -0700 | [diff] [blame] | 172 | refs = refs/heads/<submodule-branch> |
Michael Ochmann | b99feab | 2016-07-06 14:10:22 +0200 | [diff] [blame] | 173 | ---- |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 174 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 175 | === Subscription Limitations |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 176 | |
Peter Jönsson | f6488f7 | 2013-05-02 20:42:29 +0200 | [diff] [blame] | 177 | Gerrit will only automatically update superprojects where the |
| 178 | submodules are hosted on the same Gerrit instance as the |
| 179 | superproject. Gerrit determines this by checking the hostname of the |
| 180 | submodule specified in the .gitmodules file and comparing it to the |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 181 | hostname from the link:config-gerrit.html#gerrit.canonicalWebUrl[`gerrit.canonicalWebUrl`]. |
Peter Jönsson | f6488f7 | 2013-05-02 20:42:29 +0200 | [diff] [blame] | 182 | |
| 183 | It is currently not possible to use the submodule subscription feature |
| 184 | with a canonical web URL hostname that differs from the hostname of |
| 185 | the submodule. Instead relative submodules should be used. |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 186 | |
| 187 | The Gerrit instance administrator group should always certify to |
Peter Jönsson | f6488f7 | 2013-05-02 20:42:29 +0200 | [diff] [blame] | 188 | provide the canonical web URL value in its configuration file. Users |
| 189 | should certify to use the correct hostname of the running Gerrit |
| 190 | instance to add/subscribe submodules. |
| 191 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 192 | === Relative submodules |
Peter Jönsson | f6488f7 | 2013-05-02 20:42:29 +0200 | [diff] [blame] | 193 | |
| 194 | To enable easier usage of Gerrit mirrors and/or distribution over |
| 195 | several protocols, such as plain git and HTTP(S) as well as SSH, one |
| 196 | can use relative submodules. This means that instead of providing the |
| 197 | entire URL to the submodule a relative path is stated in the |
| 198 | .gitmodules file. |
| 199 | |
| 200 | Gerrit will try to match the entire project name of the submodule |
| 201 | including directories. Therefore it is important to supply the full |
| 202 | path name of the Gerrit project, not only relative to the super |
| 203 | repository. See the following example: |
| 204 | |
| 205 | We have a super repository placed under a sub directory. |
| 206 | |
| 207 | product/super_repository.git |
| 208 | |
| 209 | To this repository we wish add a submodule "deeper" into the directory |
| 210 | structure. |
| 211 | |
| 212 | product/framework/subcomponent.git |
| 213 | |
| 214 | Now we need to edit the .gitmodules to include the complete path to |
| 215 | the Gerrit project. Observe that we need to use two "../" to include |
| 216 | the complete Gerrit project path. |
| 217 | |
| 218 | path = subcomponent.git |
| 219 | url = ../../product/framework/subcomponent.git |
| 220 | branch = master |
| 221 | |
| 222 | In contrast the following will not setup proper submodule |
| 223 | subscription, even if the submodule will be successfully cloned by git |
| 224 | from Gerrit. |
| 225 | |
| 226 | path = subcomponent.git |
| 227 | url = ../framework/subcomponent.git |
| 228 | branch = master |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 229 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 230 | == Removing Subscriptions |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 231 | |
Stefan Beller | c62f9fe | 2016-03-21 12:14:58 -0700 | [diff] [blame] | 232 | To remove a subscription, either disable the subscription from the |
| 233 | submodules configuration or remove the submodule or information thereof |
| 234 | (such as the branch field) in the superproject. |
Rafael Rabelo Silva | f6d9e74 | 2012-01-06 11:32:32 -0200 | [diff] [blame] | 235 | |
| 236 | GERRIT |
| 237 | ------ |
| 238 | Part of link:index.html[Gerrit Code Review] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 239 | |
| 240 | SEARCHBOX |
| 241 | --------- |