Skip to content

Commit 41c3d3c

Browse files
committed
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 3c187e8 commit 41c3d3c

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

hook.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options)
178178
.hook_name = hook_name,
179179
.options = options,
180180
};
181-
const char *const hook_path = find_hook(hook_name);
181+
const char *hook_path = find_hook(hook_name);
182182
int ret = 0;
183183
const struct run_process_parallel_opts opts = {
184184
.tr2_category = "hook",
@@ -194,6 +194,18 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options)
194194
.data = &cb_data,
195195
};
196196

197+
/*
198+
* Backwards compatibility hack in VFS for Git: when originally
199+
* introduced (and used!), it was called `post-indexchanged`, but this
200+
* name was changed during the review on the Git mailing list.
201+
*
202+
* Therefore, when the `post-index-change` hook is not found, let's
203+
* look for a hook with the old name (which would be found in case of
204+
* already-existing checkouts).
205+
*/
206+
if (!hook_path && !strcmp(hook_name, "post-index-change"))
207+
hook_path = find_hook("post-indexchanged");
208+
197209
if (!options)
198210
BUG("a struct run_hooks_opt must be provided to run_hooks");
199211

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

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

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

0 commit comments

Comments
 (0)