Skip to content

Commit

Permalink
Fixing error at re-registration (#249)
Browse files Browse the repository at this point in the history
* fix

* add tests
  • Loading branch information
aguschin authored Sep 5, 2022
1 parent 40ec47a commit ddc1b64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions gto/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,18 @@ def register( # pylint: disable=too-many-locals
# check that this commit don't have a version already
found_version = found_artifact.find_version(commit_hexsha=ref)
if found_version is not None:
if not force and found_version.is_registered:
if not force and found_version.is_registered and found_version.is_active:
raise VersionExistsForCommit(name, found_version.version)
if force and found_version.version != version:
if not version:
version = found_version.version
elif found_version.version != version:
raise WrongArgs(
f"For this REF you can only register {found_version.version}"
)
# if version name is provided, use it
if version:
SemVer(version)
if found_artifact.find_version(name=version) is not None:
if found_artifact.find_version(name=version) != found_version:
raise VersionAlreadyRegistered(version)
else:
# if version name wasn't provided but there were some, bump the last one
Expand Down
16 changes: 16 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,22 @@ def test_register(repo_with_commit: Tuple[git.Repo, Callable]):
" git push [email protected]\n",
)

_check_successful_cmd(
"deprecate",
["-r", repo.working_dir, "a2", "v1.2.3"],
"Created git tag '[email protected]!' that deregisters version\n"
"To push the changes upstream, run:\n"
" git push [email protected]!\n",
)

_check_successful_cmd(
"register",
["-r", repo.working_dir, "a2", "--simple", "false"],
"Created git tag '[email protected]#1' that registers version\n"
"To push the changes upstream, run:\n"
" git push [email protected]#1\n",
)

_check_failing_cmd(
"register",
["-r", repo.working_dir, "a3", "--version", "1.2.3"],
Expand Down

0 comments on commit ddc1b64

Please sign in to comment.