-
-
Notifications
You must be signed in to change notification settings - Fork 905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Git.version_info can drop intermediate fields unexpectedly #1833
Comments
Thanks for investigating this! I think the behaviour shown here is clearly incorrect, no matter the intent, and thus a fix would be preferred. Even though such versions would be unusual, it's a question on how to correct them. Should they be turned into the closest-possible number? Or should parsing stop there so, in this example, there is only a single number present? I think these details are best left to the one implementing this. |
This modifies two existing test cases to include an assertion about the length. These test cases are retained as there is value in testing on output from a real git command rather than only with test doubles. More importantly, this also adds a parameterized test method to check parsing of: - All numeric, shorter than the limit - all fields used. - All numeric, at the limit - all fields used. - All numeric, longer than the limit - extra fields dropped. - Has unambiguous non-numeric - dropped from there on. - Has ambiguous non-numeric, negative int - dropped from there on. - Has ambiguous non-numeric, number+letter - dropped from there on. The cases for parsing when a field is not numeric (or not fully or unambiguously numeric) currently all fail, because the existing logic drops intermediate non-numeric fields (gitpython-developers#1833). Parsing should instead stop at (or, *perhaps* in cases like "2a", after) such fields. When the code is changed to stop at them rather than dropping them and presenting the subsequent field as though it were a previous field, these test cases should also pass.
I think that if the chosen approach is simple enough then it may reasonably be included in the same PR that fixes some other It may be that fields such as This issue with non-numeric parts is also related, at least conceptually, to the way |
For gitpython-developers#1833. This makes version_info parsing stop including fields after the first non-numeric field, rather than skipping non-numeric fields and including subsequent numeric fields that then wrongly appear to have the original position and significance of the dropped field. This actually stops at (rather than merely after) a non-numeric field, i.e., potentially parseable fields that are not fully numeric, such as "2a", are stopped at, rather than parsed as "2".
The
version_info
attribute ofGit
instances drops non-numeric fields, even if they appear before a field that is kept:GitPython/git/cmd.py
Line 822 in afa5754
If a non-numeric field is followed by a numeric field, the effect is to make it look like the field that was actually non-numeric has the value of the subsequent field:
(As shown, partially numeric fields that do not wholly parse to a number are non-numeric for this purpose.)
I think this should either be changed to stop before the first non-numeric field, or kept as it is but with this behavior documented explicitly to reduce confusion. In the latter case, the rationale should be given. The rationale may just be backward compatibility, though I am not sure if that is a sufficient reason to keep this behavior, since it seems unexpected in the cases where it makes a difference. There may be other alternatives that I haven't thought of.
I think this is a minor issue, since such versions may be rare or nonexistent.
git
version numbers that have a non-numeric field followed by a numeric field are common, such as 2.43.0.windows.1 on Windows. However, GitPython only looks at the first four fields, so the trailing 1 in 2.43.0.windows.1 is not wrongly presented as the field that follows the 0.From the comments, it looks like this situation was specifically envisioned, suggesting that the exact current behavior may be intended:
GitPython/git/cmd.py
Line 816 in afa5754
However, it seems more likely to me that it was done this way to preserve earlier logic while fixing a specific bug. The
if n.isdigit()
filter was added in 6a61110 (#195).Full current code for context:
GitPython/git/cmd.py
Lines 814 to 826 in afa5754
This may make sense to fix at the same time as #1829 and/or #1830, I'm not sure.
The text was updated successfully, but these errors were encountered: