Home | History | Annotate | Download | only in documentation
      1 Using Gerrit without git-cl
      2 ===========================
      3 
      4 Setup
      5 -----
      6 
      7 The following must be executed within the Skia source repository.
      8 
      9 This command sets up a Git commit-message hook to add a unique Change-Id to
     10 each commit.  Gerrit only accepts changes with a Change-Id and uses it to
     11 identify 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 
     17 If 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
     19 that there is nothing special about the string `origin` and that you could call
     20 this 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 
     25 Authentication
     26 --------------
     27 
     28 Go to [skia.googlesource.com/new-password](https://skia.googlesource.com/new-password)
     29 and follow the instructions.
     30 
     31 
     32 Creating a Change
     33 -----------------
     34 
     35 1.  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 
     43 2.  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 
     53 3.  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 
     57 4.  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 
     70 
     71 Updating a Change
     72 -----------------
     73 
     74 
     75 1.  Edit your commits more.
     76 
     77         echo BAR >> whitespace.txt
     78         git commit --all --amend
     79 
     80     Changes to the commit message will be sent with the push as well.
     81 
     82 
     83 2.  Re-squash if needed.  (Not needed if you only amended your original commit.)
     84 
     85 
     86 3.  Push to Gerrit.
     87 
     88         git push origin @:refs/for/master
     89 
     90     If you want to set a comment message for this patch set, do this instead:
     91 
     92         git push origin @:refs/for/master%m=this_is_the_patch_set_comment_message
     93 
     94     The title of this patch set will be "this is the patch set comment message".
     95 
     96 
     97 Using `git cl try`
     98 ------------------
     99 
    100 On your current branch, after uploading to gerrit:
    101 
    102     git cl issue $(experimental/tools/gerrit-change-id-to-number @)
    103 
    104 Now `git cl try` and `bin/try` will work correctly.
    105 
    106 
    107 Scripting
    108 ---------
    109 
    110 You may want to make git aliases for common tasks:
    111 
    112     git config alias.gerrit-push 'push origin @:refs/for/master'
    113 
    114 The following alias amends the head without editing the commit message:
    115 
    116     git config alias.amend-head 'commit --all --amend --reuse-message=@'
    117 
    118 Set the CL issue numnber:
    119 
    120     git config alias.setcl '!git-cl issue $(experimental/tools/gerrit-change-id-to-number @)'
    121 
    122 The following shell script will squash all commits on the current branch,
    123 assuming that the branch has an upstream topic branch.
    124 
    125     squash_git_branch() {
    126         local MESSAGE="$(git log --format=%B ^@{upstream} @)"
    127         git reset --soft $(git merge-base @ @{upstream})
    128         git commit -m "$MESSAGE" -e
    129     }
    130 
    131 This shell script pushes to gerrit and adds a message to a patchset:
    132 
    133     gerrit_push_with_message() {
    134         local REMOTE='origin'
    135         local REMOTE_BRANCH='master'
    136         local MESSAGE="$(echo $*|sed 's/[^A-Za-z0-9]/_/g')"
    137         git push "$REMOTE" "@:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}"
    138     }
    139 
    140 These shell scripts can be turned into Git aliases with a little hack:
    141 
    142     git config alias.squash-branch '!M="$(git log --format=%B ^@{u} @)";git reset --soft $(git merge-base @ @{u});git commit -m "$M" -e'
    143 
    144     git config alias.gerrit-push-message '!f(){ git push origin @:refs/for/master%m=$(echo $*|sed "s/[^A-Za-z0-9]/_/g");};f'
    145 
    146 If your branch's upstream branch (set with `git branch --set-upstream-to=...`)
    147 is set, you can use that to automatically push to that branch:
    148 
    149     gerrit_push_upstream() {
    150         local UPSTREAM_FULL="$(git rev-parse --symbolic-full-name @{upstream})"
    151         case "$UPSTREAM_FULL" in
    152             (refs/remotes/*);;
    153             (*) echo "Set your remote upstream branch."; return 2;;
    154         esac
    155         local UPSTREAM="${UPSTREAM_FULL#refs/remotes/}"
    156         local REMOTE="${UPSTREAM%%/*}"
    157         local REMOTE_BRANCH="${UPSTREAM#*/}"
    158         local MESSAGE="$(echo $*|sed 's/[^A-Za-z0-9]/_/g')"
    159         echo git push $REMOTE @:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}
    160         git push "$REMOTE" "@:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}"
    161     }
    162 
    163 As a Git alias:
    164 
    165     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'
    166 
    167