Skip to content

Commit

Permalink
backwards-compatibility: support the post-indexchanged hook
Browse files Browse the repository at this point in the history
When our patches to support that hook were upstreamed, the hook's name
was eliciting some reviewer suggestions, and it was renamed to
`post-index-change`. These patches (with the new name) made it into
v2.22.0.

However, VFSforGit users may very well have checkouts with that hook
installed under the original name.

To support this, let's just introduce a hack where we look a bit more
closely when we just failed to find the `post-index-change` hook, and
allow any `post-indexchanged` hook to run instead (if it exists).
  • Loading branch information
dscho authored and derrickstolee committed Oct 30, 2021
1 parent e59e3f6 commit 165711c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions run-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,17 @@ int run_hook_strvec(const char *const *env, const char *name,
const char *p;

p = find_hook(name);
/*
* Backwards compatibility hack in VFS for Git: when originally
* introduced (and used!), it was called `post-indexchanged`, but this
* name was changed during the review on the Git mailing list.
*
* Therefore, when the `post-index-change` hook is not found, let's
* look for a hook with the old name (which would be found in case of
* already-existing checkouts).
*/
if (!p && !strcmp(name, "post-index-change"))
p = find_hook("post-indexchanged");
if (!p)
return 0;

Expand Down
30 changes: 30 additions & 0 deletions t/t7113-post-index-change-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@ test_expect_success 'setup' '
git commit -m "initial"
'

test_expect_success 'post-indexchanged' '
mkdir -p .git/hooks &&
test_when_finished "rm -f .git/hooks/post-indexchanged marker" &&
write_script .git/hooks/post-indexchanged <<-\EOF &&
: >marker
EOF
: make sure -changed is called if -change does not exist &&
test_when_finished "echo testing >dir1/file2.txt && git status" &&
echo changed >dir1/file2.txt &&
: force index to be dirty &&
test-tool chmtime -60 .git/index &&
git status &&
test_path_is_file marker &&
test_when_finished "rm -f .git/hooks/post-index-change marker2" &&
write_script .git/hooks/post-index-change <<-\EOF &&
: >marker2
EOF
: make sure -changed is not called if -change exists &&
rm -f marker marker2 &&
echo testing >dir1/file2.txt &&
: force index to be dirty &&
test-tool chmtime -60 .git/index &&
git status &&
test_path_is_missing marker &&
test_path_is_file marker2
'

test_expect_success 'test status, add, commit, others trigger hook without flags set' '
mkdir -p .git/hooks &&
write_script .git/hooks/post-index-change <<-\EOF &&
Expand Down

0 comments on commit 165711c

Please sign in to comment.