ejwa / gitinspector

:bar_chart: The statistical analysis tool for git repositories
GNU General Public License v3.0
2.34k stars 324 forks source link

Authorless commits crash tool #230

Open cujomalainey opened 2 years ago

cujomalainey commented 2 years ago
Traceback (most recent call last):
  File "/usr/bin/gitinspector", line 33, in <module>
    sys.exit(load_entry_point('gitinspector==0.4.4', 'console_scripts', 'gitinspector')())
  File "/usr/lib/python3/dist-packages/gitinspector/gitinspector.py", line 184, in main
    __run__.output()
  File "/usr/lib/python3/dist-packages/gitinspector/gitinspector.py", line 75, in output
    outputable.output(changes.ChangesOutput(self.hard))
  File "/usr/lib/python3/dist-packages/gitinspector/outputable.py", line 38, in output
    outputable.output_text()
  File "/usr/lib/python3/dist-packages/gitinspector/changes.py", line 343, in output_text
    authorinfo_list = self.changes.get_authorinfo_list()
  File "/usr/lib/python3/dist-packages/gitinspector/changes.py", line 242, in get_authorinfo_list
    Changes.modify_authorinfo(self.authors, i.author, i)
AttributeError: 'Commit' object has no attribute 'author'

Tool was run on https://github.com/zephyrproject-rtos/zephyr

uberkael commented 2 years ago

I "solved" it for plain text (for HTML continues to crash) like this:

--- <gitinspector/changes.py>
+++ <gitinspector/changes.py>
    def get_authorinfo_list(self):
        if not self.authors:
            for i in self.commits:
-               Changes.modify_authorinfo(self.authors, i.author, i)
+               Changes.modify_authorinfo(self.authors, i.author if hasattr(i, 'author') else "x", i)

        return self.authors
adam-waldenberg commented 2 years ago

Good catch - By authorless I'm assuming we are talking about an empty author string ? That's actually not permited by git. If you run git fsck on such a repo you should get errors. Question is what the correct behavior is here. We could certainly insert a "No Author" user into the result, but it's probably also a good idea to inform users about it and not condone invalid use of git.

dirtcrusher commented 1 year ago

I'm having this issue as well on a private (work) repository, and I do not have any authorless commits in the repository.

I'm not familiar with the codebase, but I attempted some debugging.

I found some invalid strings passed to the Commit constructor (1 file changed, 1 insertion(+), 1 deletion(-)).

When I removed the or i is lines[-1] from here, the error went away.

I added a print statement of i when i is lines[-1], and I had a lot of empty lines + the invalid strings I mentioned before.

This is where I'm stuck for now, but I hope that my experiments can help someone find the actual bug.

adam-waldenberg commented 1 year ago

I'm having this issue as well on a private (work) repository, and I do not have any authorless commits in the repository.

I'm not familiar with the codebase, but I attempted some debugging.

I found some invalid strings passed to the Commit constructor (1 file changed, 1 insertion(+), 1 deletion(-)).

When I removed the or i is lines[-1] from here, the error went away.

I added a print statement of i when i is lines[-1], and I had a lot of empty lines + the invalid strings I mentioned before.

This is where I'm stuck for now, but I hope that my experiments can help someone find the actual bug.

If you don't have any authorless commits, then this mandates further investigation I would say.

FeXd commented 1 month ago

I just ran into the exact same issue with a class I am teaching.

The error I'm getting:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Users\xxx\gitinspector\changes.py", line 151, in run
    bisect.insort(commits, commit)
  File "C:\Users\xxx\gitinspector\changes.py", line 82, in __lt__
    return self.timestamp.__lt__(other.timestamp) # only used for sorting; we just consider the timestamp.
AttributeError: 'Commit' object has no attribute 'timestamp'

Following @dirtcrusher's suggestions and deleting or i is lines[-1] from here allows everything to run.

I've tried some other Python 3.x versions and am getting the same result.

The line of code in question was introduce in the second commit of the project here.