1 of 54

Code Matters - �Eclipse Hackers Git Guide

EclipseCon 2014

http://eclipse.org/jgit

http://eclipse.org/egit

http://code.google.com/p/gerrit

Stefan Lay�(SAP)

Lars Vogel

(vogella)

Christian Grail�(SAP)

2 of 54

Gerrit Code Review @ Eclipse

https://git.eclipse.org/r/ is activated for most projects

3 of 54

Case study: Contributing to Eclipse

  • Create a user account https://dev.eclipse.org/site_login/createaccount.php
  • Log into https://projects.eclipse.org/ and agree to the Contributor License agreement
  • Logon to the Gerrit Web UI at https://git.eclipse.org/r/ using the email address you registered with your Eclipse (and Bugzilla) account and your Eclipse password.
  • https://git.eclipse.org/r/#/settings/ and upload your public SSH key
  • Clone platform.ui from git.eclipse.org (this takes a while)
  • Fix something and upload the change

4 of 54

Agenda

Introduction

Exercises

Setup & Cloning the Sample Repository

Local Development with EGit

Gerrit Code Review�Contribution to Eclipse

Q & A

5 of 54

Git

Version Control

Distributed

Created 2005 for Linux Kernel development

Enables collaborative Workflows

6 of 54

Git at Eclipse

2010

2011

2012

2014

EGit and JGit projects used Git and Gerrit

Projects could move to git

Gerrit available for all projects

CVS support ended

2013

7 of 54

Development with Git and Eclipse

8 of 54

Developer PC

Gerrit

git

git

git

git

Developer PC

git

git

clone repository

9 of 54

Sample Application

10 of 54

Git Exercises

1 Setup & Clone the example repository

2 Develop a feature

3 Work on branches in parallel

4 Fetch the latest state

Copyright © S. Lay, M. Sohn

11 of 54

Git in a nutshell

12 of 54

Git Concepts: Storage

13 of 54

Git Concepts: Storage

14 of 54

Git Concepts: Commits

15 of 54

Git Concepts: Commits

16 of 54

Git Concepts: Branches

17 of 54

Git Concepts: Branches

18 of 54

Git Exercises

5 Merging, Rebasing, Resolving Conflicts

6 History view

7 Change a series of commits

8 Git blame

19 of 54

Gerrit code review

20 of 54

Originally developed by Google for code review of the Android OS project

21 of 54

Gerrit Code Review @ Eclipse

https://git.eclipse.org/r/ is activated for most projects

22 of 54

Contributions in Git

I fix Eclipse

23 of 54

Contributions in Git

Integration

repository

Contributor 1

Fetch/ Push

Git

Fetch

I fix Eclipse

24 of 54

Contributions either via patches or commit rights

Fetch/

Push

Reviews

I don't know this guy,

he does not get

commit rights.

Committer

25 of 54

Reviewing patches

Fetch/

Push

Reviews

To much

work… especially if there is a feedback loop

Committer

26 of 54

Rule #1 of good code review - Make it easy!

Reviews must

be easy

Contributions

must be

easy

27 of 54

Roles in a Gerrit project

  • Contributor
  • Reviewer
  • Committer
  • Admin

28 of 54

Review feedback

  • -2 Blocks (committer only)
  • -1 Please adjust
  • 1 OK
  • 2 Good to go (commiter only)

29 of 54

Integration

repository

Contributor 1

Contributor 2

Reviewer

Fetch/

Push

Fetch

Fetch/ Push

CI Build

Server

Fetch

Gerrit

Reviews

Fetch

Fetch

Approve +1

Suggestion to improve -1

30 of 54

Integration

repository

CI Build

Server

Fetch

Gerrit

Reviews

Approve +2

Committer

Rejects -2

31 of 54

Advantages of Gerrit code review

  • “Safe” to contribute
  • Easy for all sides
  • Feedback possible on a line-by-line basis
  • Great learning environment

32 of 54

One Commit == one Gerrit review

Gerrit review is identified via the Change-ID in the commit message

Amend the commit and push the changes to update the review

33 of 54

Dark side of Gerrit

34 of 54

Comparison to Github

  • Merge requests based on branches
  • Feels easier than reviews based on commits
  • But: Github review system not as advanced as with Gerrit

35 of 54

Gerrit

Access Control

Gerrit

git push

36 of 54

Git Concepts: Pushing to Gerrit

37 of 54

Demo

38 of 54

Gerrit

Commenting

39 of 54

Gerrit

Discussing & Improving

Copyright © S. Lay, M. Sohn

40 of 54

Gerrit

Voting

41 of 54

Gerrit

Learn more:

Talk by Shawn Pearce (Gerrit founder and Project Lead)�and Ian Bull

Extending Gerrit: A Look at the Gerrit Plugin API

Tuesday, 10:30 to 11:05, Bayside

42 of 54

Gerrit Exercises

1 Configure push to Gerrit

2 Push change to Gerrit

3 Review change

4 Improve a change

5 Submit a change to the codebase

6 New Changescreen

7 View Gerrit review notes

43 of 54

Common

ancestor

Commit 3

origin/master

Gerrit issue #1 – non fast forward change

Commit 4

Gerrit review 2

Gerrit review 3

Commit 2

Commit A

Commit B

44 of 54

origin/master

Solution issue #1 – Rebase

Commit 4

Gerrit review 2

Gerrit review 3

Commit A

Commit B

More...

45 of 54

Commit 1

Commit 2

Commit 3

origin/master

Gerrit issue #2 – Push a series of

unrelated changes

Commit 4

Gerrit review 1

Gerrit review 2

Gerrit review 3

46 of 54

Commit 1

Commit 2

Commit 3

origin/master

Gerrit issue #2 – Push a series of

unrelated changes

Commit 4

NO WAY THIS

GETS INTO OUR

CODE BASE!!!

Gerrit review 2

Gerrit review 3

47 of 54

Commit 1

Commit 2

Commit 3'

origin/master

Gerrit issue #2 – Solution

Commit 4'

git reset --hard origin/master

git cherrypick 4

Push again to Gerrit → new change set

Gerrit review 2

Gerrit review 3

48 of 54

Commit 1

Commit 2

origin/master

Gerrit issue #3 – Using the same Change-ID

in two commits

Commit 3

Change-ID I123

Change-ID I123

Change-ID I123

49 of 54

Commit 1

Commit 2

origin/master

Gerrit issue #3 – Solution: Squash commits

Commit 3

Squash commits

Push again to Gerrit → new change set

Change-ID I123

Change-ID I123

Change-ID I123

Commit 2'

Change-ID I123

Changes from 2 and 3

50 of 54

Gerrit Code Review @ Eclipse

https://git.eclipse.org/r/ is activated for most projects

51 of 54

Case study: Contributing to Eclipse

  • Create a user account https://dev.eclipse.org/site_login/createaccount.php
  • Log into https://projects.eclipse.org/ and agree to the Contributor License agreement
  • Logon to the Gerrit Web UI at https://git.eclipse.org/r/ using the email address you registered with your Eclipse (and Bugzilla) account and your Eclipse password.
  • https://git.eclipse.org/r/#/settings/ and upload your public SSH key
  • Clone platform.ui from git.eclipse.org (this takes a while)
  • Fix something and upload the change

52 of 54

Q&A

53 of 54

Join us at the

EclipseCon Hackathon

and learn how to hack on JGit / EGit

Harbour - Tuesday, March 18, 2014 - 19:00 to 21:00

54 of 54

Evaluate This Session

Select session from schedule

Evaluate:

1

2

3