| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,6 +59,9 @@ def update(self, tags_only: bool, freeze: bool) -> RevInfo: | |||
| 59 | 59 | except CalledProcessError: | |
| 60 | 60 | cmd = (*git_cmd, 'rev-parse', 'FETCH_HEAD') | |
| 61 | 61 | rev = cmd_output(*cmd, cwd=tmp)[1].strip() | |
| 62 | + else: | ||
| 63 | + if tags_only: | ||
| 64 | + rev = git.get_best_candidate_tag(rev, tmp) | ||
| 62 | 65 | ||
| 63 | 66 | frozen = None | |
| 64 | 67 | if freeze: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -229,3 +229,18 @@ def check_for_cygwin_mismatch() -> None: | |||
| 229 | 229 | f' - python {exe_type[is_cygwin_python]}\n' | |
| 230 | 230 | f' - git {exe_type[is_cygwin_git]}\n', | |
| 231 | 231 | ) | |
| 232 | + | ||
| 233 | + | ||
| 234 | + def get_best_candidate_tag(rev: str, git_repo: str) -> str: | ||
| 235 | + """Get the best tag candidate. | ||
| 236 | + | ||
| 237 | + Multiple tags can exist on a SHA. Sometimes a moving tag is attached | ||
| 238 | + to a version tag. Try to pick the tag that looks like a version. | ||
| 239 | + """ | ||
| 240 | + tags = cmd_output( | ||
| 241 | + 'git', *NO_FS_MONITOR, 'tag', '--points-at', rev, cwd=git_repo, | ||
| 242 | + )[1].splitlines() | ||
| 243 | + for tag in tags: | ||
| 244 | + if '.' in tag: | ||
| 245 | + return tag | ||
| 246 | + return rev | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -103,6 +103,24 @@ def test_rev_info_update_tags_only_does_not_pick_tip(tagged): | |||
| 103 | 103 | assert new_info.rev == 'v1.2.3' | |
| 104 | 104 | ||
| 105 | 105 | ||
| 106 | + def test_rev_info_update_tags_prefers_version_tag(tagged, out_of_date): | ||
| 107 | + cmd_output('git', 'tag', 'latest', cwd=out_of_date.path) | ||
| 108 | + config = make_config_from_repo(tagged.path, rev=tagged.original_rev) | ||
| 109 | + info = RevInfo.from_config(config) | ||
| 110 | + new_info = info.update(tags_only=True, freeze=False) | ||
| 111 | + assert new_info.rev == 'v1.2.3' | ||
| 112 | + | ||
| 113 | + | ||
| 114 | + def test_rev_info_update_tags_non_version_tag(out_of_date): | ||
| 115 | + cmd_output('git', 'tag', 'latest', cwd=out_of_date.path) | ||
| 116 | + config = make_config_from_repo( | ||
| 117 | + out_of_date.path, rev=out_of_date.original_rev, | ||
| 118 | + ) | ||
| 119 | + info = RevInfo.from_config(config) | ||
| 120 | + new_info = info.update(tags_only=True, freeze=False) | ||
| 121 | + assert new_info.rev == 'latest' | ||
| 122 | + | ||
| 123 | + | ||
| 106 | 124 | def test_rev_info_update_freeze_tag(tagged): | |
| 107 | 125 | git_commit(cwd=tagged.path) | |
| 108 | 126 | config = make_config_from_repo(tagged.path, rev=tagged.original_rev) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments