Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork948
Description
Theversion_info
property ofGit
instances is cached per-instance, while thegit.refresh
function andGit.refresh
class method modify global state. Whenversion_info
has been read on aGit
instance, refreshing affects the behavior of that instance, but does not invalidate the cache, causing theversion_info
property and dynamicversion
method to give inconsistent results even when no changes to environment variables or the filesystem have occurred.
Here's an example produced on a CentOS 7 system where I have both the systemgit
and a newer upstreamgit
installed:
ek in 🌐 Eald in GitPython on main via 🐍 v3.12.1 via 🅒 GitPython❯ type -a gitgit is /home/ek/bin/gitgit is /usr/bin/gitek in 🌐 Eald in GitPython on main via 🐍 v3.12.1 via 🅒 GitPython❯ git --versiongit version 2.43.0ek in 🌐 Eald in GitPython on main via 🐍 v3.12.1 via 🅒 GitPython❯ /usr/bin/git --versiongit version 1.8.3.1ek in 🌐 Eald in GitPython on main via 🐍 v3.12.1 via 🅒 GitPython❯ pythonPython 3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:03:24) [GCC 12.3.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import git>>> g1 = git.Git()>>> g2 = git.Git()>>> g1.version_info(2, 43, 0)>>> git.refresh("/usr/bin/git")>>> g1.version()'git version 1.8.3.1'>>> g2.version()'git version 1.8.3.1'>>> g1.version_info(2, 43, 0)>>> g2.version_info(1, 8, 3, 1)
Because I had accessedg1.version_info
before refreshing, the stale version information is handed back even after the refresh.
This is admittedly consistent with howversion_info
is documented:
Line 839 inafa5754
This value is generated on demand and is cached. |
But it seems to me that the documentation, as currently written, does not prevent it from being surprising. I think that either this should be made clear in theversion_info
property docstring, or the behavior should be changed so that refreshing invalidates allGit
instances' cachedversion_info
properties. I am not sure which is better, because I don't know whyversion_info
is cached (and cached per instance).
This issue can probably be considered minor. In particular, this does not preventFetchInfo.refresh
(whichgit.refresh
calls after callingGit.refresh
) from updatingFetchInfo._flag_map
correctly, becauseFetchInfo.refresh
accessesversion_info
on a newly createdGit
instance:
Line 346 inafa5754
ifGit().version_info[:2]>= (2,10): |