aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/documentation/gerrit.md
blob: 24cf0b6b7edc3d97ff2a730e26d81c17b1b61340 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
Using Gerrit without git-cl
===========================

Setup
-----

The following must be executed within the Skia source repository.

This command sets up a Git commit-message hook to add a unique Change-Id to
each commit.  Gerrit only accepts changes with a Change-Id and uses it to
identify which review a change applies to.

    curl -Lo "$(git rev-parse --git-dir)/hooks/commit-msg"
      'https://gerrit-review.googlesource.com/tools/hooks/commit-msg'
    chmod +x "$(git rev-parse --git-dir)/hooks/commit-msg"

If you acquired Skia from a mirror (such as github), you need to change the
`origin` remote to point to point to googlesource.  Advanced uses will note
that there is nothing special about the string `origin` and that you could call
this remote anything you want, as long as you use that name for `get push`.

    git remote set-url origin 'https://skia.googlesource.com/skia.git'


Authentication
--------------

Go to [skia.googlesource.com/new-password](https://skia.googlesource.com/new-password)
and follow the instructions.


Creating a Change
-----------------

1.  Create a topic branch

        git checkout -b TOPIC

    You may want to set a tracking branch at this time with:

        git checkout -b TOPIC -t origin/master

2.  Make a commit.

        echo FOO >> whitespace.txt
        git commit --all --message 'Change Foo'
        git log -1

    `git log` should show that a Change-Id line has been added you your commit
    message.


3.  If You have multiple commits in your branch, Gerrit will think you want
    multiple changes that depend on each other.  If this is not what you want,
    you need to squash the commits.

4.  Push to Gerrit

        git push origin @:refs/for/master

    `@` is shorthand for `HEAD`, introduced in git v1.8.5.

    If you want to target a branch other than `master`, that can be specified
    here, too.  For example:

        git push origin @:refs/for/chrome/m57

    [Gerrit Upload Documentation](https://gerrit-review.googlesource.com/Documentation/user-upload.html)


Updating a Change
-----------------


1.  Edit your commits more.

        echo BAR >> whitespace.txt
        git commit --all --amend

    Changes to the commit message will be sent with the push as well.


2.  Re-squash if needed.  (Not needed if you only amended your original commit.)


3.  Push to Gerrit.

        git push origin @:refs/for/master

    If you want to set a comment message for this patch set, do this instead:

        git push origin @:refs/for/master%m=this_is_the_patch_set_comment_message

    The title of this patch set will be "this is the patch set comment message".


Using `git cl try`
------------------

On your current branch, after uploading to gerrit:

    git cl issue $(experimental/tools/gerrit-change-id-to-number @)

Now `git cl try` and `bin/try` will work correctly.


Scripting
---------

You may want to make git aliases for common tasks:

    git config alias.gerrit-push 'push origin @:refs/for/master'

The following alias amends the head without editing the commit message:

    git config alias.amend-head 'commit --all --amend --reuse-message=@'

Set the CL issue numnber:

    git config alias.setcl '!git-cl issue $(experimental/tools/gerrit-change-id-to-number @)'

The following shell script will squash all commits on the current branch,
assuming that the branch has an upstream topic branch.

    squash_git_branch() {
        local MESSAGE="$(git log --format=%B ^@{upstream} @)"
        git reset --soft $(git merge-base @ @{upstream})
        git commit -m "$MESSAGE" -e
    }

This shell script pushes to gerrit and adds a message to a patchset:

    gerrit_push_with_message() {
        local REMOTE='origin'
        local REMOTE_BRANCH='master'
        local MESSAGE="$(echo $*|sed 's/[^A-Za-z0-9]/_/g')"
        git push "$REMOTE" "@:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}"
    }

These shell scripts can be turned into Git aliases with a little hack:

    git config alias.squash-branch '!M="$(git log --format=%B ^@{u} @)";git reset --soft $(git merge-base @ @{u});git commit -m "$M" -e'

    git config alias.gerrit-push-message '!f(){ git push origin @:refs/for/master%m=$(echo $*|sed "s/[^A-Za-z0-9]/_/g");};f'

If your branch's upstream branch (set with `git branch --set-upstream-to=...`)
is set, you can use that to automatically push to that branch:

    gerrit_push_upstream() {
        local UPSTREAM_FULL="$(git rev-parse --symbolic-full-name @{upstream})"
        case "$UPSTREAM_FULL" in
            (refs/remotes/*);;
            (*) echo "Set your remote upstream branch."; return 2;;
        esac
        local UPSTREAM="${UPSTREAM_FULL#refs/remotes/}"
        local REMOTE="${UPSTREAM%%/*}"
        local REMOTE_BRANCH="${UPSTREAM#*/}"
        local MESSAGE="$(echo $*|sed 's/[^A-Za-z0-9]/_/g')"
        echo git push $REMOTE @:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}
        git push "$REMOTE" "@:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}"
    }

As a Git alias:

    git config alias.gerrit-push '!f()(F="$(git rev-parse --symbolic-full-name @{u})";case "$F" in (refs/remotes/*);;(*)echo "Set your remote upstream branch.";return 2;;esac;U="${F#refs/remotes/}";R="${U%%/*}";B="${U#*/}";M="$(echo $*|sed 's/[^A-Za-z0-9]/_/g')";echo git push $R @:refs/for/${B}%m=$M;git push "$R" "@:refs/for/${B}%m=$M");f'