Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions mkdocs/livereload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ def watch(self, path: str, func: None = None, *, recursive: bool = True) -> None
def callback(event):
if event.is_directory:
return
# Ignore hidden files and editor temporary/backup files:
# - .dotfiles (vim swap .foo.md.swp, .foo.md.swo, .foo.md.swn, etc.)
# - files ending with ~ (editor backup)
# - #files# matching Emacs auto-save pattern
name = os.path.basename(event.src_path)
if (
name.startswith(".")
or name.endswith("~")
or (name.startswith("#") and name.endswith("#"))
):
return
log.debug(str(event))
with self._rebuild_cond:
self._want_rebuild = True
Expand Down
40 changes: 40 additions & 0 deletions mkdocs/tests/livereload_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,46 @@ def test_watches_through_relative_symlinks(self, origin_dir, site_dir):
Path(origin_dir, "README.md").write_text("edited")
self.assertTrue(started_building.wait(timeout=10))

@tempdir({"foo.md": "original"})
def test_ignores_dotfile_changes(self, docs_dir):
"""Hidden files (starting with '.') should not trigger rebuild."""
started_building = threading.Event()
with testing_server(docs_dir, started_building.set) as server:
server.watch(docs_dir)
time.sleep(0.01)

# Vim swap file
Path(docs_dir, ".foo.md.swp").write_text("swap")
self.assertFalse(started_building.wait(timeout=0.5))

# Generic dotfile
Path(docs_dir, ".hidden").write_text("hidden")
self.assertFalse(started_building.wait(timeout=0.5))

@tempdir({"foo.md": "original"})
def test_ignores_tilde_backup_files(self, docs_dir):
"""Editor backup files (ending with '~') should not trigger rebuild."""
started_building = threading.Event()
with testing_server(docs_dir, started_building.set) as server:
server.watch(docs_dir)
time.sleep(0.01)

# Backup file created by editors
Path(docs_dir, "foo.md~").write_text("backup")
self.assertFalse(started_building.wait(timeout=0.5))

@tempdir({"foo.md": "original"})
def test_ignores_emacs_autosave_files(self, docs_dir):
"""Emacs auto-save files (#*#) should not trigger rebuild."""
started_building = threading.Event()
with testing_server(docs_dir, started_building.set) as server:
server.watch(docs_dir)
time.sleep(0.01)

# Emacs auto-save pattern
Path(docs_dir, "#foo.md#").write_text("autosave")
self.assertFalse(started_building.wait(timeout=0.5))

@tempdir()
def test_watch_with_broken_symlinks(self, docs_dir):
Path(docs_dir, "subdir").mkdir()
Expand Down
Loading