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 aquired Skia from a mirror (such as github), you need to change the
     18 `origin` remote to point to point to googlesource.  Advanvced 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 creating a change
     26 -----------------
     27 
     28 1.  Create a topic branch
     29 
     30         git checkout -b TOPIC
     31 
     32     You may want to set a tracking branch at this time with:
     33 
     34         git checkout -b TOPIC -t origin/master
     35 
     36 2.  Make a commit.
     37 
     38         echo FOO >> whitespace.txt
     39         git commit --all --message 'Change Foo'
     40         git log -1
     41 
     42     `git log` should show that a Change-Id line has been added you your commit
     43     message.
     44 
     45 
     46 3.  If You have multiple commits in your branch, Gerrit will think you want
     47     multiple changes that depend on each other.  If this is not what you want,
     48     you need to squash the commits.
     49 
     50 4.  Push to Gerrit
     51 
     52         git push origin @:refs/for/master
     53 
     54     `@` is shorthand for `HEAD`, introduced in git v1.8.5.
     55 
     56     If you want to target a branch other than `master`, that can be specified
     57     here, too.  For example:
     58 
     59         git push origin @:refs/for/chrome/m57
     60 
     61     [Gerrit Upload Documentation](https://gerrit-review.googlesource.com/Documentation/user-upload.html)
     62 
     63 
     64 updating a change
     65 -----------------
     66 
     67 
     68 1.  Edit your commits more.
     69 
     70         echo BAR >> whitespace.txt
     71         git commit --all --amend
     72 
     73     Changes to the commit message will be sent with the push as well.
     74 
     75 
     76 2.  Re-squash if needed.  (Not needed if you only amended your original commit.)
     77 
     78 
     79 3.  Push to Gerrit.
     80 
     81         git push origin @:refs/for/master
     82 
     83     If you want to set a comment message for this patch set, do this instead:
     84 
     85         git push origin @:refs/for/master%m=this_is_the_patch_set_comment_message
     86 
     87     The title of this patch set will be "this is the patch set comment message".
     88 
     89 
     90 scripting
     91 ---------
     92 
     93 You may want to make git aliases for common tasks:
     94 
     95     git config alias.gerrit-push 'push origin @:refs/for/master'
     96 
     97 The following alias amends the head without editing the commit message:
     98 
     99     git config alias.amend-head 'commit --all --amend --reuse-message=@'
    100 
    101 The following shell script will squash all commits on the current branch,
    102 assuming that the branch has an upstream topic branch.
    103 
    104     squash_git_branch() {
    105         local MESSAGE="$(git log --format=%B ^@{upstream} @)"
    106         git reset --soft $(git merge-base @ @{upstream})
    107         git commit -m "$MESSAGE" -e
    108     }
    109 
    110 This shell script pushes to gerrit and adds a message to a patchset:
    111 
    112     gerrit_push_with_message() {
    113         local REMOTE='origin'
    114         local REMOTE_BRANCH='master'
    115         local MESSAGE="$(echo $*|sed 's/[^A-Za-z0-9]/_/g')"
    116         git push "$REMOTE" "@:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}"
    117     }
    118 
    119 These shell scripts can be turned into Git aliases with a little hack:
    120 
    121     git config alias.squash-branch '!M="$(git log --format=%B ^@{u} @)";git reset --soft $(git merge-base @ @{u});git commit -m "$M" -e'
    122 
    123     git config alias.gerrit-push-message '!f(){ git push origin @:refs/for/master%m=$(echo $*|sed "s/[^A-Za-z0-9]/_/g");};f'
    124 
    125 If your branch's upstream branch (set with `git branch --set-upstream-to=...`)
    126 is set, you can use that to automatically push to that branch:
    127 
    128     gerrit_push_upstream() {
    129         local UPSTREAM_FULL="$(git rev-parse --symbolic-full-name @{upstream})"
    130         case "$UPSTREAM_FULL" in
    131             (refs/remotes/*);;
    132             (*) echo "Set your remote upstream branch."; return 2;;
    133         esac
    134         local UPSTREAM="${UPSTREAM_FULL#refs/remotes/}"
    135         local REMOTE="${UPSTREAM%%/*}"
    136         local REMOTE_BRANCH="${UPSTREAM#*/}"
    137         local MESSAGE="$(echo $*|sed 's/[^A-Za-z0-9]/_/g')"
    138         echo git push $REMOTE @:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}
    139         git push "$REMOTE" "@:refs/for/${REMOTE_BRANCH}%m=${MESSAGE}"
    140     }
    141 
    142 As a Git alias:
    143 
    144     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'
    145 
    146