Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · –...
Transcript of Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · –...
![Page 1: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/1.jpg)
Git and Gerrit Workflows
Enforcing Manual & Automated Review
![Page 2: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/2.jpg)
• Branching and Workflow Review • A Look at Gerrit • The Gerrit Workflow • Other Workflows • Customizing Gerrit Workflow
Agenda
![Page 3: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/3.jpg)
Branching and Workflow Basics
![Page 4: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/4.jpg)
Branches represent divergence. They confuse developers. They add complexity.
![Page 5: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/5.jpg)
So why make a branch?
![Page 6: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/6.jpg)
Maintain related sets of work – Isolate unstable or custom code
trunk
feature
![Page 7: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/7.jpg)
Maintain related sets of work – Work on older releases
trunk
rel-1.1
![Page 8: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/8.jpg)
Branches Have… DuraDon
trunk
feature Promote and
reDre
![Page 9: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/9.jpg)
Branches Have… Stability
trunk
feature
rel-1.1
More stable
Less stable
![Page 10: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/10.jpg)
Branches Have… Flow of Change
trunk
feature
rel-1.1
Merge down
Promote up
![Page 11: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/11.jpg)
Simple to Complex
trunk feature
sandbox
rel
patch
custom
![Page 12: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/12.jpg)
Workflow Guides the Flow of Change
trunk
task branch
svn merge git merge
![Page 13: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/13.jpg)
A Look at Gerrit
![Page 14: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/14.jpg)
Origins
Mondrian!
Rietveld!
Perforce-‐centric Google internal
Open source Subversion
Android ecosystem Vibrant community
![Page 15: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/15.jpg)
Community
User Conferences Hackathons
Sponsors Contributors
Qualcomm Motorola Google SAP
SpoDfy Yahoo Nvidia Samsung
![Page 16: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/16.jpg)
Repository Management
Key Features
Code Review
Access Control
![Page 17: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/17.jpg)
Repository Management
Key Features
Code Review
Access Control
Repo creaDon HTTPS/SSH
![Page 18: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/18.jpg)
Repository Management
Key Features
Code Review
Access Control
Hierarchical model Granular permissions
LDAP & others
![Page 19: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/19.jpg)
Gerrit Workflow
![Page 20: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/20.jpg)
The Gerrit Model
• Unreviewed changes isolated
• CI built into workflow
![Page 21: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/21.jpg)
Android
• ‘Repo’ coordinates 300+ repos
• Isolates patch authors from commi\ers
• Otherwise not as bad as it looks
![Page 22: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/22.jpg)
• All changes are reviewed • Dynamic review branches • Review IDs group serial work • Human voting • Enforce CI on every commit
– Build system gets a vote!
Key Principles
![Page 23: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/23.jpg)
Steps
Clone • Gerrit has unusual URLs • Should clone change-‐id hook
Push • Use special review ref • Can amend exisDng review
Review • +1 to like, +2 to approve • Build result
Submit • Merge through UI • Commit to branch
![Page 24: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/24.jpg)
• Web UI • CLI / API • Download patch • Voting rights based on access control
– +/- 1 – +/- 2 – Verify
Review Options
![Page 25: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/25.jpg)
Check out original commit
Amend commit with new work
Push again
Rework
Each change has a unique
ID
All amendments preserved as patch sets
![Page 26: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/26.jpg)
• Even rejected changes are valuable • Comments are often as important as the
code • Can enforce ‘signed off by’
Etiquette
![Page 27: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/27.jpg)
• Best to see it in action • Find a demo station
This is weird
![Page 28: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/28.jpg)
Other Git Workflows
![Page 29: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/29.jpg)
Fork and pull
Pull request Work Fork
![Page 30: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/30.jpg)
Topic branches
30
Merge request
Push branch Work
Make topic branch
Clone
![Page 31: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/31.jpg)
Mainline model
Push frequently
Push to trunk
Work locally
31
![Page 32: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/32.jpg)
Git Flow
• Uses several long lived branches
– Master – Develop – Staging
• Feature and release branches and tags
32
![Page 33: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/33.jpg)
Gerrit
• Similar to topic branches with very narrow topics
• Really represents mainline model with continuous review
ConDnuous Review ‘The speedy picking up of unreviewed pending commits’ -‐ Paul Hammant
• Every commit is reviewed • Within minute or hours of
compleDon • Before it hits trunk • Ties review to code
![Page 34: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/34.jpg)
Mainline model is built for conDnuous delivery
In parDcular have a mainline: a single branch of the project currently under development. Pre\y much everyone should work off this mainline most of the Dme. (Reasonable branches are bug fixes of prior producDon releases and temporary experiments.) – Mar8n Fowler
git commit –am “task work” git push origin HEAD:refs/for/master <review, build, and publish in Gerrit>
Steps to Trunk
![Page 35: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/35.jpg)
Customizing Gerrit Workflow
![Page 36: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/36.jpg)
" Defines when a change can be submitted
" Default – One highest vote in
each category – No lowest votes in
any category
Submit Rules
Both: Human +2!CI +1! But not: Human -2!Or CI -1!
![Page 37: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/37.jpg)
" Defines how a change can be submitted (per project)
" Types – Fast forward only – Merge if necessary – Merge always – Cherry pick – Rebase if
necessary
Submit Types
![Page 38: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/38.jpg)
" Prolog – Logic programming
language – Often used in AI – Bit of a learning
curve
Custom Workflows
" What’s possible – Project-specific submit rules – Replace default submit
rules – Define when a commit is
accepted – Override project submit type
![Page 39: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/39.jpg)
" Prolog-café fork embedded " Prolog-shell provided for testing " SWI-Prolog environment for debugging
Prolog in Gerrit
![Page 40: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/40.jpg)
" Stored in rules.pl in refs/meta/config branch – Modify via Git commits
" Sequence – Gerrit provides a set of facts about a change
• Author, committer, message, etc. • Provided in gerrit package
– Then calls rules.pl • Submit_rule predicate • Return value indicates whether change is
submittable • And indicates the submit criteria
Project-specific submit rules
![Page 41: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/41.jpg)
" Filters submit rules " Runs up parent project hierarchy " Mechanism for global admins to enforce
rules across all projects
Global submit filters
![Page 42: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/42.jpg)
" Write a submit_type predicate " For any change indicate accepted submit
type " Can include submit type filters
Custom submit type
![Page 43: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/43.jpg)
" Test submit_rule against a real change in Gerrit
" Use test-submit rule
Testing submit rules
cat rules.pl | ! ssh gerrit_host gerrit test-submit rule <change id> -s!
![Page 44: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/44.jpg)
Example: Authors cannot +2
submit_rule(S) :-! gerrit:default_submit(X),! X =.. [submit | Ls],! add_non_author_approval(Ls, R),! S =.. [submit | R].!!add_non_author_approval(S1, S2) :-! gerrit:commit_author(A),! gerrit:commit_label(label('Code-Review', 2), R),! R \= A, !,! S2 = [label('Non-Author-Code-Review', ok(R)) | S1].!add_non_author_approval(S1, ! [label('Non-Author-Code-Review', need(_)) | S1]).!
![Page 45: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/45.jpg)
Example: Only fast forward on release branches
submit_type(fast_forward_only) :-! gerrit:change_branch(B), regex_matches('refs/heads/! release.*', B),! !.!submit_type(T) :- gerrit:project_default_submit_type(T)!
![Page 46: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change](https://reader033.fdocuments.in/reader033/viewer/2022053011/5f0eb3637e708231d44082ca/html5/thumbnails/46.jpg)
Thank You @rdefauw