aboutsummaryrefslogtreecommitdiff
path: root/git-codereview/hook.go
AgeCommit message (Collapse)Author
6 daysgit-codereview: support remote other than "origin"HEADmainShulhan
For the git-codereview commands to works on any Go's repositories, the remote name for "origin" must be pointed to the Go original repository URL (in most cases the one with go.googlesource.com domain). The problem is when the "origin" is from the fork, all of the git-codereview commands then will not works. For example, in computer X, I clone the this repository from "https://go.googlesource.com/review" (the origin) and then push my changes on "git@git.sr.ht:~shulhan/go-x-review" (the fork). In another computer Y, I then clone from the fork to continue my works. The fork become origin. One of the solution is to rename the remote names manually each time we clone the fork. The only cons using this solution is every time new branch created we need to remember to pass "--set-upstream" during git push. This changes introduce "remote" configuration in codereview.cfg. When one first working on fork of Go repository, they set the "remote" key, commit it, and push it. When they cloned the fork, they did not needs to changes anything except adding new remote using the pre-defined name. Change-Id: I335d08fd8b7efe17ba07b3c0a3794f9ccf59b339
2025-06-17git-codereview: explicitly include the codereview subcommand in suggested ↵Adam Bender
commands If a user does not have the recommended aliases in their .gitconfig, the suggested command will not work. Several suggestions have the codereview subcommand already; this change updates all suggestions to include it. Change-Id: I3613f24172c2d90a7038f263cad93cbdcddbbbca Reviewed-on: https://go-review.googlesource.com/c/review/+/681176 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: Sean Liao <sean@liao.dev> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Sean Liao <sean@liao.dev>
2025-04-11git-codereview: do not write hooks if -n is givenv1.15.0Anatoli Babenia
Fixes golang/go#73314 Change-Id: I881c2ae97f72990a6daac4919687f85cb24ac076 Reviewed-on: https://go-review.googlesource.com/c/review/+/664555 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org>
2024-01-25git-codereview: remove usage of io/ioutilv1.9.0Joshua Sing
io/ioutil is now deprecated. Use non-deprecated equivalents. Change-Id: Iad1cc9c14dbdad3a6f9ada25072bc194bace4081 Reviewed-on: https://go-review.googlesource.com/c/review/+/543615 Reviewed-by: qiulaidongfeng <2645477756@qq.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-10-18git-codereview: make hooks command report conflicting hooksv1.8.0siddharth ravikumar
Display warning message when a hook is already installed and is different from the one installed by git-codereview. Improves upon CL 184417. Fixes golang/go#16777 Change-Id: I7579a3e86572e8b74f92317973e7cc7094b3942d Reviewed-on: https://go-review.googlesource.com/c/review/+/377034 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2021-09-21git-codereview: reword: apply commit message hook to editsRuss Cox
If you run "git codereview reword" you should get the same "Fixes" fixing and Change-Id insertion as with regular commit message editing. Change-Id: I77220d42b49f575c07a7c1ef786c3775ee75133c Reviewed-on: https://go-review.googlesource.com/c/review/+/295310 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-01-15git-codereview: fix buglet in 'reword' related to work treesThan McIntosh
The reword command was trying to store a saved messages file in the subdirectory .git in the repo root; this doesn't work well if multiple work trees are in use and the user is working in a non-main work tree. Use "git rev-parse --git-path ." instead of "git rev-parse --show-top-level" to find the location for the saved messages file. Fixes golang/go#43695. Change-Id: Ie0b3e810ad585fe1c18805f4070736335a2ef2b5 Reviewed-on: https://go-review.googlesource.com/c/review/+/283646 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Trust: Than McIntosh <thanm@google.com>
2021-01-07git-codereview: allow work on main branchesRuss Cox
The only reason not to allow work on branches named for the origin branches is to preserve them for "git change main; git change new" to make a new branch tracking main. But we can still do that and allow commits on main - we just have to use the branchpoint as the root of the new branch. Now people can work on "main" (or "dev.regabi") if that suits them. In particular, if you're doing merges, it's nice to be on "dev.regabi" and know for sure that's the branch you're working on. Change-Id: I8e9458793c30857a5c00e6bfd4f1cb41adbbe637 Reviewed-on: https://go-review.googlesource.com/c/review/+/279874 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Austin Clements <austin@google.com>
2019-03-25git-codereview: make commit-msg hook play nicely with other systemsAndrew Gerrand
Gerrit requires 'Change-Id:' lines to be included in each commit message, but they are not the only kind of 'metadata line' that might appear in a commit message. Metadata lines observed by other systems include 'Bug:' and 'Signed-off-by:'. This change ensures that the commit-msg hook adds its 'Change-Id:' line to the set of metadata lines, separated only by a single linefeed, rather than creating a new set by inserting two line feeds. Change-Id: Ia3bdce6f52f663685eea1e648874ef81ddb2bd91 Reviewed-on: https://go-review.googlesource.com/c/review/+/169097 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-07-17git-codereview: create hooks directory if it doesn't existMarko Mudrinic
Fixes golang/go#21028 On some versions of Git, "git init" will not create ".git/hooks directory", causing "git change" to fail. This fix will check if the hooks directory exists, and if not, create it. Change-Id: I6a9e688740fde8701e5d48630686039c8ebf4172 Reviewed-on: https://go-review.googlesource.com/49070 Reviewed-by: Kevin Burke <kev@inburke.com>
2017-03-09git-codereview: fix hook installation in git 2.13.0Austin Clements
git 2.13.0 changed the behavior of git rev-parse --git-path from printing a path relative to the repo root to printing a path relative to the working directory. This breaks git-codereview's hook installation when a git-codereview command is invoked from a directory other than the repo root, since it will try to resolve this path as relative to the repo root. Fix this by running git rev-parse from the repo root, so it behaves the same either way. Fixes golang/go#19477. Change-Id: Ia5e1b81da5041365d817daf9f5979df0772ede4b Reviewed-on: https://go-review.googlesource.com/38010 Reviewed-by: Russ Cox <rsc@golang.org>
2016-08-01git-codereview: fix commitmsg hook when verboseDaniel Martí
If the commit message is verbose it shows the diff being committed. This can be shown by either `git commit --verbose` or setting the following in your git config: [commit] verbose = true The diff is uncomented and shown after a "everything below will be removed" comment section. Identify it and do remove everything under it, as otherwise the diff would get mixed up with the commit message. Fixes golang/go#16376. Change-Id: Ia69aeaf36a1c8471da423a142fb233168d455a5d Reviewed-on: https://go-review.googlesource.com/25342 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2016-07-11git-codereview: add [branchname] when on release branchAndrew Gerrand
This behavior was changed by 2865802. Change-Id: Ib5a254240d4e8a8254ce52929ed1ec2165d545e2 Reviewed-on: https://go-review.googlesource.com/24756 Reviewed-by: Chris Broadfoot <cbro@golang.org>
2016-06-14git-codereview: pass args to installHookJosh Bleecher Snyder
This enables passing -v to 'git codereview hooks' to see what commands are being run. It also means that automatic installation of hooks should respect -n. Change-Id: I812685b43e9ea678641f64b2182b957342a4e43c Reviewed-on: https://go-review.googlesource.com/24002 Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-03-02git-codereview: fix hooks install when using 'git worktree'Caio Marcelo de Oliveira Filho
Use 'git rev-parse' to obtain the repo root (toplevel) and the hooks directory (git-path hooks). Git knows better how to handle more complex scenarios, e.g. in a linked worktree (created using "git worktree add"), ".git" is not a directory but a regular file, that contains the path to the linked gitdir, that then contains the path to the main gitdir. The hooks should be there. For older version git versions without --git-path (and without worktree), fallback to the previous approach. Updates golang/go#12182. Change-Id: I7a90362409fc5000282db95c4ec2ab5052ae59a8 Reviewed-on: https://go-review.googlesource.com/19882 Run-TryBot: Andrew Gerrand <adg@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-02-18git-codereview: disable Gerrit-specific hook behavior if Gerrit is not in useRuss Cox
Every time I accidentally type 'git pending' in a non-Gerrit repository, that command installs hooks, and then I have to zero the hook files to keep working. First, don't install the hooks if this looks like a non-Gerrit git repo. That seems like it will play well with others. But, people might also want to use the non-Gerrit parts of the tool, so if people do say 'git codereview hooks', let that install them. And then if the hooks are invoked in a non-Gerrit repo, selectively disable the Gerrit-specific parts. For example, if it's not a Gerrit repo we might still want to check and fix 'Fixes #N' lines if directed by the config, but we don't want to add Change-Id lines. Now that things are a bit better behaved, also leave the hooks on in detached head mode. I've found that it's quite frustrating not to have the hooks on when working midway through git rebase -i. If we find reasons that the hooks were off we can try to figure out how to split the difference. Fixes golang/go#12170. Change-Id: I69fa156ce4fd11c0c84416088cd972957ce1ce6d Reviewed-on: https://go-review.googlesource.com/19560 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Austin Clements <austin@google.com>
2015-10-19git-codereview: Properly detect Rietveld-style fix messagesMichael Darakananda
Detection of Rietveld-style fix messages is already in place as a warning, but was broken when we added feature to rewrite issue references in commit edbdf1a7 . To fix this, we automatically reformat the fix message into the GitHub style. We also forget to write the change to the fix message back, if we do not also need to write Change-Id and origin branch. This change also fixes this. Fixes golang/go#11472 Change-Id: Ie77358867e38cf976a0688b6e2f80525dae3891e Reviewed-on: https://go-review.googlesource.com/15754 Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-04-09git-codereview: reject commits with multiple Change-Id linesJosh Bleecher Snyder
This should help prevent the situation in CL 8653. Change-Id: I03e4868656a86e69e11f3e0545feb1681fb0f628 Reviewed-on: https://go-review.googlesource.com/8671 Reviewed-by: Minux Ma <minux@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2015-03-18git-codereview: rewrite issue referencesJosh Bleecher Snyder
We have a single repo against which all issues are filed. GitHub supports closing issues in other repos, but it is easy to forget to use the magic syntax. To fix that, rewrite issue references in the commit msg hook. To that end, introduce a repo-level config file, located at REPOROOT/codereview.cfg. The config is always read from origin/master. Config lines are of the form "key: value". Lines beginning with # are comments. To designate a repo as the issues repo, add issuerepo: USERNAME/REPO to the config. Fixes golang/go#9273. Change-Id: I31ec98883641bbf0c149f3619769231f6a452512 Reviewed-on: https://go-review.googlesource.com/4131 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2015-02-23git-codereview: do not insert branch prefix in fixup! and squash! commitsRuss Cox
Change-Id: I0fc5df1e23cf18a78aa0339ac16901214d7924e4 Reviewed-on: https://go-review.googlesource.com/5552 Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-02-07git-codereview: ensure blank line after subjectJosh Bleecher Snyder
Fixes golang/go#9522 Change-Id: Ic06feda22711fe320a789957620af98f38f1df8f Reviewed-on: https://go-review.googlesource.com/4130 Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-01-30git-codereview: use cmd prefix on command implementation funcsRuss Cox
The name space is getting a bit crowded. These words are too easy to use for other variables or functions. Change-Id: Iedbccb82f85627fe422a029a6b45ad39a2e18dd0 Reviewed-on: https://go-review.googlesource.com/3627 Reviewed-by: Rob Pike <r@golang.org>
2015-01-14git-codereview: disable gofmt hook when $GIT_GOFMT_HOOK=offRuss Cox
Change-Id: I9b0b178188a8095af14445f90a16dc32050556f5 Reviewed-on: https://go-review.googlesource.com/2784 Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-01-14git-codereview: add [serverbranch] prefix for work on non-master server branchesRuss Cox
For example this will add [dev.cc] to the work on the dev.cc (C to Go conversion) branch, and it will add [release-branch.go1.4] to the upcoming 1.4.1 cherry-pick CLs. Change-Id: I59fff85ced61453796b52c738a47ea1fc4a5bf36 Reviewed-on: https://go-review.googlesource.com/2782 Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-23git-codereview: fix a few corner case failuresRuss Cox
- make it clearer what the random git command at the end of failures means - avoid some problems with detached HEAD mode in hooks run during git rebase - redirect all stdout/stderr into test buffers Change-Id: I102f22fc870f69c884728eaa46ecc95792d5b795 Reviewed-on: https://go-review.googlesource.com/2011 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2014-12-18git-codereview: rename from 'git-review' to 'git-codereview'Andrew Gerrand
Mostly trivial search and replace, except for hooks.go which includes a special case to remove the old git-review hooks. Change-Id: Ic0792bb3e26607e5e0ead88958e46c3ac08288cd Reviewed-on: https://go-review.googlesource.com/1741 Reviewed-by: Russ Cox <rsc@golang.org>