mtkennerly / dunamai

Dynamic versioning library and CLI
https://dunamai.readthedocs.io/en/latest
MIT License
312 stars 24 forks source link

fix: add `-c log.showsignature=false` to all `git log` commands #75

Closed pdecat closed 4 months ago

pdecat commented 5 months ago

This PR is a follow up to https://github.com/mtkennerly/dunamai/pull/51 and resolves issues where log.showSignature = true is set in git config, e.g.:

# pipx install git+ssh://git@myhost/myrepo.git
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [36 lines of output]
      Traceback (most recent call last):
        File "/home/patrick/.local/pipx/shared/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/patrick/.local/pipx/shared/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/patrick/.local/pipx/shared/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 149, in prepare_metadata_for_build_wheel
          return hook(metadata_directory, config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-ndzkym2o/overlay/lib/python3.11/site-packages/poetry/core/masonry/api.py", line 42, in prepare_metadata_for_build_wheel
          poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-ndzkym2o/overlay/lib/python3.11/site-packages/poetry_dynamic_versioning/patch.py", line 26, in alt_poetry_create
          name = _get_and_apply_version(
                 ^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-ndzkym2o/overlay/lib/python3.11/site-packages/poetry_dynamic_versioning/__init__.py", line 608, in _get_and_apply_version
          version, instance = _get_version(config, name)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-ndzkym2o/overlay/lib/python3.11/site-packages/poetry_dynamic_versioning/__init__.py", line 462, in _get_version
          serialized = version.serialize(
                       ^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-ndzkym2o/overlay/lib/python3.11/site-packages/dunamai/__init__.py", line 817, in serialize
          out = serialize_semver(base, pre=pre_parts, metadata=meta_parts)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-ndzkym2o/overlay/lib/python3.11/site-packages/dunamai/__init__.py", line 2131, in serialize_semver
          check_version(serialized, Style.SemVer)
        File "/tmp/pip-build-env-ndzkym2o/overlay/lib/python3.11/site-packages/dunamai/__init__.py", line 1991, in check_version
          raise ValueError(failure_message)
      ValueError: Version '0.35.1-post.4+gpg: Signature made Tue 21 Nov 2023 03:12:10 PM CET
      gpg:                using RSA key ******
      gpg: Good signature from "****** <******>" [unknown]
      gpg:                 aka "****** <******>" [unknown]
      gpg: WARNING: This key is not certified with a trusted signature!
      gpg:          There is no indication that the signature belongs to the owner.
      Primary key fingerprint: ******
      bab8748' does not conform to the Semantic Versioning style
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
Cannot determine package name from spec 'git+ssh://git@myhost/myrepo.git'. Check package spec for errors.

A work-around is to ignore the git configuration during installation:

GIT_CONFIG_GLOBAL=/dev/null pipx install git+ssh://git@myhost/myrepo.git

Signed-off-by: Patrick Decat pdecat@gmail.com

mtkennerly commented 5 months ago

Thanks for this!

One issue is that log.showsignature was added in Git 2.10.0, so we just need to add a condition based on the Git version (e.g., if git_version < [2, 10]). Dunamai tries to at least partially support versions as old as 1.8.2.3.

pdecat commented 5 months ago

Hi @mtkennerly, done!

Note: git -c log.showsignature was already used without this exact version check, so it would have failed with git versions between v2.2 and v2.9.