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

喜夏-厌秋 提交于 2019-12-23 02:21:33

问题


I've cloned an empty repository from Gerrit. I've created a new branch called "new_files" and pulled an upstream into it. When I'm trying to run git-review, I get such an error:

The outstanding commits are:

6d5d8ac (HEAD, new_files) Change-Id: If528f4dd29638e8c2a8d18a624a289afe390e6e2
cc81223 Merge branch 'master' of UPSTREAM into new_files
d787290 (upstream/master) rename properties to dat
32d76cf rename properties to dat
73d8e05 rename data to properties
e46416e Add file.
8bfcab5 referencing properties
e8b03fc rename data

Do you really want to submit the above commits?
Type 'yes' to confirm, other to cancel: yes
2016-11-15 12:09:54.407178 Running: git branch --color=never
2016-11-15 12:09:54.411090 Running: git log HEAD^1..HEAD
Using local branch name "new_files" for the topic of the change submitted
2016-11-15 12:09:54.416984 Running: git push gerrit HEAD:refs/publish/master/new_files
remote: Processing changes: refs: 1, done
remote: ERROR: missing Change-Id in commit message footer
remote:
remote: Hint: To automatically insert Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 user@:hooks/commit-msg ${gitdir}/hooks/
remote: And then amend the commit:
remote:   git commit --amend
remote:
To ssh://
 ! [remote rejected] HEAD -> refs/publish/master/new_files (missing Change-Id in commit message footer)
error: failed to push some refs to 'ssh://'
2016-11-15 12:09:54.655379 Running: git rev-parse --show-toplevel --git-dir

I tried to install the hook and to use amend but it makes no difference.


回答1:


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



来源:https://stackoverflow.com/questions/40609744/missing-change-id-in-commit-message-footer-for-git-review

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