admin管理员组

文章数量:1125621

I've written a custom diff command for reading a proprietary file type *.hdict, which would otherwise be treated as a binary file to be used in Git Extensions 5.1.1.17970.

.gitconfig:

[diff "hdict"]
    command = powershell -ExecutionPolicy Bypass -File C:/Repos/fillhalcon/DictionaryDiff/hdict-diff.ps1 $LOCAL $REMOTE

.gitattributes:

*.hdict diff=hdict

PowerShell script:

Param($LocalFile, $RemoteFile)
   
# Ensure paths are absolute
$LocalFile = Join-Path -Path (Get-Location) -ChildPath $LocalFile

# Generate temporary files for output
$CleanLocal = [System.IO.Path]::GetTempFileName()
$CleanRemote = [System.IO.Path]::GetTempFileName()

# Path to ConsoleApp2.exe using relative path
$ExePath = Join-Path -Path $PSScriptRoot -ChildPath "DictConversion\DictConversion\bin\Debug\net8.0\DictConversion.exe"

# Run ConsoleApp2.exe ONCE for both files
& $ExePath $LocalFile $RemoteFile $CleanLocal $CleanRemote

# Remove null bytes (^@) from the files
(Get-Content -Raw $CleanLocal) -replace "`0", "" | Set-Content $CleanLocal
(Get-Content -Raw $CleanRemote) -replace "`0", "" | Set-Content $CleanRemote

# Perform the diff using git diff and save output
& git diff --no-index $CleanRemote $CleanLocal

# Clean up temporary files
Remove-Item $CleanLocal
Remove-Item $CleanRemote

Console output from the Git-Extensions works fine:

But any visual interaction is still seeing it as a binary:

Any idea, why GUI is not triggering the same command "git diff"?

本文标签: powershellGitExtensions GUI produces different output as Git consoleStack Overflow