Created
March 1, 2017 10:30
-
-
Save mig42/1c36928d8bd3f09aa9db8be1c8141d6a to your computer and use it in GitHub Desktop.
Powershell script to generate UNIX diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter(Mandatory=$true)][string]$SrcRev, | |
[Parameter(Mandatory=$true)][string]$DstRev, | |
[bool]$Force | |
) | |
function ExtractFileNameFromRev([string]$rev) | |
{ | |
if ("$rev" -match '^([^:#@]*:)?([^@]*).*$') | |
{ | |
$matches[2] | |
return | |
} | |
echo "UNKNOWN" | |
} | |
function FileExists([string]$File) | |
{ | |
if ("$File") | |
{ | |
Test-Path -LiteralPath "$File" | |
return | |
} | |
$false | |
} | |
$srcLabel = ExtractFileNameFromRev "$SrcRev" | |
$dstLabel = ExtractFileNameFromRev "$DstRev" | |
$srcPath = [io.path]::combine($env:Temp, [guid]::NewGuid()) | |
$dstPath = [io.path]::combine($env:Temp, [guid]::NewGuid()) | |
cm cat "$SrcRev;$srcPath" "$DstRev;$dstPath" | |
if ($Force -or (FileExists "$srcPath" -and FileExists "$dstPath")) | |
{ | |
# Download diff and depencencies at http://gnuwin32.sourceforge.net/packages/diffutils.htm | |
diff -Naur --label "$srcLabel" --label "$dstLabel" "$srcPath" "$dstPath" | |
} | |
else | |
{ | |
echo "Unable to calculate differences" | |
} | |
rm -Force "$srcPath","$dstPath" -ErrorAction SilentlyContinue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment