missing Change-Id in commit message footer for git-review

梦想与她 提交于 2019-12-06 15:36:31

I'd be tempted to suggest that the commit hook is not installed properly. Also, I would suggest removing git review from the equation until you can get a git commit --amend working on it's own (working in this case means that the change-id appears in the commit message after an amend commit).

Here is how to troubleshoot the commit message hook: (I noticed that a lot of the below assumes that the commit-msg hook script is a shell script. Let me know if this assumption is incorrect)

Level 1 : The basics

  1. Check that the commit message hook is installed where you expect it to be: $ ls -la .git/hooks/commit-msg -rwxr-xr-x 1 az staff 4407 15 Nov 19:00 .git/hooks/commit-msg
    Notice the non-zero size of the commit message hook as well as the fact that ('-rwx') script is executable.

  2. Try executing the commit-msg script on it's own by doing .git/hooks/commit-msg. This should fail with a : sed: : No such file or directory
    which is ok and expected since the hook script assumes that it is being run by git and not standalone. Keep calm and carry on.

  3. Add the following at the top of .git/hooks/commit-msg (just before unset GREP_OPTIONS):
    echo "Executingbasename "$0"with args: $@"

  4. Now try doing a git commit --amend, for me the output with a correctly installed hook was as follows:
    $ git commit -m "Test commit-msg hook" Executing commit-msg with args: .git/COMMIT_EDITMSG

If you don't see the expected output as posted above in any of the steps then your hook script was not installed properly. You can manually scp the hook script over to .git/hooks directory and check that it is executable by the correct user (the former is what git command in your output does).

Level 2: Asking GIT to be a bit more verbose

GIT will reveal a bit more if you only ask it nicely. Notice that this also shows the hook script being executed:

$ GIT_CURL_VERBOSE=1 GIT_TRACE=2 git commit --amend 19:13:26.836236 git.c:349 trace: built-in: git 'commit' '--amend' 19:13:27.025894 run-command.c:336 trace: run_command: '/usr/bin/vim' '/Users/some-git-dir/.git/COMMIT_EDITMSG' 19:13:27.026454 run-command.c:195 trace: exec: '/usr/bin/vim' '/Users/some-git-dir/.git/COMMIT_EDITMSG' 19:13:28.497117 run-command.c:336 trace: run_command: '.git/hooks/commit-msg' '.git/COMMIT_EDITMSG' Executing commit-msg with args: .git/COMMIT_EDITMSG 19:13:28.504150 git.c:349 trace: built-in: git 'stripspace' 19:13:28.507498 git.c:349 trace: built-in: git 'config' '--bool' '--get' 'gerrit.createChangeId' [some-branch-blah 1f205cb] Test commit-msg hook Date: Tue Nov 15 19:00:59 2016 +0000 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 a

Level 3: Debugging hook like a shell script

I doubt that it is the script itself which needs to be looked at, however if that turns out to be the case, then the next step is to do what you normally would to debug shell scripts (since that is what the default commit-msg hook is).

I would start by changing the she-bang line from #!/bin/sh to #!/bin/sh -xv and then revel in the uber-verbose output as the script is executed when you do a git commit --amend

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!