Skip to content

Commit

Permalink
Fix x-update-baseline to use reference field (#1414)
Browse files Browse the repository at this point in the history
  • Loading branch information
data-queue authored Jun 14, 2024
1 parent 8a25087 commit f09af89
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 4 deletions.
102 changes: 102 additions & 0 deletions azure-pipelines/end-to-end-tests-dir/registries.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,105 @@ finally
{
Pop-Location
}

# test x-update-baseline reference in registry
Write-Trace "test x-update-baseline reference in registry"
$manifestDir = "$TestingRoot/update-baseline-registry-reference"

New-Item -Path $manifestDir -ItemType Directory
$manifestDir = (Get-Item $manifestDir).FullName

Push-Location $manifestDir
try
{
$gitMainBranch = 'master'
$gitSecondaryBranch = 'secondary'

$CurrentTest = 'git init .'
git @gitConfigOptions init .
Throw-IfFailed

$vcpkgBaseline = @{
"default" = @{
}
}

New-Item -Path './ports' -ItemType Directory
New-Item -Path './versions' -ItemType Directory

New-Item -Path './versions/baseline.json' -Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgBaseline)

$CurrentTest = 'git add versions/baseline.json'
git @gitConfigOptions add versions/baseline.json
Throw-IfFailed

$CurrentTest = 'git commit initial commit'
git @gitConfigOptions commit -m "initial commit"
Throw-IfFailed

$vcpkgConfigurationJson = @{
"default-registry"= @{
"kind" = "git";
"baseline" = "";
"repository" = $manifestDir;
}
}

$vcpkgJson = @{}
New-Item -Path './vcpkg-configuration.json' -Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgConfigurationJson)
New-Item -Path './vcpkg.json' -Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgJson)

$CurrentTest = 'vcpkg x-update-baseline'
$out = Run-VcpkgAndCaptureOutput x-update-baseline
Throw-IfFailed

$CurrentTest = 'git rev-parse HEAD'
$registryBaseline = git rev-parse HEAD
Throw-IfFailed

$configurationBefore = Get-Content "$manifestDir/vcpkg-configuration.json" | ConvertFrom-Json -AsHashTable
if ($configurationBefore["default-registry"]["baseline"] -ne $registryBaseline) {
throw "x-update-baseline baseline mismatch"
}

$CurrentTest = 'git checkout secondary branch'
git @gitConfigOptions checkout -b $gitSecondaryBranch
Throw-IfFailed

$CurrentTest = 'git commit empty commit'
git @gitConfigOptions commit --allow-empty -m "empty commit"
Throw-IfFailed

$CurrentTest = 'git checkout main branch'
git @gitConfigOptions checkout $gitMainBranch
Throw-IfFailed

$vcpkgConfigurationJson = @{
"default-registry"= @{
"kind" = "git";
"baseline" = "";
"repository" = $manifestDir;
"reference" = "secondary";
}
}

New-Item -Path './vcpkg-configuration.json' -Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgConfigurationJson) -Force

$CurrentTest = 'git rev-parse branch'
$refBaseline = git rev-parse $gitSecondaryBranch
Throw-IfFailed

$CurrentTest = 'vcpkg x-update-baseline on reference'
$out = Run-VcpkgAndCaptureOutput x-update-baseline
Throw-IfFailed

$configurationBefore = Get-Content "$manifestDir/vcpkg-configuration.json" | ConvertFrom-Json -AsHashTable

if ($configurationBefore["default-registry"]["baseline"] -ne $refBaseline) {
throw "Unexpected baseline mismatch on reference branch"
}
}
finally
{
Pop-Location
}
10 changes: 6 additions & 4 deletions src/vcpkg/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,11 @@ namespace

namespace vcpkg
{
static ExpectedL<Optional<std::string>> get_baseline_from_git_repo(const VcpkgPaths& paths, StringView url)
static ExpectedL<Optional<std::string>> get_baseline_from_git_repo(const VcpkgPaths& paths,
StringView url,
std::string reference)
{
auto res = paths.git_fetch_from_remote_registry(url, "HEAD");
auto res = paths.git_fetch_from_remote_registry(url, reference);
if (auto p = res.get())
{
return Optional<std::string>(std::move(*p));
Expand All @@ -709,13 +711,13 @@ namespace vcpkg
{
if (kind == JsonIdGit)
{
return get_baseline_from_git_repo(paths, repo.value_or_exit(VCPKG_LINE_INFO));
return get_baseline_from_git_repo(paths, repo.value_or_exit(VCPKG_LINE_INFO), reference.value_or("HEAD"));
}
else if (kind == JsonIdBuiltin)
{
if (paths.use_git_default_registry())
{
return get_baseline_from_git_repo(paths, builtin_registry_git_url);
return get_baseline_from_git_repo(paths, builtin_registry_git_url, reference.value_or("HEAD"));
}
else
{
Expand Down

0 comments on commit f09af89

Please sign in to comment.