-
Notifications
You must be signed in to change notification settings - Fork 2
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_helpers: add fallback for inconsistent describe #2
base: master
Are you sure you want to change the base?
Conversation
@mithru @ajelinski can you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is right but I'm not sure if it is wrong either :-P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to assume this works?
Would be nice to have tests but I don't think we want to block things to add tests.
Added tests and simplified implementation. |
@ajelinski @mithro PTAL, added some tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments on the testing.
gh._call_custom_git_cmd(filepath.parent, f'commit -m {msg}') | ||
if tag: | ||
gh._call_custom_git_cmd(filepath.parent, f'tag {tag}') | ||
time.sleep(COMMIT_DELAY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might need to explain why you need time.sleep
and COMMIT_DELAY
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise git get confused about the sorting with all the commit dates being the same (it doesn't got below second resolution).
I'll add a comment.
|
||
|
||
def git_commit_and_tag(filepath, msg, tag=None): | ||
now = time.time() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use tempfile
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do use tmp_path
fixture from pytest in the test function, see https://docs.pytest.org/en/7.1.x/how-to/tmp_path.html for more details.
The date here is used for the file content (not the name).
time.sleep(COMMIT_DELAY) | ||
|
||
|
||
def test_get_first_reachable_tag(tmp_path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you probably want to put the setup into a def setup_test_repo
type function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean the git init
+ git config
? Maybe we can do this when there is actually more than one test that share the same setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, mostly because it wasn't clear to see what was the actual test verse what was just needed to get things set up for the test.
@proppy - What do we need to do to get this merged? |
We need to address the remaining comments :) |
try: | ||
return _call_custom_git_cmd(git_repo, 'describe --tags --abbrev=0', quiet=True) | ||
# list reachable tag sorted by commit date | ||
tags = _call_custom_git_cmd(git_repo, 'tag --merged').splitlines() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it depends on the git configuration but for me this is sorted lexicographically.
For example for hidapi (https://github.com/libusb/hidapi) this is definitely not a valid replacement:
$ git describe --tags --abbrev=0
hidapi-0.13.1
$ git tag --merged
hidapi-0.1.0
hidapi-0.10.0
hidapi-0.10.1
hidapi-0.11.0
hidapi-0.11.1
hidapi-0.11.2
hidapi-0.12.0
hidapi-0.12.0-rc1
hidapi-0.12.0-rc2
hidapi-0.13.0
hidapi-0.13.1
hidapi-0.2.2
hidapi-0.2.3
hidapi-0.2.4
hidapi-0.3.0
hidapi-0.5.0
hidapi-0.5.1
hidapi-0.5.2
hidapi-0.6.0
hidapi-0.7.0
hidapi-0.8.0-rc1
hidapi-0.9.0
hidapi-0.9.0-rc1
I tried using different --sort
options but they don't seem very stable to me (shouldn't creatordate
be the same as taggerdate
or committerdate
?):
$ git tag --sort=taggerdate --merged
hidapi-0.1.0
hidapi-0.10.0
hidapi-0.10.1
hidapi-0.11.0
hidapi-0.11.1
hidapi-0.11.2
hidapi-0.12.0
hidapi-0.12.0-rc1
hidapi-0.12.0-rc2
hidapi-0.2.2
hidapi-0.2.3
hidapi-0.2.4
hidapi-0.3.0
hidapi-0.5.0
hidapi-0.8.0-rc1
hidapi-0.9.0
hidapi-0.9.0-rc1
hidapi-0.5.1
hidapi-0.5.2
hidapi-0.6.0
hidapi-0.7.0
hidapi-0.13.0
hidapi-0.13.1
$ git tag --sort=committerdate --merged
hidapi-0.13.0
hidapi-0.13.1
hidapi-0.5.1
hidapi-0.5.2
hidapi-0.6.0
hidapi-0.7.0
hidapi-0.1.0
hidapi-0.2.2
hidapi-0.2.3
hidapi-0.2.4
hidapi-0.3.0
hidapi-0.5.0
hidapi-0.8.0-rc1
hidapi-0.9.0-rc1
hidapi-0.9.0
hidapi-0.10.0
hidapi-0.10.1
hidapi-0.11.0
hidapi-0.11.1
hidapi-0.11.2
hidapi-0.12.0-rc1
hidapi-0.12.0-rc2
hidapi-0.12.0
$ git tag --sort=creatordate --merged
hidapi-0.1.0
hidapi-0.2.2
hidapi-0.2.3
hidapi-0.2.4
hidapi-0.3.0
hidapi-0.5.0
hidapi-0.5.1
hidapi-0.5.2
hidapi-0.6.0
hidapi-0.7.0
hidapi-0.8.0-rc1
hidapi-0.9.0-rc1
hidapi-0.9.0
hidapi-0.10.0
hidapi-0.10.1
hidapi-0.11.0
hidapi-0.11.1
hidapi-0.11.2
hidapi-0.12.0-rc1
hidapi-0.12.0-rc2
hidapi-0.12.0
hidapi-0.13.0
hidapi-0.13.1
The --sort=creatordate
option seems to be what we look for but I'd need to test this on all our packages if it's really correct. I have a feeling the date of creation of either tag or commit won't necessarily point to the tag "closest" to the current HEAD.
Therefore I started thinking about other options.
Since for Xyce the Public_Release-7.6.0
name returned by git describe --tags
is invalid I didn't find any way to get to the actual tag name from it.
Maybe we should simply call git describe --tags
and grep the warning message to return the "is really '(.*)' here"
name:
warning: tag 'Public_Release-7.6.0' is really 'Release-7.6.0' here
I don't like this option very much but at least we don't need to worry about tag sorting which might be tricky.
WDYT?
|
||
gh._call_custom_git_cmd(repo, 'checkout main') | ||
git_commit_and_tag(repo / 'foo', 'third', tag='v0.2') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make sure this isn't just sorted lexicographically perhaps let's also add a v0.10
tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise the test file LGTM.
Fixes #1
Before:
After: