Fix: re-stage files after task when using ${staged:separator}#173
Draft
mvanhilst-msft wants to merge 4 commits intoalirezanet:masterfrom
Draft
Fix: re-stage files after task when using ${staged:separator}#173mvanhilst-msft wants to merge 4 commits intoalirezanet:masterfrom
${staged:separator}#173mvanhilst-msft wants to merge 4 commits intoalirezanet:masterfrom
Conversation
Owner
|
Hi @mvanhilst-msft, |
…r re-staging) Add 3 integration tests: - StagedSeparator_FormattedChanges_ShouldBeCommitted: verifies re-stages formatted files before commit - StagedSeparator_MultipleFiles_FormattedChanges_ShouldAllBeCommitted: same for multiple files - StagedWithoutSeparator_FormattedChanges_ShouldBeCommitted: control test confirming (no separator) works correctly Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Description
Fixes #172
This is what Claude Opus 4.6 thought would be a good fix for this issue. I'm putting this here as a draft to save you some time/tokens if it helps. No need to merge this PR.
Problem
When a task uses
${staged:;}(the separator variant), files modified by the task are never re-staged before the commit is finalized. The commit records the original unformatted content, and formatting changes are left as unstaged modifications.This is because
AddStaticMatchedFilescreates a singleArgumentInfo(ArgumentTypes.Static, ...)for the combined string (e.g.,--include=file1;file2). TheExecutableTaskFactoryonly routes toStagedTask— which contains the re-staging logic — when it findsArgumentTypes.StagedFileentries, so the${staged:;}path always gets a plainExecutableTaskwith no re-staging.Solution
Track individual staged files as metadata alongside the combined static argument. A new
ExcludeFromCommandArgsflag onArgumentInfodistinguishes these tracking entries from actual command-line arguments, so they inform theStagedTaskrouting and re-staging logic without being passed to the child process.Changes
ArgumentInfo.cs— AddedExcludeFromCommandArgsproperty (defaults tofalsefor backward compatibility). Whentrue, the entry is metadata-only and excluded from the process command line.FileArgumentInfo.cs— Propagates the newexcludeFromCommandArgsparameter to the base constructor.ArgumentParser.cs—AddStagedFilesnow callsAddMatchedFileswithexcludeFromCommandArgs: trueafterAddStaticMatchedFiles, emitting hiddenFileArgumentInfo(StagedFile)tracking entries for each matched file.AddMatchedFilesaccepts the new optional parameter and passes it through toFileArgumentInfo.ExecutableTaskFactory.cs— FiltersExcludeFromCommandArgsentries when building the command-linestring[]forTaskInfo.Arguments, and when computing total command length for chunk decisions. Chunk creation separates tracking args from command args, appending tracking entries to each chunk's metadata soStagedTaskrouting still works.StagedTask.cs— AddedcanPartialExecutecheck: when all staged file entries are tracking-only (from${staged:;}where files are embedded in a combined argument), partial execution via temp-file swapping is skipped since it requires individual file arguments. In this case, all staged files are re-staged after task execution.Tests
Five new unit tests in
ArgumentParserTests.cs:ParseAsync_WithStagedVariable_NoSeparator_ReturnsStagedFileArgumentType${staged}still producesStagedFileargs (regression guard)ParseAsync_WithStagedSeparator_ProducesBothStaticAndStagedFileTracking${staged:;}produces the combinedStaticarg and hiddenStagedFiletracking entriesParseAsync_WithStagedSeparator_StagedEntriesHaveCorrectRelativePathsgit addParseAsync_WithStagedSeparator_ResultContainsStagedFileType_EnablingRestagingRouteStagedFiletype, enablingStagedTaskrouting in the factoryParseAsync_WithStagedSeparator_NoMatchingFiles_ReturnsOnlyStaticArgs.csfiles → noStagedFileentries, only static argsManual verification
Tested end-to-end with
jb cleanupcodeand a.csfile with deliberate formatting issues:Type of change
Checklist