blob: ffdd5da05a6467a8c0c30b85d65f739d081f81a2 [file] [log] [blame]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08001= commit-msg Hook
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -07002
David Pursehousebecc8d42013-08-08 15:06:24 +09003
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08004== NAME
David Pursehousebecc8d42013-08-08 15:06:24 +09005
6
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -07007commit-msg - Edit commit messages to insert a `Change-Id` tag.
8
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08009== DESCRIPTION
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070010
David Pursehousebecc8d42013-08-08 15:06:24 +090011
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070012A Git hook automatically invoked by `git commit`, and most other
13commit creation tools such as `git citool` or `git gui`. The Gerrit
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070014Code Review supplied implementation of this hook is a short shell
David Pursehousebecc8d42013-08-08 15:06:24 +090015script which automatically inserts a globally unique `Change-Id` tag
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070016in the footer of a commit message. When present, Gerrit uses this
17tag to track commits across cherry-picks and rebases.
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070018
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070019After the hook has been installed in the user's local Git repository
20for a project, the hook will modify a commit message such as:
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070021
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070022----
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070023 Improve foo widget by attaching a bar.
24
25 We want a bar, because it improves the foo by providing more
26 wizbangery to the dowhatimeanery.
27
28 Signed-off-by: A. U. Thor <author@example.com>
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070029----
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070030
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070031by inserting a new `Change-Id: ` line in the footer:
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070032
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070033----
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070034 Improve foo widget by attaching a bar.
35
36 We want a bar, because it improves the foo by providing more
37 wizbangery to the dowhatimeanery.
38
39 Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b
40 Signed-off-by: A. U. Thor <author@example.com>
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070041----
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070042
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070043The hook implementation is reasonably intelligent at inserting the
David Pursehousebecc8d42013-08-08 15:06:24 +090044`Change-Id` line before any `Signed-off-by` or `Acked-by` lines placed
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070045at the end of the commit message by the author, but if no such
46lines are present then it will just insert a blank line, and add
David Pursehousebecc8d42013-08-08 15:06:24 +090047the `Change-Id` at the bottom of the message.
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070048
David Pursehousebecc8d42013-08-08 15:06:24 +090049If a `Change-Id` line is already present in the message footer, the
50script will do nothing, leaving the existing `Change-Id` unmodified.
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070051This permits amending an existing commit, or allows the user to
52insert the Change-Id manually after copying it from an existing
53change viewed on the web.
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070054
David Pursehousec05da5b52013-08-08 15:09:12 +090055The `Change-Id` will not be added if `gerrit.createChangeId` is set
56to `false` in the git config.
57
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080058== OBTAINING
David Pursehousebecc8d42013-08-08 15:06:24 +090059
60
61To obtain the `commit-msg` script use `scp`, `wget` or `curl` to download
62it to your local system from your Gerrit server.
Fredrik Luthanderfb9536d2011-10-28 07:00:53 +020063
64You can use either of the below commands:
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070065
Michael Ochmannb99feab2016-07-06 14:10:22 +020066----
Fredrik Luthanderfb9536d2011-10-28 07:00:53 +020067 $ scp -p -P 29418 <your username>@<your Gerrit review server>:hooks/commit-msg <local path to your git>/.git/hooks/
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070068
Dave Borowitz572d5992013-05-10 16:17:10 +010069 $ curl -Lo <local path to your git>/.git/hooks/commit-msg <your Gerrit http URL>/tools/hooks/commit-msg
Michael Ochmannb99feab2016-07-06 14:10:22 +020070----
Fredrik Luthanderfb9536d2011-10-28 07:00:53 +020071
72A specific example of this might look something like this:
73
74.Example
Michael Ochmannb99feab2016-07-06 14:10:22 +020075----
Fredrik Luthanderfb9536d2011-10-28 07:00:53 +020076 $ scp -p -P 29418 john.doe@review.example.com:hooks/commit-msg ~/duhproject/.git/hooks/
77
Dave Borowitz572d5992013-05-10 16:17:10 +010078 $ curl -Lo ~/duhproject/.git/hooks/commit-msg http://review.example.com/tools/hooks/commit-msg
Michael Ochmannb99feab2016-07-06 14:10:22 +020079----
Shawn O. Pearce3e4e8042010-01-29 12:48:21 -080080
David Pursehouse056ed182012-08-16 10:19:14 +090081Make sure the hook file is executable:
82
Michael Ochmannb99feab2016-07-06 14:10:22 +020083----
David Pursehouse056ed182012-08-16 10:19:14 +090084 $ chmod u+x ~/duhproject/.git/hooks/commit-msg
Michael Ochmannb99feab2016-07-06 14:10:22 +020085----
David Pursehouse056ed182012-08-16 10:19:14 +090086
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080087== SEE ALSO
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070088
David Pursehousebecc8d42013-08-08 15:06:24 +090089
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070090* link:user-changeid.html[Change-Id Lines]
91* link:http://www.kernel.org/pub/software/scm/git/docs/git-commit.html[git-commit(1)]
92* link:http://www.kernel.org/pub/software/scm/git/docs/githooks.html[githooks(5)]
93
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080094== IMPLEMENTATION
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070095
David Pursehousebecc8d42013-08-08 15:06:24 +090096
97The hook generates unique `Change-Id` lines by creating a virtual
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070098commit object within the local Git repository, and obtaining the
99SHA-1 hash from it. Like any other Git commit, the following
100properties are included in the computation:
101
102* SHA-1 of the tree being committed
103* SHA-1 of the parent commit
104* Name, email address, timestamp of the author
105* Name, email address, timestamp of the committer
David Pursehousebecc8d42013-08-08 15:06:24 +0900106* Proposed commit message (before `Change-Id` was inserted)
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700107
108Because the names of the tree and parent commit, as well as the
109committer timestamp are included in the hash computation, the output
David Pursehousebecc8d42013-08-08 15:06:24 +0900110`Change-Id` is sufficiently unique.
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700111
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -0700112GERRIT
113------
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -0700114Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700115
116SEARCHBOX
117---------