fails pulling hooks from sha1 repos with `init.defaultobjectformat=sha256`. · Issue #3434 · pre-commit/pre-commit · GitHub
Skip to content

fails pulling hooks from sha1 repos with init.defaultobjectformat=sha256. #3434

@mschilli87

Description

@mschilli87

search you tried in the issue tracker

sha256

describe your issue

I have init.defaultobjectformat=sha256 configure globally to ensure I do not create any new repositories with sha1 anymore. If in a (local) sha256 repo which refers to a remote sha1 repo in its .pre-commit-config.yaml I run

pre-commit run --all-files

, I get the following error:

[INFO] Initializing environment for https://github.com/fsfe/reuse-tool.
An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', 'fetch', 'origin', '--tags')
return code: 128
stdout: (none)
stderr:
    fatal: mismatched algorithms: client sha256; server sha1
Check the log at /home/mschilli87/.cache/pre-commit/pre-commit.log

Temporarily setting

git config --global init.defaultObjectFormat sha1

enables pre-commit run to pass and successfully I can set

git config --global init.defaultObjectFormat sha256

again and it keeps working.

I guess for some reason, instead of cloning the upstream sha1 repo locally via git clone, pre-commit for some reason initiates an empty repo via git init, adds the upstream repo as origin via git remote add and the tries to fetch the specified tag via git fetch.

Anyhow, running a pre-commit hook on an existing repo based on an upstream one should not depend on config options specific to the creation of new local repos, so I consider this a bug.

pre-commit --version

pre-commit 4.2.0

.pre-commit-config.yaml

# SPDX-FileCopyrightText: 2020 Free Software Foundation Europe e.V.
# SPDX-License-Identifier: CC0-1.0
repos:
  - repo: https://github.com/fsfe/reuse-tool
    rev: v5.0.2
    hooks:
      - id: reuse

~/.cache/pre-commit/pre-commit.log (if present)

version information

pre-commit version: 4.2.0
git --version: git version 2.49.0
sys.version:
    3.12.9 (main, Mar  4 2025, 22:48:41) [GCC 13.3.0]
sys.executable: /usr/bin/python3.12
os.name: posix
sys.platform: linux

error information

An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', 'fetch', 'origin', '--tags')
return code: 128
stdout: (none)
stderr:
    fatal: mismatched algorithms: client sha256; server sha1
Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/pre_commit/store.py", line 207, in clone_strategy
    self._shallow_clone(ref, _git_cmd)
  File "/usr/lib/python3.12/site-packages/pre_commit/store.py", line 189, in _shallow_clone
    git_cmd('-c', git_config, 'fetch', 'origin', ref, '--depth=1')
  File "/usr/lib/python3.12/site-packages/pre_commit/store.py", line 204, in _git_cmd
    cmd_output_b('git', *args, cwd=directory, env=env)
  File "/usr/lib/python3.12/site-packages/pre_commit/util.py", line 111, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/usr/bin/git', '-c', 'protocol.version=2', 'fetch', 'origin', 'v5.0.2', '--depth=1')
return code: 128
stdout: (none)
stderr:
    fatal: mismatched algorithms: client sha256; server sha1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/usr/lib/python3.12/site-packages/pre_commit/main.py", line 417, in main
    return run(args.config, store, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pre_commit/commands/run.py", line 425, in run
    for hook in all_hooks(config, store)
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pre_commit/repository.py", line 233, in all_hooks
    return tuple(
           ^^^^^^
  File "/usr/lib/python3.12/site-packages/pre_commit/repository.py", line 236, in <genexpr>
    for hook in _repository_hooks(repo, store, root_config)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pre_commit/repository.py", line 211, in _repository_hooks
    return _cloned_repository_hooks(repo_config, store, root_config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pre_commit/repository.py", line 177, in _cloned_repository_hooks
    manifest_path = os.path.join(store.clone(repo, rev), C.MANIFEST_FILE)
                                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pre_commit/store.py", line 211, in clone
    return self._new_repo(repo, ref, deps, clone_strategy)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pre_commit/store.py", line 165, in _new_repo
    make_strategy(directory)
  File "/usr/lib/python3.12/site-packages/pre_commit/store.py", line 209, in clone_strategy
    self._complete_clone(ref, _git_cmd)
  File "/usr/lib/python3.12/site-packages/pre_commit/store.py", line 181, in _complete_clone
    git_cmd('fetch', 'origin', '--tags')
  File "/usr/lib/python3.12/site-packages/pre_commit/store.py", line 204, in _git_cmd
    cmd_output_b('git', *args, cwd=directory, env=env)
  File "/usr/lib/python3.12/site-packages/pre_commit/util.py", line 111, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/usr/bin/git', 'fetch', 'origin', '--tags')
return code: 128
stdout: (none)
stderr:
    fatal: mismatched algorithms: client sha256; server sha1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions