feat: add staged property to custom variables for re-staging support#163
Merged
alirezanet merged 3 commits intomasterfrom Mar 11, 2026
Merged
feat: add staged property to custom variables for re-staging support#163alirezanet merged 3 commits intomasterfrom
staged property to custom variables for re-staging support#163alirezanet merged 3 commits intomasterfrom
Conversation
Copilot
AI
changed the title
[WIP] Add Csharpier pre commit hook with custom variable
feat: add Mar 11, 2026
staged property to custom variables for re-staging support
alirezanet
requested changes
Mar 11, 2026
Owner
alirezanet
left a comment
There was a problem hiding this comment.
we need more Unit tests and Integration tests to make sure this would work as expected.
also we should test the existing behavior if it is not provided.
…integration tests
Contributor
Author
Added in commit
|
11 tasks
This was referenced Mar 11, 2026
This was referenced Mar 13, 2026
This was referenced Mar 21, 2026
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.
Custom variables in
task-runner.jsondon't re-stage formatted files after a task runs in a pre-commit hook — unlike the built-in${staged}variable. This is because custom variable files are taggedArgumentTypes.CustomVariable, causing a plainExecutableTaskto be created instead of aStagedTask.Description
A new
stagedboolean property has been added to custom variable definitions. When set totrue, files returned by the custom variable are treated as staged files, enabling the same re-staging behavior as the built-in${staged}variable (including partial staging support).The
stagedproperty is scoped exclusively to a new dedicatedHuskyVariablemodel — it is not part of the generalHuskyTaskmodel used for task definitions — keeping the API clean and purpose-specific.Changes
HuskyVariable(new model) — Dedicated class for custom variable definitions (Name,Command,Args,Cwd,Staged). Replaces the use ofHuskyTaskfor variable loading inArgumentParser.ArgumentParser.AddCustomVariable()— When the variable hasstaged: true, tags output files asArgumentTypes.StagedFileinstead ofArgumentTypes.CustomVariable, triggering the existingStagedTaskmachinery (re-staging, partial staging, etc.).Utils.GetTaskCwdAsync()— Added overload acceptingHuskyVariable.schema.json— Addedstaged(boolean, default:false) andcwdproperties to thevariableTaskdefinition.docs/guide/task-configuration.md— Documents the newstagedproperty with a CSharpier-style example.ArgumentParserTests) — 4 tests coveringstaged: true→StagedFileargument type,staged: false→CustomVariabletype, nostagedproperty (default) →CustomVariabletype, and unknown variable → empty args.StagedCustomVariableTests) — 4 Docker-based tests verifying real behavior: staged variable with matching files executes and re-stages, non-staged variable works normally, and both skip correctly when no matching files are staged.Usage
{ "variables": [ { "name": "staged-diff-files", "command": "git", "args": ["diff", "--cached", "--name-only", "--no-ext-diff", "--diff-filter=ACMRTUXB"], "staged": true } ], "tasks": [ { "name": "Run csharpier", "group": "pre-commit", "command": "dotnet", "args": ["csharpier", "${staged-diff-files}"], "include": ["**/*.cs"] } ] }Non-breaking — existing custom variables without
"staged": trueare unaffected.Type of change
Checklist
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.