Skip to content

[repo-assist] fix(deps-file): preserve group indentation when adding packages - #4429

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
repo-assist/fix-issue-3784-group-indentation-537b214ab5303f66
Draft

[repo-assist] fix(deps-file): preserve group indentation when adding packages#4429
github-actions[bot] wants to merge 1 commit into
masterfrom
repo-assist/fix-issue-3784-group-indentation-537b214ab5303f66

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant.

Summary

Fixes #3784paket add -g <Group> (and other package-add code paths that go through DependenciesFile.AddAdditionalPackage) did not preserve the existing indentation of an indented group in paket.dependencies. If a group's contents were indented (e.g. two spaces, a common convention), the newly added nuget/clitool line was inserted at column 0, leaving a mix of indented and non-indented lines.

Root cause

AddAdditionalPackage in src/Paket.Core/PaketConfigFiles/DependenciesFile.fs built the new package line via DependenciesFileSerializer.packageString without 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 the group X header itself) for the first non-blank line and reuses its leading whitespace. AddAdditionalPackage now 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

  • Indentation detection is based on the first non-blank content line found in the group (source/nuget/github lines), which matches the common case where a whole group is consistently indented. Mixed-indentation groups are not specially handled — behavior there is unspecified but no worse than before.
  • Two existing tests (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

  • Added two new tests in AddPackageSpecs.fs:
    • should preserve indentation when adding package to an indented group
    • should not add indentation when adding package to a non-indented group
  • dotnet test tests/Paket.Tests/Paket.Tests.fsproj --filter "FullyQualifiedName~AddPackageSpecs|FullyQualifiedName~DependenciesFile" -f net10.0237/237 passed.
  • Full unit test suite (net10.0): 1272 passed, 5 failed, 16 skipped. Verified via git stash that the same 5 failures (proxy-env-var tests and an assembly-metadata-loading test) are pre-existing on master and unrelated to this change.
  • Not run: net461 test pass and integration tests (require Mono, unavailable in this sandbox).

Generated by 🌈 Repo Assist, see workflow run. Learn more.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@ae8d551f07c7ed7619f8c58c7bb4c3ac89395d38

`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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

paket add using groups does not indent when adding to paket.dependecies

0 participants