2017-01-27 18:33:55 +00:00
|
|
|
Using Gerrit without git-cl
|
|
|
|
===========================
|
|
|
|
|
2017-10-13 19:53:29 +00:00
|
|
|
Setup
|
2017-01-27 18:33:55 +00:00
|
|
|
-----
|
|
|
|
|
2017-01-30 18:18:43 +00:00
|
|
|
The following must be executed within the Skia source repository.
|
2017-01-27 18:33:55 +00:00
|
|
|
|
2017-01-30 18:18:43 +00:00
|
|
|
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.
|
2017-01-30 17:50:18 +00:00
|
|
|
|
2019-07-10 16:28:23 +00:00
|
|
|
experimental/tools/set-change-id-hook
|
2017-01-30 18:18:43 +00:00
|
|
|
|
2017-10-13 19:53:29 +00:00
|
|
|
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
|
2017-01-30 18:18:43 +00:00
|
|
|
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'
|
2017-01-27 18:33:55 +00:00
|
|
|
|
|
|
|
|
2017-10-13 19:53:29 +00:00
|
|
|
Authentication
|
|
|
|
--------------
|
|
|
|
|
|
|
|
Go to [skia.googlesource.com/new-password](https://skia.googlesource.com/new-password)
|
|
|
|
and follow the instructions.
|
|
|
|
|
|
|
|
|
|
|
|
Creating a Change
|
2017-01-27 18:33:55 +00:00
|
|
|
-----------------
|
|
|
|
|
|
|
|
1. Create a topic branch
|
|
|
|
|
2017-01-30 18:18:43 +00:00
|
|
|
git checkout -b TOPIC
|
|
|
|
|
|
|
|
You may want to set a tracking branch at this time with:
|
|
|
|
|
2017-01-27 18:33:55 +00:00
|
|
|
git checkout -b TOPIC -t origin/master
|
|
|
|
|
2017-01-30 18:18:43 +00:00
|
|
|
2. Make a commit.
|
2017-01-27 18:33:55 +00:00
|
|
|
|
2017-01-30 18:18:43 +00:00
|
|
|
echo FOO >> whitespace.txt
|
|
|
|
git commit --all --message 'Change Foo'
|
|
|
|
git log -1
|
2017-01-27 18:33:55 +00:00
|
|
|
|
2017-01-30 18:18:43 +00:00
|
|
|
`git log` should show that a Change-Id line has been added you your commit
|
|
|
|
message.
|
2017-01-27 18:33:55 +00:00
|
|
|
|
2017-01-30 17:27:14 +00:00
|
|
|
|
2017-01-30 18:18:43 +00:00
|
|
|
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.
|
2017-01-27 18:33:55 +00:00
|
|
|
|
|
|
|
4. Push to Gerrit
|
|
|
|
|
2017-01-30 18:18:43 +00:00
|
|
|
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)
|
2017-01-27 18:33:55 +00:00
|
|
|
|
2018-12-05 16:08:12 +00:00
|
|
|
5. Open in web browser:
|
|
|
|
|
2018-12-05 16:58:05 +00:00
|
|
|
bin/sysopen https://skia-review.googlesource.com/c/skia/+/$(bin/gerrit-number @)
|
2017-01-27 18:33:55 +00:00
|
|
|
|
2017-10-13 19:53:29 +00:00
|
|
|
Updating a Change
|
2017-01-27 18:33:55 +00:00
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
|
|
1. Edit your commits more.
|
|
|
|
|
2017-01-30 18:18:43 +00:00
|
|
|
echo BAR >> whitespace.txt
|
|
|
|
git commit --all --amend
|
|
|
|
|
|
|
|
Changes to the commit message will be sent with the push as well.
|
|
|
|
|
2017-01-30 17:27:14 +00:00
|
|
|
|
|
|
|
2. Re-squash if needed. (Not needed if you only amended your original commit.)
|
|
|
|
|
2017-01-27 18:33:55 +00:00
|
|
|
|
2017-01-30 17:27:14 +00:00
|
|
|
3. Push to Gerrit.
|
2017-01-27 18:33:55 +00:00
|
|
|
|
2017-01-30 18:18:43 +00:00
|
|
|
git push origin @:refs/for/master
|
|
|
|
|
|
|
|
If you want to set a comment message for this patch set, do this instead:
|
|
|
|
|
2019-08-01 15:52:05 +00:00
|
|
|
M=$(experimental/tools/gerrit_percent_encode 'This is the patch set comment message!')
|
|
|
|
git push origin @:refs/for/master%m=$M
|
2017-01-30 18:18:43 +00:00
|
|
|
|
2019-08-01 15:52:05 +00:00
|
|
|
The title of this patch set will be "This is the patch set comment message!".
|
|
|
|
|
|
|
|
|
|
|
|
Triggering Commit-Queue Dry Run when you upload a patch
|
|
|
|
-------------------------------------------------------
|
|
|
|
|
|
|
|
M=$(experimental/tools/gerrit_percent_encode 'This is the patch set comment message!')
|
|
|
|
git push origin @:refs/for/master%l=Commit-Queue+1,m=$M
|
2017-01-30 18:18:43 +00:00
|
|
|
|
|
|
|
|
2017-12-18 17:01:18 +00:00
|
|
|
Using `git cl try`
|
|
|
|
------------------
|
|
|
|
|
|
|
|
On your current branch, after uploading to gerrit:
|
|
|
|
|
2018-12-05 16:08:12 +00:00
|
|
|
git cl issue $(bin/gerrit-number @)
|
2017-12-18 17:01:18 +00:00
|
|
|
|
|
|
|
Now `git cl try` and `bin/try` will work correctly.
|
|
|
|
|
|
|
|
|
2017-10-13 19:53:29 +00:00
|
|
|
Scripting
|
2017-01-30 18:18:43 +00:00
|
|
|
---------
|
|
|
|
|
|
|
|
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=@'
|
|
|
|
|
2017-12-18 17:01:18 +00:00
|
|
|
Set the CL issue numnber:
|
|
|
|
|
2018-12-05 16:08:12 +00:00
|
|
|
git config alias.setcl '!git-cl issue $(bin/gerrit-number @)'
|
2017-12-18 17:01:18 +00:00
|
|
|
|
2017-01-30 18:18:43 +00:00
|
|
|
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'
|
2017-01-27 18:33:55 +00:00
|
|
|
|
2017-01-30 18:18:43 +00:00
|
|
|
git config alias.gerrit-push-message '!f(){ git push origin @:refs/for/master%m=$(echo $*|sed "s/[^A-Za-z0-9]/_/g");};f'
|
2017-01-27 18:33:55 +00:00
|
|
|
|
2017-05-15 20:16:42 +00:00
|
|
|
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() {
|
2017-07-02 16:38:45 +00:00
|
|
|
local UPSTREAM_FULL="$(git rev-parse --symbolic-full-name @{upstream})"
|
|
|
|
case "$UPSTREAM_FULL" in
|
2017-07-03 02:05:59 +00:00
|
|
|
(refs/remotes/*);;
|
2017-07-02 16:38:45 +00:00
|
|
|
(*) echo "Set your remote upstream branch."; return 2;;
|
|
|
|
esac
|
|
|
|
local UPSTREAM="${UPSTREAM_FULL#refs/remotes/}"
|
2017-05-15 20:16:42 +00:00
|
|
|
local REMOTE="${UPSTREAM%%/*}"
|
|
|
|
local REMOTE_BRANCH="${UPSTREAM#*/}"
|
|
|
|
local MESSAGE="$(echo $*|sed 's/[^A-Za-z0-9]/_/g')"
|
2017-07-03 02:05:59 +00:00
|
|
|
echo git push $REMOTE @:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}
|
2017-05-15 20:16:42 +00:00
|
|
|
git push "$REMOTE" "@:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}"
|
|
|
|
}
|
|
|
|
|
|
|
|
As a Git alias:
|
|
|
|
|
2017-07-02 16:38:45 +00:00
|
|
|
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'
|
2017-01-27 18:33:55 +00:00
|
|
|
|