预提交自动更新 C:\Users\用户名\AppData\Local\Temp mp4up095pz\.pre-commit-hooks.yaml 不是文件

问题描述 投票:0回答:1

现在迫切需要一些帮助: 我正在创建一个 预提交钩子,以在 git commit -m "" 时触发

dotnet format
工具 我在解决方案根文件夹中有一个 p.re-commit-config.yaml 文件,可以通过
pre-commit autoupdate
访问该文件 因为存储库是我们的微服务组件之一

repos:
  - repo: https://github.com/**/Exchange
    rev: daa6bb69960b1e4d120cffb1f307afb9c5b493c1 #generated the latest SHA with pwsh update_rev.ps1
    hooks:
      - id: update-and-commit
        name: Update rev and commit
        entry: | 
          Write-Host "Starting update_rev.ps1 script..."
          ./.update_rev.ps1 
          Write-Host "Calling Update-Config function..."
          Update-Config -ConfigFile "./.pre-commit-config.yaml" 
          Write-Host "Executing git add..." 
          git add "./pre-commit-config.yaml" 
          Write-Host "Executing git commit..." 
          git commit       
        language: script
        pass_filenames: false 

      - id: dotnet-format
        name: Format C# files using dotnet format
        entry: Get-ChildItem -Recurse -Filter *.csproj | ForEach-Object {
                 Write-Host "Reading $_.FullName"
                 dotnet format --verbosity normal $_.FullName
               }
        language: system 
        types: [c#]

update_rev.ps1 是:

function Update-Config {
    param ($ConfigFile)
    Write-Host "$ConfigFile"
    # Get latest commit SHA on the 'main' branch 
    $latestSHA = git rev-parse main 2>$null
    $latestSHA
    
    if ($LASTEXITCODE -ne 0) {
        Write-Host "Failed to retrieve the latest commit SHA. Please ensure you are on the 'main' branch."
        exit 1
    }

    # Read the YAML config file
    $configText = Get-Content -Path $ConfigFile

    # Replace the 'rev' value (Modify if your config structure differs)
    $updatedConfig = $configText -replace '(?<=rev:\s).*', $latestSHA 

    # Overwrite the config file
    $updatedConfig | Set-Content -Path $ConfigFile
} 

# Call the function with the path to the config file
$configFilePath = "./.pre-commit-config.yaml" 
Update-Config -ConfigFile $configFilePath --force

我尝试了几种方法(检查目录、清理缓存、卸载/安装预提交),但错误输出仍然:

=====> C:\Users\username\.cache\pre-commit\repoh63ihe8q\.pre-commit-hooks.yaml is not a file
or 
=====> C:\Users\username\AppData\Local\Temp\tmpui9t9p_t\.pre-commit-hooks.yaml is not a file

/pre-commit 和 /Temp 文件夹存在,但文件未创建,也不在该目录中。 如何知道我是否有权访问该 /pre-commit 缓存文件夹并创建 .pre-commit-hooks.yaml 文件? 我怀疑这是 rev SHA 不正确,因此它无法访问该文件夹,但我不知道如何找出答案。

日志文件如下:

Traceback (most recent call last):
  File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\pre_commit\error_handler.py", line 73, in error_handler
    yield
  File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\pre_commit\main.py", line 417, in main
    return run(args.config, store, args)
  File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\pre_commit\commands\run.py", line 425, in run
    for hook in all_hooks(config, store)
  File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\pre_commit\repository.py", line 242, in all_hooks
    return tuple(
  File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\pre_commit\repository.py", line 245, in <genexpr>
    for hook in _repository_hooks(repo, store, root_config)
  File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\pre_commit\repository.py", line 220, in _repository_hooks
    return _cloned_repository_hooks(repo_config, store, root_config)
  File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\pre_commit\repository.py", line 187, in _cloned_repository_hooks
    by_id = {hook['id']: hook for hook in load_manifest(manifest_path)}
  File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\cfgv.py", line 416, in load_from_filename
    return apply_defaults(data, schema)
  File "c:\program files\python39\lib\contextlib.py", line 135, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\cfgv.py", line 45, in reraise_as
    raise tp(e).with_traceback(tb) from None
  File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\cfgv.py", line 42, in reraise_as
    yield
  File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\cfgv.py", line 401, in load_from_filename
    raise ValidationError(f'{display_filename} is not a file')
pre_commit.clientlib.InvalidManifestError: 
=====> C:\Users\username\.cache\pre-commit\repoecyb86_3\.pre-commit-hooks.yaml is not a file
git pre-commit pre-commit.com
1个回答
0
投票

该错误表明,在

https://github.com/**/Exchange
的最新标记修订版中,没有预提交清单

我怀疑清单仅存在于较新的标记版本上 - 您可以使用

pre-commit autoupdate --bleeding-edge
- 或者如果您控制该存储库,您可以发布版本


免责声明:我写了预提交

© www.soinside.com 2019 - 2024. All rights reserved.