Skip to content

Instantly share code, notes, and snippets.

@MichalBrylka
Last active November 9, 2021 23:49
Show Gist options
  • Save MichalBrylka/cc6c007ee6950b2e23aaf7d600f17f2e to your computer and use it in GitHub Desktop.
Save MichalBrylka/cc6c007ee6950b2e23aaf7d600f17f2e to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
Create WIP commit message
.EXAMPLE
.\PutCommitDrivenDevelopmentMessage.ps1 "Implement new important feature"
Example output
[feature/New-12345 b0d2215] New-12345 Implement new important feature
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $True)] [ValidateNotNullOrEmpty()] [Alias("m")] [string]$message
)
$branchName = git branch --show-current
if (($LASTEXITCODE -eq 0) -and ($branchName -match '.*?\/?(?<Issue>\w+-\d+)')) {
$issue = $Matches. Issue
$message = $message.Replace("\`"", "")
$commitMessage = "${issue} ${message}"
git commit --allow-empty -m "$commitMessage"
}
else {
Write-Error "Not a git repo or invalid branch name"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment