Skip to content

Commit

Permalink
Fix File version generation from Git branch name in case Git reposito…
Browse files Browse the repository at this point in the history
…ry is in detached head state.
  • Loading branch information
jpawlowski committed Apr 9, 2024
1 parent 4645a46 commit 6dcbdce
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions setup/AzAutoFWProject/Set-AzAutomationRunbook.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<#PSScriptInfo
.VERSION 1.0.0
.VERSION 1.0.1
.GUID ac0280b2-7ee2-46bf-8a32-c1277189fb60
.AUTHOR Julian Pawlowski
.COMPANYNAME Workoho GmbH
Expand All @@ -12,8 +12,8 @@
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
Version 1.0.0 (2024-02-25)
- Initial release.
Version 1.0.1 (2024-03-09)
- Fix File version generation from Git branch name in case Git repository is in detached head state.
#>

<#
Expand Down Expand Up @@ -791,10 +791,23 @@ try {
}

if (-not $gitCache.Repository.$currentDirectory.Contains('Branch')) {
$gitCache.Repository.$currentDirectory.Branch = git rev-parse --abbrev-ref HEAD 2>$null
try {
$tag = git describe --exact-match --tags HEAD 2>$null
if ($tag -match '^v.+') {
$gitCache.Repository.$currentDirectory.Branch = $null
} else {
throw
}
} catch {
$gitCache.Repository.$currentDirectory.Branch = git rev-parse --abbrev-ref HEAD 2>$null
}
}
if ($gitCache.Repository.$currentDirectory.Branch -ne 'master' -and $gitCache.Repository.$currentDirectory.Branch -ne 'main') {
$branches = git branch --contains $latestFileCommitHash 2>$null | ForEach-Object { $_.Replace('*', '').Trim() }
if (
-not [string]::IsNullOrEmpty($gitCache.Repository.$currentDirectory.Branch) -and
$gitCache.Repository.$currentDirectory.Branch -ne 'master' -and
$gitCache.Repository.$currentDirectory.Branch -ne 'main'
) {
$branches = git branch --contains $latestFileCommitHash 2>$null | ForEach-Object { ($_ -replace '\*|\(.*\)', '').Trim() }
$branch = $null
if ($branches -contains $gitCache.Repository.$currentDirectory.Branch) {
$branch = $gitCache.Repository.$currentDirectory.Branch
Expand All @@ -807,6 +820,7 @@ try {
}

if ($null -ne $branch) {
Write-Verbose " Adding branch '$branch' to versioning."
if ($version -like '*-*') {
$version += ".$branch"
}
Expand Down

0 comments on commit 6dcbdce

Please sign in to comment.