gotec / git2net

An Open Source Python package for the extraction of fine-grained and time-stamped co-editing networks from git repositories.
https://git2net.readthedocs.io
GNU Affero General Public License v3.0
53 stars 16 forks source link

Fixed git version detection on MacOS #16

Closed milo-trujillo closed 3 years ago

milo-trujillo commented 3 years ago

Git2Net currently crashes on MacOS when mining any cloned repository. This one-line patch fixes that.

Until now, if a user attempts to mine any git repo on MacOS:

Traceback (most recent call last):
  File "./test.py", line 10, in <module>
    git2net.mine_git_repo(git_repo_dir, "test.db", max_modifications=100)
  File "/Users/USERNAME/Library/Python/3.7/lib/python/site-packages/git2net/extraction.py", line 1431, in mine_git_repo
    parsed_git_version = re.search(r'(\d+)\.(\d+)\.(\d+)', git_version).groups()
AttributeError: 'NoneType' object has no attribute 'groups'

This is because git2net determines the git client version using the following two lines:

https://github.com/gotec/git2net/blob/917eb7b1992d63a58581bf80958d68f115e6d56c/git2net/extraction.py#L1429-L1431

This works on Linux where the version string looks like:

$ git --version
git version 2.17.1

But fails on MacOS, where the git version string looks like:

$ git --version
git version 2.14.3 (Apple Git-98)

Since you're using regular expressions already, splitting the version string on spaces and applying a regex to just the "2.17.1" portion is unnecessary - we can apply the regex to the entire version string, and extract the first x.y.z version number regardless of position.

With this change, version detection works on both Linux and MacOS.

gotec commented 3 years ago

Hi Milo,

Thanks a lot for letting me know and already providing a fix. While I checked for the different existing git versions I had only tested this feature on Linux so far. I will make a new release on PyPi soon.

Cheers, Christoph

gotec commented 3 years ago

git2net version 1.4.8 which includes your fix is now available on PyPi. Thanks again for reporting the issue as well as the solution :)