blob: a962d25e4fda61a69aec39e4c271c00a5de7041b [file] [log] [blame]
John DeNisco06dcd452018-07-26 12:45:10 -04001.. _gitreview:
2
andrewbcddab22018-08-06 17:40:31 -04003*******************************
John DeNisco758dc462018-08-13 17:00:06 -04004Getting a Patch Reviewed
andrewbcddab22018-08-06 17:40:31 -04005*******************************
John DeNisco06dcd452018-07-26 12:45:10 -04006
John DeNisco758dc462018-08-13 17:00:06 -04007This section describes how to get FD.io VPP sources reviewed and merged.
John DeNisco06dcd452018-07-26 12:45:10 -04008
andrewbcddab22018-08-06 17:40:31 -04009Setup
10========
John DeNisco06dcd452018-07-26 12:45:10 -040011
andrewbcddab22018-08-06 17:40:31 -040012If you don't have a Linux Foundation ID, `create one here. <https://identity.linuxfoundation.org/>`_
John DeNisco06dcd452018-07-26 12:45:10 -040013
andrewbcddab22018-08-06 17:40:31 -040014With your Linux Foundation ID credentials sign into `Gerrit Code Review at gerrit.fd.io <https://gerrit.fd.io/r/login/%23%2Fq%2Fstatus%3Aopen>`_
John DeNisco06dcd452018-07-26 12:45:10 -040015
andrewbcddab22018-08-06 17:40:31 -040016`Install git-review, <https://www.mediawiki.org/wiki/Gerrit/git-review>`_ which is a "command-line tool for Git / Gerrit to submit a change or to fetch an existing one."
John DeNisco06dcd452018-07-26 12:45:10 -040017
andrewbcddab22018-08-06 17:40:31 -040018If you're on Ubuntu, install keychain:
19
20.. code-block:: console
21
22 $ sudo apt-get install keychain
23
24ssh keys
25-------------
26
27To get FD.io VPP documents reviewed the VPP repository should be cloned with ssh. You should be logged into Gerrit Code Review as noted above.
28
29Create your public and private ssh key with:
John DeNisco06dcd452018-07-26 12:45:10 -040030
31.. code-block:: console
32
33 $ ssh-keygen -t rsa
34 $ keychain
35 $ cat ~/.ssh/id_rsa.pub
36
andrewbcddab22018-08-06 17:40:31 -040037Copy **all** the contents of the public key (id_rsa.pub) output by the above **cat** command. Then go to your `SSH Public keys settings page <https://gerrit.fd.io/r/#/settings/ssh-keys>`_, click **Add Key ...**, paste your public key, and finally click **Add**.
38
39.. _clone-ssh:
40
41Clone with ssh
42==============
43
44Clone the repo with:
John DeNisco06dcd452018-07-26 12:45:10 -040045
46.. code-block:: console
47
48 $ git clone ssh://gerrit.fd.io:29418/vpp
49 $ cd vpp
50
andrewbcddab22018-08-06 17:40:31 -040051This will only work if the name of the user on your system matches your Gerrit username.
John DeNisco06dcd452018-07-26 12:45:10 -040052
andrewbcddab22018-08-06 17:40:31 -040053Otherwise, clone with:
54
55.. code-block:: console
56
John DeNisco2ba9dcf2018-08-23 14:04:22 -040057 $ git clone ssh://<YOUR_GERRIT_USERNAME>@gerrit.fd.io:29418/vpp
andrewbcddab22018-08-06 17:40:31 -040058 $ cd vpp
59
John DeNiscoce96dda2018-08-14 16:04:09 -040060When attempting to clone the repo Git will prompt you asking if you want to add the Server Host Key to the list of known hosts. Enter **yes** and press the **Enter** key.
andrewbcddab22018-08-06 17:40:31 -040061
62Git Review
63===========
64
John DeNiscoce96dda2018-08-14 16:04:09 -040065The VPP documents use the gerrit server, and git review for submitting and fetching patches.
andrewbcddab22018-08-06 17:40:31 -040066
67
68New patch
69-----------------
70
John DeNiscoce96dda2018-08-14 16:04:09 -040071When working with a new patch, use the following commands to get your patch reviewed.
andrewbcddab22018-08-06 17:40:31 -040072
John DeNiscoce96dda2018-08-14 16:04:09 -040073Make sure you have modified the correct files by issuing the following commands:
John DeNisco06dcd452018-07-26 12:45:10 -040074
75.. code-block:: console
76
John DeNisco2d1a0432018-07-26 16:21:31 -040077 $ git status
andrewbcddab22018-08-06 17:40:31 -040078 $ git diff
79
John DeNisco758dc462018-08-13 17:00:06 -040080Then add and commit the patch. You may want to add a tag to the commit comments.
John DeNisco2ba9dcf2018-08-23 14:04:22 -040081For example for a document with only patches you should add the tag **docs:**.
andrewbcddab22018-08-06 17:40:31 -040082
83.. code-block:: console
84
John DeNisco2d1a0432018-07-26 16:21:31 -040085 $ git add <filename>
John DeNisco758dc462018-08-13 17:00:06 -040086 $ git commit -s -m "<*TAG*>: <*COMMIT_MESSAGE*>"
John DeNisco2d1a0432018-07-26 16:21:31 -040087 $ git review
John DeNisco06dcd452018-07-26 12:45:10 -040088
andrewbcddab22018-08-06 17:40:31 -040089If you are creating a draft, meaning you do not want your changes reviewed yet, do the following:
John DeNisco06dcd452018-07-26 12:45:10 -040090
andrewbcddab22018-08-06 17:40:31 -040091.. code-block:: console
John DeNisco06dcd452018-07-26 12:45:10 -040092
John DeNisco2d1a0432018-07-26 16:21:31 -040093 $ git review -D
John DeNisco06dcd452018-07-26 12:45:10 -040094
andrewbcddab22018-08-06 17:40:31 -040095After submitting a review, reset where the HEAD is pointing to with:
John DeNisco06dcd452018-07-26 12:45:10 -040096
andrewbcddab22018-08-06 17:40:31 -040097.. code-block:: console
98
99 $ git reset --hard origin/master
100
101Existing patch
102-----------------------
103
104The "change number" used below is in the URL of the review.
105
John DeNisco758dc462018-08-13 17:00:06 -0400106After clicking an individual review, the change number can be found in the URL at "https://gerrit.fd.io/r/#/c/<*CHANGE_NUMBER*>/"
andrewbcddab22018-08-06 17:40:31 -0400107
108To view an existing patch:
109
110.. code-block:: console
111
112 $ git review -d <change number>
113 $ git status
114 $ git diff
115
116.. caution::
117
118 If you have made changes and do "git review -d <change number>", your current
119 changes will try to be stashed so that the working tree can change to the review branch
120 you specified. If you want to make sure you don't lose your changes, clone another Gerrit
121 repo into a new directory using the cloning steps shown in :ref:`clone-ssh`, and perform
122 "git review -d <change number>" in this new directory.
123
124To modify an existing patch, make sure you modified the correct files, and apply the patch with:
125
126.. code-block:: console
127
128 $ git review -d <change number>
129 $ git status
130 $ git diff
131
132 $ git add <filename>
133 $ git commit --amend
134 $ git review
135
John DeNisco2ba9dcf2018-08-23 14:04:22 -0400136When you're done viewing or modifying a branch, get back to the master branch by entering:
John DeNisco06dcd452018-07-26 12:45:10 -0400137
138.. code-block:: console
139
John DeNisco2d1a0432018-07-26 16:21:31 -0400140 $ git reset --hard origin/master
141 $ git checkout master
John DeNisco758dc462018-08-13 17:00:06 -0400142
Dave Barach8a692892018-10-24 09:23:23 -0400143Patch Conflict Resolution
144-------------------------
John DeNisco758dc462018-08-13 17:00:06 -0400145
Dave Barach8a692892018-10-24 09:23:23 -0400146Two different patch conflict scenarios arise from time to
147time. Sometime after uploading a patch to https://gerrit.fd.io, the
148gerrit UI may show a patch status of "Merge Conflict."
149
150Or, you may attempt to upload a new patch-set via "git review," only to
151discover that the gerrit server won't allow the upload due to an upstream
152merge conflict.
153
154In both cases, it's [usually] fairly simple to fix the problem. You
155need to rebase the patch onto master/latest. Details vary from case to
156case.
157
158Here's how to rebase a patch previously uploaded to the Gerrit server
159which now has a merge conflict. In a fresh workspace cloned from
160master/latest, do the following:
John DeNisco758dc462018-08-13 17:00:06 -0400161
162.. code-block:: console
163
John DeNisco2ba9dcf2018-08-23 14:04:22 -0400164 $ git-review -d <*Gerrit change #*>
John DeNisco758dc462018-08-13 17:00:06 -0400165 $ git rebase origin/master
166 while (conflicts)
167 <fix conflicts>
168 $ git rebase --continue
169 $ git review
170
Dave Barach8a692892018-10-24 09:23:23 -0400171In the upload-failure case, use caution: carefully **save your work**
172before you do anything else!
John DeNisco758dc462018-08-13 17:00:06 -0400173
Dave Barach8a692892018-10-24 09:23:23 -0400174Rebase your patch and try again. Please **do not** re-download ["git
175review -d"] the patch from the gerrit server...:
176
177.. code-block:: console
178
179 $ git rebase origin/master
180 while (conflicts)
181 <fix conflicts>
182 $ git rebase --continue
183 $ git review
John DeNisco758dc462018-08-13 17:00:06 -0400184