Private/Add-KadenTransactionalIgnoreEntry.ps1

function Add-KadenTransactionalIgnoreEntry {
    <#
    .SYNOPSIS
        Append missing transactional ignore entries to a child repository .gitignore.
    .DESCRIPTION
        Reads the required lines from Seeds/dot-gitignore (manifest key GitIgnore).
        Appends only lines the child does not already have. Creates `.gitignore` when
        absent. Does not replace other child lines. Writes UTF-8 without BOM via a
        temp file and replace so concurrent readers see a complete file.
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [string]$ChildRoot
    )

    $seedRoot = Join-Path $script:KadenModuleRoot 'Seeds'
    $manifest = Import-PowerShellDataFile -Path (Join-Path $seedRoot 'manifest.psd1')
    $required = @(Get-KadenRequiredIgnoreLine -SeedRoot $seedRoot -Manifest $manifest)
    $gitignorePath = Resolve-KadenContainedPath -Root $ChildRoot -RelativePath '.gitignore'

    $existing = @()
    if (Test-Path -LiteralPath $gitignorePath) {
        $existing = @(Get-Content -LiteralPath $gitignorePath)
    }

    $missing = @()
    foreach ($line in $required) {
        $already = $false
        foreach ($existingLine in $existing) {
            if ([string]::Equals($existingLine, $line, [System.StringComparison]::Ordinal)) {
                $already = $true
                break
            }
        }
        if (-not $already) {
            $missing += $line
        }
    }

    if ($missing.Count -eq 0) {
        return
    }

    $merged = @($existing) + @($missing)
    $text = ($merged -join [Environment]::NewLine) + [Environment]::NewLine
    Write-KadenTextAtomic -LiteralPath $gitignorePath -Text $text
}