-
Notifications
You must be signed in to change notification settings - Fork 1
git_helpers: add fallback for inconsistent describe #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
base: master
Are you sure you want to change the base?
Changes from all commits
02dd022
917639f
17e71e4
06ea4bd
41ecf06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,10 +145,11 @@ def _call_custom_git_cmd(git_repo, cmd_string, check=True, quiet=False): | |
| return stdout.strip() | ||
|
|
||
|
|
||
| def get_latest_describe_tag(git_repo): | ||
| # Find the `git describe` tag having any version-like part | ||
| def get_first_reachable_tag(git_repo): | ||
| 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() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. I tried using different The Therefore I started thinking about other options. Maybe we should simply call I don't like this option very much but at least we don't need to worry about tag sorting which might be tricky. |
||
| return tags[-1] | ||
| except subprocess.CalledProcessError: | ||
| return None | ||
|
|
||
|
|
@@ -232,7 +233,7 @@ def git_rewrite_tags(git_repo): | |
| print(f'\nRewriting tags in "{os.path.abspath(git_repo)}"...\n') | ||
|
|
||
| while True: | ||
| tag = get_latest_describe_tag(git_repo) | ||
| tag = get_first_reachable_tag(git_repo) | ||
| if tag is None: | ||
| # Add '0.0' tag on initial commit and skip rewriting. | ||
| git_add_initial_tag(git_repo) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import time | ||
|
|
||
| import conda_build_prepare.git_helpers as gh | ||
|
|
||
| COMMIT_DELAY = 1 | ||
|
|
||
|
|
||
| def git_commit_and_tag(filepath, msg, tag=None): | ||
| now = time.time() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do use The date here is used for the file content (not the name). |
||
| with open(filepath, 'w') as f: | ||
| f.write(f'{now}') | ||
| gh._call_custom_git_cmd(filepath.parent, f'add {filepath}') | ||
| 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might need to explain why you need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 test_get_first_reachable_tag(tmp_path): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you probably want to put the setup into a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you mean the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| repo = tmp_path | ||
| gh._call_custom_git_cmd(repo, 'init -b main') | ||
| gh._call_custom_git_cmd( | ||
| repo, 'config --local user.email "you@example.com"' | ||
| ) | ||
| gh._call_custom_git_cmd( | ||
| repo, 'config --local user.name "Your Name"' | ||
| ) | ||
| git_commit_and_tag(repo / 'foo', 'first', tag=None) | ||
|
|
||
| initial_rev = gh._call_custom_git_cmd(repo, 'rev-parse HEAD') | ||
| gh._call_custom_git_cmd(repo, 'checkout -b fixup') | ||
| git_commit_and_tag(repo / 'foo', 'unreachable', tag='v0.0-unreachabe') | ||
|
|
||
| gh._call_custom_git_cmd(repo, 'checkout main') | ||
| git_commit_and_tag(repo / 'foo', 'second', tag='v0.1') | ||
|
|
||
| git_commit_and_tag(repo / 'foo', 'untagged', tag=None) | ||
|
|
||
| gh._call_custom_git_cmd(repo, 'checkout main') | ||
| git_commit_and_tag(repo / 'foo', 'third', tag='v0.2') | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise the test file LGTM. |
||
| gh._call_custom_git_cmd(repo, f'tag v0.0-retroactive {initial_rev}') | ||
| assert gh.get_first_reachable_tag(repo) == 'v0.2' | ||
Uh oh!
There was an error while loading. Please reload this page.