forked from git-for-windows/git
-
Notifications
You must be signed in to change notification settings - Fork 106
Update behavior for postCommand.strategy=post-index-change #748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dscho
merged 5 commits into
microsoft:vfs-2.49.0
from
derrickstolee:post-command-strategy
May 7, 2025
Merged
Update behavior for postCommand.strategy=post-index-change #748
dscho
merged 5 commits into
microsoft:vfs-2.49.0
from
derrickstolee:post-command-strategy
May 7, 2025
Conversation
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
This change to use the 'info/' directory instead of the 'hooks/' directory is important because the hooks dir could be redirected to the source tree. Modify the test in such a way that this code change would fail due to being unable to write to the internal hooks directory. Signed-off-by: Derrick Stolee <stolee@gmail.com>
Before making the post-index-change logic more advanced for the postCommand.strategy=post-index-change feature, extract the code into a new method that will be easier to update in the future. Signed-off-by: Derrick Stolee <stolee@gmail.com>
The postCommand.strategy=post-index-change config was designed to replace some internal hook usage. This internal hook was more restrictive than the initial feature was designed. Specifically, it ignored index updates that did not update the worktree. With the existing implementation, this causes more work done in the post-command hook than intended. Update the code to write a sentinel file only when the worktree is changed. Signed-off-by: Derrick Stolee <stolee@gmail.com>
dscho
previously approved these changes
May 7, 2025
Member
dscho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, and since the feature is young enough, I have no objection to that minor behavior change.
The previously-named 'post-index-change' value for
'postCommand.strategy' did the following two things:
1. Avoid running the post-command hook unless the post-index-change
hook _would_ run with a signal that the worktree changed.
2. Avoid running any installed post-index-change hooks.
The additional restriction of the worktree change in (1) makes this name
less appropriate. Also, item (2) seems to be a side-effect that we
should avoid. We would like to allow both behaviors to exist.
Update the value and behavior, including the tests.
Signed-off-by: Derrick Stolee <stolee@gmail.com>
dscho
previously approved these changes
May 7, 2025
Now that we don't skip the post-index-change hook, we don't need to pass the return value as an out-parameter in this method. Signed-off-by: Derrick Stolee <stolee@gmail.com>
dscho
approved these changes
May 7, 2025
1 task
derrickstolee
added a commit
that referenced
this pull request
Nov 10, 2025
The postCommand.strategy=worktree-change config option allows for skipping the post-command hook when the Git command doesn't change the worktree. However, sometimes this config isn't loaded before the post-command hook is invoked, causing the hook to run in cases where we'd prefer it to not run. Examples include: `git version` or `git <typo>`. The tricky bit is that there are several places where we get here and standard config mechanisms can't load due to not having a `gitdir` in the repository struct. We fix this by: 1. Using the "load early config" mechanism also used by `core.hooksPath`. 2. Skipping the lookup for the sentinel file when there isn't a `gitdir` since we couldn't have written one without it. The change is given in two commits: the first expands the tests with the existing behavior and the second changes the behavior, showing the impact on those tests. * [X] This change only applies to microsoft/git specifics (post-command hook) See #736 and #748 for prior art in this space.
dscho
pushed a commit
that referenced
this pull request
Nov 10, 2025
The postCommand.strategy=worktree-change config option allows for skipping the post-command hook when the Git command doesn't change the worktree. However, sometimes this config isn't loaded before the post-command hook is invoked, causing the hook to run in cases where we'd prefer it to not run. Examples include: `git version` or `git <typo>`. The tricky bit is that there are several places where we get here and standard config mechanisms can't load due to not having a `gitdir` in the repository struct. We fix this by: 1. Using the "load early config" mechanism also used by `core.hooksPath`. 2. Skipping the lookup for the sentinel file when there isn't a `gitdir` since we couldn't have written one without it. The change is given in two commits: the first expands the tests with the existing behavior and the second changes the behavior, showing the impact on those tests. * [X] This change only applies to microsoft/git specifics (post-command hook) See #736 and #748 for prior art in this space.
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 feature was introduced in #736 but had a few pain points that were discovered when testing the full replacement of the existing post-index-change and post-command hooks in our internal environment:
core.hooksPathto point to a directory within the worktree, the sentinel files were being written into the worktree. Write to$GITDIR/info/instead.Tests are added to confirm both of these behavior changes.