• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Using Gerrit without git-cl
2===========================
3
4Setup
5-----
6
7The following must be executed within the Skia source repository.
8
9This command sets up a Git commit-message hook to add a unique Change-Id to
10each commit.  Gerrit only accepts changes with a Change-Id and uses it to
11identify which review a change applies to.
12
13    curl -Lo "$(git rev-parse --git-dir)/hooks/commit-msg"
14      'https://gerrit-review.googlesource.com/tools/hooks/commit-msg'
15    chmod +x "$(git rev-parse --git-dir)/hooks/commit-msg"
16
17If you acquired Skia from a mirror (such as github), you need to change the
18`origin` remote to point to point to googlesource.  Advanced uses will note
19that there is nothing special about the string `origin` and that you could call
20this remote anything you want, as long as you use that name for `get push`.
21
22    git remote set-url origin 'https://skia.googlesource.com/skia.git'
23
24
25Authentication
26--------------
27
28Go to [skia.googlesource.com/new-password](https://skia.googlesource.com/new-password)
29and follow the instructions.
30
31
32Creating a Change
33-----------------
34
351.  Create a topic branch
36
37        git checkout -b TOPIC
38
39    You may want to set a tracking branch at this time with:
40
41        git checkout -b TOPIC -t origin/master
42
432.  Make a commit.
44
45        echo FOO >> whitespace.txt
46        git commit --all --message 'Change Foo'
47        git log -1
48
49    `git log` should show that a Change-Id line has been added you your commit
50    message.
51
52
533.  If You have multiple commits in your branch, Gerrit will think you want
54    multiple changes that depend on each other.  If this is not what you want,
55    you need to squash the commits.
56
574.  Push to Gerrit
58
59        git push origin @:refs/for/master
60
61    `@` is shorthand for `HEAD`, introduced in git v1.8.5.
62
63    If you want to target a branch other than `master`, that can be specified
64    here, too.  For example:
65
66        git push origin @:refs/for/chrome/m57
67
68    [Gerrit Upload Documentation](https://gerrit-review.googlesource.com/Documentation/user-upload.html)
69
705.  Open in web browser:
71
72        bin/sysopen https://skia-review.googlesource.com/c/skia/+/$(bin/gerrit-number @)
73
74Updating a Change
75-----------------
76
77
781.  Edit your commits more.
79
80        echo BAR >> whitespace.txt
81        git commit --all --amend
82
83    Changes to the commit message will be sent with the push as well.
84
85
862.  Re-squash if needed.  (Not needed if you only amended your original commit.)
87
88
893.  Push to Gerrit.
90
91        git push origin @:refs/for/master
92
93    If you want to set a comment message for this patch set, do this instead:
94
95        git push origin @:refs/for/master%m=this_is_the_patch_set_comment_message
96
97    The title of this patch set will be "this is the patch set comment message".
98
99
100Using `git cl try`
101------------------
102
103On your current branch, after uploading to gerrit:
104
105    git cl issue $(bin/gerrit-number @)
106
107Now `git cl try` and `bin/try` will work correctly.
108
109
110Scripting
111---------
112
113You may want to make git aliases for common tasks:
114
115    git config alias.gerrit-push 'push origin @:refs/for/master'
116
117The following alias amends the head without editing the commit message:
118
119    git config alias.amend-head 'commit --all --amend --reuse-message=@'
120
121Set the CL issue numnber:
122
123    git config alias.setcl '!git-cl issue $(bin/gerrit-number @)'
124
125The following shell script will squash all commits on the current branch,
126assuming that the branch has an upstream topic branch.
127
128    squash_git_branch() {
129        local MESSAGE="$(git log --format=%B ^@{upstream} @)"
130        git reset --soft $(git merge-base @ @{upstream})
131        git commit -m "$MESSAGE" -e
132    }
133
134This shell script pushes to gerrit and adds a message to a patchset:
135
136    gerrit_push_with_message() {
137        local REMOTE='origin'
138        local REMOTE_BRANCH='master'
139        local MESSAGE="$(echo $*|sed 's/[^A-Za-z0-9]/_/g')"
140        git push "$REMOTE" "@:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}"
141    }
142
143These shell scripts can be turned into Git aliases with a little hack:
144
145    git config alias.squash-branch '!M="$(git log --format=%B ^@{u} @)";git reset --soft $(git merge-base @ @{u});git commit -m "$M" -e'
146
147    git config alias.gerrit-push-message '!f(){ git push origin @:refs/for/master%m=$(echo $*|sed "s/[^A-Za-z0-9]/_/g");};f'
148
149If your branch's upstream branch (set with `git branch --set-upstream-to=...`)
150is set, you can use that to automatically push to that branch:
151
152    gerrit_push_upstream() {
153        local UPSTREAM_FULL="$(git rev-parse --symbolic-full-name @{upstream})"
154        case "$UPSTREAM_FULL" in
155            (refs/remotes/*);;
156            (*) echo "Set your remote upstream branch."; return 2;;
157        esac
158        local UPSTREAM="${UPSTREAM_FULL#refs/remotes/}"
159        local REMOTE="${UPSTREAM%%/*}"
160        local REMOTE_BRANCH="${UPSTREAM#*/}"
161        local MESSAGE="$(echo $*|sed 's/[^A-Za-z0-9]/_/g')"
162        echo git push $REMOTE @:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}
163        git push "$REMOTE" "@:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}"
164    }
165
166As a Git alias:
167
168    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'
169
170