Skip to content

Commit 4451a05

Browse files
dschoderrickstolee
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 b99bb74 commit 4451a05

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
@@ -1407,6 +1407,17 @@ int run_hook_argv(const char *const *env, const char *name,
14071407
const char *p;
14081408

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

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,36 @@ test_expect_success 'setup' '
1212
git commit -m "initial"
1313
'
1414

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

0 commit comments

Comments
 (0)