Skip to content

Commit decf684

Browse files
committed
fsmonitor OSX: fix hangs for submodules
fsmonitor_classify_path_absolute() expects state->path_gitdir_watch.buf has no trailing '/' or '.' For a submodule, fsmonitor_run_daemon() sets the value with trailing "/." (as repo_get_git_dir(the_repository) on Darwin returns ".") so that fsmonitor_classify_path_absolute() returns IS_OUTSIDE_CONE. In this case, fsevent_callback() doesn't update cookie_list so that fsmonitor_publish() does nothing and with_lock__mark_cookies_seen() is not invoked. As with_lock__wait_for_cookie() infinitely waits for state->cookies_cond that with_lock__mark_cookies_seen() should unlock, the whole daemon hangs. Remove trailing "/." from state->path_gitdir_watch.buf for submodules and add a corresponding test in t7527-builtin-fsmonitor.sh. Suggested-by: Johannes Schindelin <[email protected]> Suggested-by: Junio C Hamano <[email protected]> Signed-off-by: Koji Nakamaru <[email protected]>
1 parent 3857aae commit decf684

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

builtin/fsmonitor--daemon.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,7 @@ static int fsmonitor_run_daemon(void)
13141314
strbuf_reset(&state.path_gitdir_watch);
13151315
strbuf_addstr(&state.path_gitdir_watch,
13161316
absolute_path(repo_get_git_dir(the_repository)));
1317+
strbuf_strip_suffix(&state.path_gitdir_watch, "/.");
13171318
state.nr_paths_watching = 2;
13181319
}
13191320

t/t7527-builtin-fsmonitor.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,57 @@ test_expect_success "submodule absorbgitdirs implicitly starts daemon" '
907907
test_subcommand git fsmonitor--daemon start <super-sub.trace
908908
'
909909

910+
start_git_in_background () {
911+
git "$@" &
912+
git_pid=$!
913+
git_pgid=$(ps -o pgid= -p $git_pid)
914+
nr_tries_left=10
915+
while true
916+
do
917+
if test $nr_tries_left -eq 0
918+
then
919+
kill -- -$git_pgid
920+
exit 1
921+
fi
922+
sleep 1
923+
nr_tries_left=$(($nr_tries_left - 1))
924+
done >/dev/null 2>&1 &
925+
watchdog_pid=$!
926+
wait $git_pid
927+
}
928+
929+
stop_git () {
930+
while kill -0 -- -$git_pgid
931+
do
932+
kill -- -$git_pgid
933+
sleep 1
934+
done
935+
}
936+
937+
stop_watchdog () {
938+
while kill -0 $watchdog_pid
939+
do
940+
kill $watchdog_pid
941+
sleep 1
942+
done
943+
}
944+
945+
test_expect_success "submodule implicitly starts daemon by pull" '
946+
test_atexit "stop_watchdog" &&
947+
test_when_finished "stop_git && rm -rf cloned super sub" &&
948+
949+
create_super super &&
950+
create_sub sub &&
951+
952+
git -C super submodule add ../sub ./dir_1/dir_2/sub &&
953+
git -C super commit -m "add sub" &&
954+
git clone --recurse-submodules super cloned &&
955+
956+
git -C cloned/dir_1/dir_2/sub config core.fsmonitor true &&
957+
set -m &&
958+
start_git_in_background -C cloned pull --recurse-submodules
959+
'
960+
910961
# On a case-insensitive file system, confirm that the daemon
911962
# notices when the .git directory is moved/renamed/deleted
912963
# regardless of how it is spelled in the FS event.

0 commit comments

Comments
 (0)