-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInitialize-LVGitDiff.ps1
More file actions
68 lines (55 loc) · 2.56 KB
/
Initialize-LVGitDiff.ps1
File metadata and controls
68 lines (55 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", '', Justification = "False positive")]
param(
# Path to a Git repository that needs to be initialized for diffing LabVIEW files.
[Parameter(Mandatory = $true)]
[string] $RepositoryPath,
# Explicit path to LVCompare. Defaults to '<drive>:\Program Files*\National Instruments\Shared\LabVIEW Compare\lvcompare.exe'.
[string] $LvComparePath
)
$main = {
if (!(Test-Path $RepositoryPath)) {
throw "$RepositoryPath does not exist!"
}
Import-Module $PSScriptRoot\NI.Software\NI.Software.psm1 -Force
function EscapePath([string] $UnescapedPath) {
$UnescapedPath.Replace('\', '\\')
}
$wrapperScriptPath = Copy-Item "$PSScriptRoot\GitDiffCommand.sh" $env:USERPROFILE -PassThru
$lvComparePath = Find-LvCompare $LvComparePath -Verbose:$VerbosePreference
if ($lvComparePath -and (Test-Path $lvComparePath)) {
$CgFileTypes | Enable-FileTypeDiff $RepositoryPath 'cg-diff' "$(EscapePath($wrapperScriptPath)) '\""$(EscapePath($lvComparePath))\"" -nobdpos -nofppos \""`$FIXED_OLD\"" \""`$FIXED_NEW\""' $true"
} else {
Write-Warning "Could not locate LV Compare; Re-run this script and specify the location of lvcompare.exe with -LvComparePath or LV CG files will not be graphically diffed."
}
}
function Enable-FileTypeDiff {
param(
[string] $RepositoryPath,
[string] $DiffName,
[string] $DiffCommand
)
git config --global diff."$DiffName".command $DiffCommand
$labviewType = ''
if ($DiffName -match '([^-]+)') {
$labviewType = " $($Matches[1])".ToUpperInvariant()
}
$hasHeader = $false
$gitAttributes = "$RepositoryPath\.gitattributes"
$newlineCount = if (Test-Path $gitAttributes) { 2 } else { 0 }
foreach ($filetype in $input) {
if ("$(git -C $RepositoryPath check-attr diff *$filetype)" -notmatch $DiffName) {
if (!$hasHeader) {
# AppendAllText will automatically create the file if it doesn't exist, unlike Add-Content
[System.IO.File]::AppendAllText($gitAttributes, [Environment]::NewLine * $newlineCount + @"
###############################################################################
# Use $DiffName to diff LabVIEW$labviewType files
###############################################################################
"@)
$hasHeader = $true
}
[System.IO.File]::AppendAllText($gitAttributes, [Environment]::NewLine + "*$filetype diff=$DiffName")
}
}
}
& $main