Skip to content

Instantly share code, notes, and snippets.

@Restuta
Created March 28, 2013 23:59
Show Gist options
  • Save Restuta/5267805 to your computer and use it in GitHub Desktop.
Save Restuta/5267805 to your computer and use it in GitHub Desktop.
powershell wtf
$lastCommitMessage = (git log --pretty=format:'%B' HEAD^..HEAD)
if ($lastCommitMessage | Where-Object {$_ -Match "@(?<changesetId>\d+)"} ) {
Write-Host $matches["changesetId"] -ForegroundColor Red
}
if ($lastCommitMessage -Match "@(?<changesetId>\d+)") {
Write-Host $matches["changesetId"] -ForegroundColor Red
}
<#
outpusts:
1309
1309
for the message
"
@1309 r32 created by john on 2004-08-24 17:28:21 -0700 (Tue, 24 Aug 2004)
Fixes for Xerces strangeness. No ITS IDs.
"
==========================================================================================#>
$lastCommitMessage = (git log --pretty=format:'%B' HEAD^..HEAD)
<#if ($lastCommitMessage | Where-Object {$_ -Match "@(?<changesetId>\d+)"} ) {
Write-Host $matches["changesetId"] -ForegroundColor Red
}#>
if ($lastCommitMessage -Match "@(?<changesetId>\d+)") {
Write-Host $matches["changesetId"] -ForegroundColor Red
}
<#
fails with:
Cannot index into a null array.
At c:\Dropbox\FrontRange\Work\Powershell\git\p4-sync-to-latest-changeset-that-is-in-git.ps1:8 char:26
+ Write-Host $matches[ <<<< "changesetId"] -ForegroundColor Red
+ CategoryInfo : InvalidOperation: (changesetId:String) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment