Skip to content

Commit 353a3b4

Browse files
authored
#174 fix: detect parent git repositories for nova bump (#176)
Make nova bump and Update-NovaModuleVersion resolve Git history from parent repositories, so nested project folders infer the correct semantic version instead of falling back to Patch with Commits: 0. Add regression coverage for nested project bump inference and update the changelog. Closes #174
1 parent 137ea93 commit 353a3b4

5 files changed

Lines changed: 65 additions & 5 deletions

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818

1919
### Fixed
2020

21+
- Fixed `nova bump` and `Update-NovaModuleVersion` so nested project folders now reuse parent Git repository history for bump inference instead of silently falling back to `Patch`.
22+
2123
### Security
2224

2325
## [2.3.0] - 2026-05-06

src/private/release/GetGitCommitMessagesForVersionBump.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function Get-GitCommitMessageForVersionBump {
44
[Parameter(Mandatory)][string]$ProjectRoot
55
)
66

7-
if (-not (Test-Path -LiteralPath (Join-Path $ProjectRoot '.git'))) {
7+
if (-not (Test-GitRepositoryIsAvailable -ProjectRoot $ProjectRoot)) {
88
return @()
99
}
1010

src/private/release/GetNovaVersionLabelForBump.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ function Test-GitRepositoryIsAvailable {
3535
[Parameter(Mandatory)][string]$ProjectRoot
3636
)
3737

38-
if (-not (Test-Path -LiteralPath (Join-Path $ProjectRoot '.git'))) {
39-
return $false
40-
}
41-
4238
$result = Invoke-NovaGitCommand -ProjectRoot $ProjectRoot -Arguments @('rev-parse', '--git-dir')
4339
return $result.ExitCode -eq 0
4440
}

tests/CoverageGaps.ReleaseInternals.Tests.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,28 @@ Describe 'Coverage gaps for release and git internals' {
620620
}
621621
}
622622

623+
It 'Get-GitCommitMessageForVersionBump resolves parent git repositories for nested project paths' {
624+
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
625+
Set-ItResult -Skipped -Because 'git is not available in this environment'
626+
return
627+
}
628+
629+
InModuleScope $script:moduleName {
630+
$repositoryRoot = Join-Path $TestDrive 'parent-git-repo'
631+
$projectRoot = Join-Path $repositoryRoot 'NestedProject'
632+
Initialize-TestGitRepository -Path $repositoryRoot
633+
New-Item -ItemType Directory -Path $projectRoot -Force | Out-Null
634+
New-TestGitCommit -RepositoryPath $repositoryRoot -Message 'feat!: nested project change' -File @{
635+
Name = 'NestedProject/feature.txt'
636+
Content = 'feature'
637+
}
638+
639+
$messages = @(Get-GitCommitMessageForVersionBump -ProjectRoot $projectRoot)
640+
641+
$messages | Should -Be @('feat!: nested project change')
642+
}
643+
}
644+
623645
It 'Get-NovaVersionLabelForBump falls back to Patch when the project is not a git repository' {
624646
InModuleScope $script:moduleName {
625647
$projectRoot = Join-Path $TestDrive 'no-git-project-for-label'

tests/NovaCommandModel.StandaloneCli.Tests.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,46 @@ Describe '$projectName tests' {
338338
}
339339
}
340340

341+
It 'Install-NovaCli infers a major bump from parent Git repository history for nested project roots' {
342+
$targetDirectory = Join-Path $TestDrive 'parent-git-bump-bin'
343+
$installedPath = Join-Path $targetDirectory 'nova'
344+
$repositoryRoot = Join-Path $TestDrive 'CliParentGitRepo'
345+
$projectRoot = Join-Path $repositoryRoot 'AzureDevOpsAgentInstaller'
346+
$projectJsonPath = Join-Path $projectRoot 'project.json'
347+
$originalModulePath = $env:PSModulePath
348+
$modulePathSeparator = [string][System.IO.Path]::PathSeparator
349+
$distParent = Split-Path -Parent $script:distModuleDir
350+
351+
$env:PSModulePath = "$distParent$modulePathSeparator$originalModulePath"
352+
353+
New-Item -ItemType Directory -Path $repositoryRoot -Force | Out-Null
354+
Initialize-TestNovaCliProjectLayout -ProjectRoot $projectRoot
355+
Write-TestNovaCliProjectJson -ProjectRoot $projectRoot -ProjectName 'AzureDevOpsAgentInstaller' -ProjectGuid '77777777-7777-7777-7777-777777777777'
356+
Write-TestNovaCliPublicFunction -ProjectRoot $projectRoot -FunctionName 'Invoke-TestNestedParentGitBump'
357+
358+
$projectData = Get-Content -LiteralPath $projectJsonPath -Raw | ConvertFrom-Json
359+
$projectData.Version = '1.5.4-preview'
360+
$projectData | ConvertTo-Json -Depth 20 | Set-Content -LiteralPath $projectJsonPath -Encoding utf8
361+
362+
try {
363+
Initialize-TestNovaCliGitRepository -ProjectRoot $repositoryRoot -CommitMessage 'feat!: add nested parent repo bump coverage'
364+
365+
Install-NovaCli -DestinationDirectory $targetDirectory -Force | Out-Null
366+
367+
$result = Invoke-TestInstalledNovaCommand -InstalledPath $installedPath -WorkingDirectory $projectRoot -Arguments @('bump', '--what-if')
368+
$versionAfterBump = (Get-Content -LiteralPath $projectJsonPath -Raw | ConvertFrom-Json).Version
369+
370+
$result.ExitCode | Should -Be 0
371+
$result.Text | Should -Match 'What if:'
372+
$result.Text | Should -Match 'Version plan: 1\.5\.4-preview -> 2\.0\.0 \| Label: Major \| Commits: 1'
373+
$result.Text | Should -Not -Match 'Version plan: 1\.5\.4-preview -> 1\.5\.4 \| Label: Patch \| Commits: 0'
374+
$versionAfterBump | Should -Be '1.5.4-preview'
375+
}
376+
finally {
377+
$env:PSModulePath = $originalModulePath
378+
}
379+
}
380+
341381
It 'Install-NovaCli rejects unsupported nova init invocations with clear migration guidance' -ForEach @(
342382
@{
343383
Name = 'WhatIf'

0 commit comments

Comments
 (0)