Skip to content

Commit 31d0210

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 98fabc5 commit 31d0210

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

Diff for: hook.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ int run_hooks_opt(struct repository *r, const char *hook_name,
194194
.hook_name = hook_name,
195195
.options = options,
196196
};
197-
const char *const hook_path = find_hook(r, hook_name);
197+
const char *hook_path = find_hook(r, hook_name);
198198
int ret = 0;
199199
const struct run_process_parallel_opts opts = {
200200
.tr2_category = "hook",
@@ -210,6 +210,18 @@ int run_hooks_opt(struct repository *r, const char *hook_name,
210210
.data = &cb_data,
211211
};
212212

213+
/*
214+
* Backwards compatibility hack in VFS for Git: when originally
215+
* introduced (and used!), it was called `post-indexchanged`, but this
216+
* name was changed during the review on the Git mailing list.
217+
*
218+
* Therefore, when the `post-index-change` hook is not found, let's
219+
* look for a hook with the old name (which would be found in case of
220+
* already-existing checkouts).
221+
*/
222+
if (!hook_path && !strcmp(hook_name, "post-index-change"))
223+
hook_path = find_hook(r, "post-indexchanged");
224+
213225
if (!options)
214226
BUG("a struct run_hooks_opt must be provided to run_hooks");
215227

Diff for: t/t7113-post-index-change-hook.sh

+30
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
test_hook post-index-change <<-\EOF &&
2050
if test "$1" -eq 1; then

0 commit comments

Comments
 (0)