Skip to content

Instantly share code, notes, and snippets.

@bhank
Last active December 14, 2015 17:49
Show Gist options
  • Save bhank/5124905 to your computer and use it in GitHub Desktop.
Save bhank/5124905 to your computer and use it in GitHub Desktop.
Open the TortoiseSVN or TortoiseGit Commit dialog (as appropriate) showing all modified files in a Visual Studio solution by running Tortoise-CommitSolution in the Package Manager Console.
# Tortoise-CommitSolution by Adam Coyne <adam@coyne.nu>
# Edit your NuGet PowerShell profile ($Env:UserProfile\Documents\WindowsPowerShell\NuGet_profile.ps1) to source this file (like ". $Env:UserProfile\Documents\WindowsPowerShell\commit.ps1") and add a convenient alias (like "Set-Alias commit Tortoise-CommitSolution")
function Tortoise-CommitSolution {
[string[]]$projectpaths = Get-Project -All | foreach { [System.IO.Path]::GetDirectoryName($_.FullName) }
$projectpaths += $dte.Solution.FullName
if($projectpaths.length -gt 0) {
$filename = Write-PathFile(Filter-PathArray($projectpaths))
# Visual Studio is 32-bit, but I have 64-bit TortoiseSvn and TortoiseGit installed
$programfiles = $Env:ProgramW6432
if(!$programfiles) { $programfiles = $Env:ProgramFiles }
if(Get-LocalOrParentPath .svn $projectpaths[0]) {
& "$programfiles\TortoiseSVN\bin\tortoiseproc.exe" /command:commit /deletepathfile /pathfile:`"$filename`" /hwnd:$($dte.MainWindow.HWnd)
} elseif(Get-LocalOrParentPath .git $projectpaths[0]) {
& "$programfiles\TortoiseGit\bin\tortoisegitproc.exe" /command:commit /deletepathfile /pathfile:`"$filename`" /hwnd:$($dte.MainWindow.HWnd)
}
}
}
# Filter out paths that are contained within another path, so modified files won't show up twice in the Commit dialog.
function Filter-PathArray([string[]]$paths) {
[string[]]$filteredprojectpaths = @()
[string]$lastCommonParentPath = "*" # an initial value that won't match
foreach($p in $paths | Sort-Object) {
if(-not $p.StartsWith($lastCommonParentPath)) {
$filteredprojectpaths += $p
$lastCommonParentPath = $p + "\"
}
}
return $filteredprojectpaths
}
# Tortoise's pathfile contains paths delimited by line feeds and with a trailing line feed, and is formatted as Unicode with no BOM.
function Write-PathFile([string[]]$files) {
$filename = [System.IO.Path]::GetTempFileName()
$contents = [string]::join("`n", $files) + "`n"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($contents)
Set-Content -Encoding byte $filename $bytes
return $filename
}
# From https://github.com/dahlbyk/posh-git
function Get-LocalOrParentPath($path, $startPath = '.') {
$checkIn = Get-Item $startPath
while ($checkIn -ne $NULL) {
$pathToTest = [System.IO.Path]::Combine($checkIn.fullname, $path)
if (Test-Path $pathToTest) {
return $pathToTest
} else {
$checkIn = $checkIn.parent
}
}
return $null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment