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