| Shawn O. Pearce | bb2b567 | 2009-08-21 18:33:10 -0700 | [diff] [blame] | 1 | commit-msg Hook |
| 2 | =============== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
| 6 | commit-msg - Edit commit messages to insert a `Change-Id` tag. |
| 7 | |
| 8 | DESCRIPTION |
| 9 | ----------- |
| 10 | |
| 11 | A Git hook automatically invoked by `git commit`, and most other |
| 12 | commit creation tools such as `git citool` or `git gui`. The Gerrit |
| Shawn O. Pearce | 67a09e8 | 2009-08-22 13:30:30 -0700 | [diff] [blame] | 13 | Code Review supplied implementation of this hook is a short shell |
| Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 14 | script which automatically inserts a globally unique Change-Id tag |
| 15 | in the footer of a commit message. When present, Gerrit uses this |
| 16 | tag to track commits across cherry-picks and rebases. |
| Shawn O. Pearce | bb2b567 | 2009-08-21 18:33:10 -0700 | [diff] [blame] | 17 | |
| Shawn O. Pearce | 67a09e8 | 2009-08-22 13:30:30 -0700 | [diff] [blame] | 18 | After the hook has been installed in the user's local Git repository |
| 19 | for a project, the hook will modify a commit message such as: |
| Shawn O. Pearce | bb2b567 | 2009-08-21 18:33:10 -0700 | [diff] [blame] | 20 | |
| Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 21 | ---- |
| Shawn O. Pearce | bb2b567 | 2009-08-21 18:33:10 -0700 | [diff] [blame] | 22 | Improve foo widget by attaching a bar. |
| 23 | |
| 24 | We want a bar, because it improves the foo by providing more |
| 25 | wizbangery to the dowhatimeanery. |
| 26 | |
| 27 | Signed-off-by: A. U. Thor <author@example.com> |
| Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 28 | ---- |
| Shawn O. Pearce | bb2b567 | 2009-08-21 18:33:10 -0700 | [diff] [blame] | 29 | |
| Shawn O. Pearce | 67a09e8 | 2009-08-22 13:30:30 -0700 | [diff] [blame] | 30 | by inserting a new `Change-Id: ` line in the footer: |
| Shawn O. Pearce | bb2b567 | 2009-08-21 18:33:10 -0700 | [diff] [blame] | 31 | |
| Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 32 | ---- |
| Shawn O. Pearce | bb2b567 | 2009-08-21 18:33:10 -0700 | [diff] [blame] | 33 | Improve foo widget by attaching a bar. |
| 34 | |
| 35 | We want a bar, because it improves the foo by providing more |
| 36 | wizbangery to the dowhatimeanery. |
| 37 | |
| 38 | Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b |
| 39 | Signed-off-by: A. U. Thor <author@example.com> |
| Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 40 | ---- |
| Shawn O. Pearce | bb2b567 | 2009-08-21 18:33:10 -0700 | [diff] [blame] | 41 | |
| Shawn O. Pearce | 67a09e8 | 2009-08-22 13:30:30 -0700 | [diff] [blame] | 42 | The hook implementation is reasonably intelligent at inserting the |
| 43 | Change-Id line before any Signed-off-by or Acked-by lines placed |
| 44 | at the end of the commit message by the author, but if no such |
| 45 | lines are present then it will just insert a blank line, and add |
| 46 | the Change-Id at the bottom of the message. |
| 47 | |
| 48 | If a Change-Id line is already present in the message footer, the |
| 49 | script will do nothing, leaving the existing Change-Id unmodified. |
| 50 | This permits amending an existing commit, or allows the user to |
| 51 | insert the Change-Id manually after copying it from an existing |
| 52 | change viewed on the web. |
| Shawn O. Pearce | bb2b567 | 2009-08-21 18:33:10 -0700 | [diff] [blame] | 53 | |
| 54 | OBTAINING |
| 55 | --------- |
| Fredrik Luthander | fb9536d | 2011-10-28 07:00:53 +0200 | [diff] [blame] | 56 | To obtain the 'commit-msg' script use scp, wget or curl to download it |
| David Pursehouse | 221d4f6 | 2012-06-08 17:38:08 +0900 | [diff] [blame] | 57 | to your local system from your Gerrit server. |
| Fredrik Luthander | fb9536d | 2011-10-28 07:00:53 +0200 | [diff] [blame] | 58 | |
| 59 | You can use either of the below commands: |
| Shawn O. Pearce | bb2b567 | 2009-08-21 18:33:10 -0700 | [diff] [blame] | 60 | |
| Shawn O. Pearce | 4776924 | 2011-06-14 16:40:48 -0700 | [diff] [blame] | 61 | ==== |
| Fredrik Luthander | fb9536d | 2011-10-28 07:00:53 +0200 | [diff] [blame] | 62 | $ scp -p -P 29418 <your username>@<your Gerrit review server>:hooks/commit-msg <local path to your git>/.git/hooks/ |
| Shawn O. Pearce | bb2b567 | 2009-08-21 18:33:10 -0700 | [diff] [blame] | 63 | |
| Fredrik Luthander | fb9536d | 2011-10-28 07:00:53 +0200 | [diff] [blame] | 64 | $ curl -o <local path to your git>/.git/hooks/commit-msg <your Gerrit http URL>/tools/hooks/commit-msg |
| 65 | ==== |
| 66 | |
| 67 | A specific example of this might look something like this: |
| 68 | |
| 69 | .Example |
| 70 | ==== |
| 71 | $ scp -p -P 29418 john.doe@review.example.com:hooks/commit-msg ~/duhproject/.git/hooks/ |
| 72 | |
| 73 | $ curl -o ~/duhproject/.git/hooks/commit-msg http://review.example.com/tools/hooks/commit-msg |
| Shawn O. Pearce | 4776924 | 2011-06-14 16:40:48 -0700 | [diff] [blame] | 74 | ==== |
| Shawn O. Pearce | 3e4e804 | 2010-01-29 12:48:21 -0800 | [diff] [blame] | 75 | |
| David Pursehouse | 056ed18 | 2012-08-16 10:19:14 +0900 | [diff] [blame^] | 76 | Make sure the hook file is executable: |
| 77 | |
| 78 | ==== |
| 79 | $ chmod u+x ~/duhproject/.git/hooks/commit-msg |
| 80 | ==== |
| 81 | |
| Shawn O. Pearce | 518fe3f | 2009-08-22 15:40:58 -0700 | [diff] [blame] | 82 | SEE ALSO |
| 83 | -------- |
| 84 | |
| 85 | * link:user-changeid.html[Change-Id Lines] |
| 86 | * link:http://www.kernel.org/pub/software/scm/git/docs/git-commit.html[git-commit(1)] |
| 87 | * link:http://www.kernel.org/pub/software/scm/git/docs/githooks.html[githooks(5)] |
| 88 | |
| 89 | IMPLEMENTATION |
| 90 | -------------- |
| 91 | |
| 92 | The hook generates unique Change-Id lines by creating a virtual |
| 93 | commit object within the local Git repository, and obtaining the |
| 94 | SHA-1 hash from it. Like any other Git commit, the following |
| 95 | properties are included in the computation: |
| 96 | |
| 97 | * SHA-1 of the tree being committed |
| 98 | * SHA-1 of the parent commit |
| 99 | * Name, email address, timestamp of the author |
| 100 | * Name, email address, timestamp of the committer |
| 101 | * Proposed commit message (before Change-Id was inserted) |
| 102 | |
| 103 | Because the names of the tree and parent commit, as well as the |
| 104 | committer timestamp are included in the hash computation, the output |
| 105 | Change-Id is sufficiently unique. |
| 106 | |
| Shawn O. Pearce | bb2b567 | 2009-08-21 18:33:10 -0700 | [diff] [blame] | 107 | GERRIT |
| 108 | ------ |
| 109 | Part of link:index.html[Gerrit Code Review] |