Skip to content

Commit 2332bf3

Browse files
dschojeffhostetler
authored andcommitted
backwards-compatibility: support the post-indexchanged hook
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).
1 parent 568a40b commit 2332bf3

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

run-command.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,17 @@ int run_hook_strvec(const char *const *env, const char *name,
14181418
const char *p;
14191419

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

t/t7113-post-index-change-hook.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,36 @@ test_expect_success 'setup' '
1515
git commit -m "initial"
1616
'
1717

18+
test_expect_success 'post-indexchanged' '
19+
mkdir -p .git/hooks &&
20+
test_when_finished "rm -f .git/hooks/post-indexchanged marker" &&
21+
write_script .git/hooks/post-indexchanged <<-\EOF &&
22+
: >marker
23+
EOF
24+
25+
: make sure -changed is called if -change does not exist &&
26+
test_when_finished "echo testing >dir1/file2.txt && git status" &&
27+
echo changed >dir1/file2.txt &&
28+
: force index to be dirty &&
29+
test-tool chmtime -60 .git/index &&
30+
git status &&
31+
test_path_is_file marker &&
32+
33+
test_when_finished "rm -f .git/hooks/post-index-change marker2" &&
34+
write_script .git/hooks/post-index-change <<-\EOF &&
35+
: >marker2
36+
EOF
37+
38+
: make sure -changed is not called if -change exists &&
39+
rm -f marker marker2 &&
40+
echo testing >dir1/file2.txt &&
41+
: force index to be dirty &&
42+
test-tool chmtime -60 .git/index &&
43+
git status &&
44+
test_path_is_missing marker &&
45+
test_path_is_file marker2
46+
'
47+
1848
test_expect_success 'test status, add, commit, others trigger hook without flags set' '
1949
mkdir -p .git/hooks &&
2050
write_script .git/hooks/post-index-change <<-\EOF &&

0 commit comments

Comments
 (0)