<# .SYNOPSIS Updates the libgit2 submodule to the specified commit and updates libgit2_hash.txt and NativeBinaries.props with the new hash value. .PARAMETER sha Desired libgit2 version. This is run through `git rev-parse`, so branch names are okay too. #> Param( [string]$sha = 'HEAD', [string]$libgit2Name = '' ) Set-StrictMode -Version Latest $self = Split-Path -Leaf $MyInvocation.MyCommand.Path $projectDirectory = Split-Path $MyInvocation.MyCommand.Path $libgit2Directory = Join-Path $projectDirectory "libgit2" function Invoke-Command([scriptblock]$Command, [switch]$Fatal, [switch]$Quiet) { $output = "" if ($Quiet) { $output = & $Command 2>&1 } else { & $Command } if (!$Fatal) { return } $exitCode = 0 if ($LastExitCode -ne 0) { $exitCode = $LastExitCode } elseif (!$?) { $exitCode = 1 } else { return } $error = "``$Command`` failed" if ($output) { Write-Host -ForegroundColor yellow $output $error += ". See output above." } Throw $error } function Find-Git { $git = @(Get-Command git)[0] 2>$null if ($git) { $git = $git.Definition Write-Host -ForegroundColor Gray "Using git: $git" & $git --version | write-host -ForegroundColor Gray return $git } throw "Error: Can't find git" } Push-Location $libgit2Directory & { trap { Pop-Location break } $git = Find-Git Write-Output "Fetching..." Invoke-Command -Quiet { & $git fetch } Write-Output "Verifying $sha..." $sha = & $git rev-parse $sha if ($LASTEXITCODE -ne 0) { write-host -foregroundcolor red "Error: invalid SHA. USAGE: $self " Pop-Location break } Write-Output "Checking out $sha..." Invoke-Command -Quiet -Fatal { & $git checkout $sha } Pop-Location if (![string]::IsNullOrEmpty($libgit2Name)) { $binaryFilename = $libgit2Name } else { $binaryFilename = "git2-" + $sha.Substring(0,7) } Set-Content -Encoding ASCII (Join-Path $projectDirectory "nuget.package\libgit2\libgit2_hash.txt") $sha $buildProperties = @" `$(MSBuildAllProjects);`$(MSBuildThisFileFullPath) `$(MSBuildThisFileFullPath) $sha $binaryFilename "@ Set-Content -Encoding UTF8 (Join-Path $projectDirectory "nuget.package\build\LibGit2Sharp.NativeBinaries.props") $buildProperties $net46BuildProperties = @" `$(MSBuildAllProjects);`$(MSBuildThisFileFullPath) `$(MSBuildThisFileFullPath) $sha $binaryFilename lib\win32\x64\$binaryFilename.dll PreserveNewest lib\win32\x64\$binaryFilename.pdb PreserveNewest lib\win32\x86\$binaryFilename.dll PreserveNewest lib\win32\x86\$binaryFilename.pdb PreserveNewest lib\osx\lib$binaryFilename.dylib PreserveNewest lib\linux-x64\lib$binaryFilename.so PreserveNewest lib\ubuntu.18.04-x64\lib$binaryFilename.so PreserveNewest lib\rhel-x64\lib$binaryFilename.so PreserveNewest lib\fedora-x64\lib$binaryFilename.so PreserveNewest lib\debian.9-x64\lib$binaryFilename.so PreserveNewest lib\alpine-x64\lib$binaryFilename.so PreserveNewest LibGit2Sharp.dll.config PreserveNewest "@ Set-Content -Encoding UTF8 (Join-Path $projectDirectory "nuget.package\build\net46\LibGit2Sharp.NativeBinaries.props") $net46BuildProperties $dllConfig = @" "@ Set-Content -Encoding UTF8 (Join-Path $projectDirectory "nuget.package\libgit2\LibGit2Sharp.dll.config") $dllConfig Write-Output "Done!" } exit