Skip to content

Commit 43952a7

Browse files
dscholdennington
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 77c2f79 commit 43952a7

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

run-command.c

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

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

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
mkdir -p .git/hooks &&
2151
write_script .git/hooks/post-index-change <<-\EOF &&

0 commit comments

Comments
 (0)