[repo-assist] fix(deps-file): preserve group indentation when adding packages - #4429
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
`paket add` did not preserve the existing indentation of an indented group in paket.dependencies. Packages added to a group whose entries were indented (e.g. two spaces) were inserted at column 0, producing mixed indentation in the file. AddAdditionalPackage now detects the indentation used by an existing group's other lines (ignoring the "group X" header itself) and applies it to the newly generated package line, so newly-added packages match the surrounding formatting. Closes #3784 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist, an AI assistant.
Summary
Fixes #3784 —
paket add -g <Group>(and other package-add code paths that go throughDependenciesFile.AddAdditionalPackage) did not preserve the existing indentation of an indented group inpaket.dependencies. If a group's contents were indented (e.g. two spaces, a common convention), the newly addednuget/clitoolline was inserted at column 0, leaving a mix of indented and non-indented lines.Root cause
AddAdditionalPackageinsrc/Paket.Core/PaketConfigFiles/DependenciesFile.fsbuilt the new package line viaDependenciesFileSerializer.packageStringwithout ever inspecting the surrounding lines for indentation, and then spliced it into the group's text at various insertion points depending on alphabetical position, sources, etc. None of those insertion paths added back any indentation.Fix
Added a small helper,
groupIndentation, that scans the target group's existing lines (skipping thegroup Xheader itself) for the first non-blank line and reuses its leading whitespace.AddAdditionalPackagenow prefixes the freshly generated package line with that indentation before inserting it, so it lines up with the rest of the group. The main (unnamed) dependency group is left untouched (no indentation), matching existing behavior/tests.Trade-offs
should add pinned package version to third group,should add pinned package version to last group) encoded the buggy indentation-loss behavior in their expected output; their expectations were updated to include the correct indentation, since that inconsistent formatting was itself the bug.Test Status
AddPackageSpecs.fs:should preserve indentation when adding package to an indented groupshould not add indentation when adding package to a non-indented groupdotnet test tests/Paket.Tests/Paket.Tests.fsproj --filter "FullyQualifiedName~AddPackageSpecs|FullyQualifiedName~DependenciesFile" -f net10.0→ 237/237 passed.net10.0): 1272 passed, 5 failed, 16 skipped. Verified viagit stashthat the same 5 failures (proxy-env-var tests and an assembly-metadata-loading test) are pre-existing onmasterand unrelated to this change.net461test pass and integration tests (require Mono, unavailable in this sandbox).Add this agentic workflow to your repo
To install this agentic workflow, run