yor: Unable to fetch git blame info on specific files
@nimrodkor Most of my git tagging issues have been resolved after #147, however it seems like one of the files in the sub-dir I tested this on was still unable to fetch git blame info:
2021/06/18 09:01:16 [WARNING] Unable to get git blame for file envs/cetus/receipts/receipts.tf: failed to get blame for latest commit of file envs/cetus/receipts/receipts.tf because of error contents and commits have different length
2021/06/18 09:01:29 [WARNING] Failed to tag receipts_bucket with git tags, err: failed to get blame for latest commit of file envs/cetus/receipts/receipts.tf because of error failed to get blame for latest commit of file envs/cetus/receipts/receipts.tf because of error contents and commits have different length
You can see that one of the resources was only tagged with yor_trace
:
New Resources Traced (4):
+------------------------------------------+--------------------------------+----------------------+------------------------------------------+--------------------------------------+
| FILE | RESOURCE | TAG KEY | TAG VALUE | YOR ID |
+------------------------------------------+--------------------------------+----------------------+------------------------------------------+--------------------------------------+
| envs/cetus/receipts/receipts.tf | receipts_bucket | yor_trace | 0a4a88ef-f713-4f9f-8e50-effadb1422b4 | 0a4a88ef-f713-4f9f-8e50-effadb1422b4 |
+ + +----------------------+------------------------------------------+ +
| | | yor_trace | 0a4a88ef-f713-4f9f-8e50-effadb1422b4 | |
+------------------------------------------+--------------------------------+----------------------+------------------------------------------+--------------------------------------+
| envs/cetus/receipts/secretsmgr.tf | aws_iam_policy.secrets_manager | yor_trace | 0b7c9745-0ded-438b-8b59-7876b1b4e712 | 0b7c9745-0ded-438b-8b59-7876b1b4e712 |
+ + +----------------------+------------------------------------------+ +
| | | git_org | waveaccounting | |
+ + +----------------------+------------------------------------------+ +
| | | git_repo | keller | |
+ + +----------------------+------------------------------------------+ +
Not sure what error contents and commits have different length
means. From slack:
It seems like we’re not handling git correctly for merge commits
_Originally posted by @mwarkentin in https://github.com/bridgecrewio/yor/issues/147#issuecomment-864037339_
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 30 (15 by maintainers)
Hi @gustavoortega,
go-git
has a working pr which could solve this issue once and for all, please stay tuned.Seems to be also related/duplicated by below issues:
For me it also fails as described above in both cases: a) when running on merge request and b) when running after the merge request on master. I am using GitLab.
Below is job configuration I am using
Here is my CI output:
Should stay open. The mentioned PR has been merged a couple of days ago.
I’m debugging the very same issue. It looks like a
go-git
bug.The
contents and commits have different length
error was caused by the file has different line count than the blame informations.In
go-git
:The
b.fillRevs()
loaded the commits that contain the file, and sort these commits by time:In
fillRevs()
it calledreferences()
to read the commits:You would find that
result
wouldn’t contain the merge commits. Let’s saymain.tf
in your branchnew-feature
contains 100 lines, and this branch has been merged with the main branch, and on the merged branchmain.tf
has 120 lines, but the merged commit was discarded sogo-git
would has amain.tf
contains 120 line and a blame record which belongs to branchnew-feature
.Let’s drill down into
walkGraph
:It traversed the whole git commits tree, filter out commits those are related to the current file, uses
different, err := differentContents(path, current, parents)
to verify whether the commit has changed the file, if the answer is yes, then put the commit into results.The problem is:
For a merged commit, it has two parent commits, but in this block it forgot to check the
different
and store the releated commits into the result. That’s why we’ve met this issue.I’ll try to commit a pr to
go-git
repo.Hi, i have the same issue. Our pipeline job fails with the same error. The job is executed after the MR was MERGED. Any update on this? Thanks!
Confirmed the last commit on that file was a merge commit: