From 680a635a4b4303e5947ecec55a44b09f7e18a862 Mon Sep 17 00:00:00 2001 From: dajiaohuang <108231307+dajiaohuang@users.noreply.github.com> Date: Mon, 19 Oct 2026 01:18:50 +0800 Subject: [PATCH] Preserve comment lines when cleaning bookmarks gitup --clean (--cleanup) deletes bookmarks that no longer exist, but it also removed comment lines from the bookmarks file, which are a supported feature since v0.5.1. Skip lines beginning with '#' in the cleanup check so they survive, matching the comment handling used when updating. --- src/gitup/config.py | 6 +++++- src/gitup/test/test_bookmarks.py | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/gitup/config.py b/src/gitup/config.py index c3e6bed..1124cbb 100644 --- a/src/gitup/config.py +++ b/src/gitup/config.py @@ -147,7 +147,11 @@ def clean_bookmarks(config_path=None): delete = [ path for path in bookmarks - if not (os.path.isdir(path) or glob(os.path.expanduser(path))) + if not ( + path.lstrip().startswith("#") + or os.path.isdir(path) + or glob(os.path.expanduser(path)) + ) ] if not delete: print("All of your bookmarks are valid.") diff --git a/src/gitup/test/test_bookmarks.py b/src/gitup/test/test_bookmarks.py index c051432..9f64ac2 100644 --- a/src/gitup/test/test_bookmarks.py +++ b/src/gitup/test/test_bookmarks.py @@ -3,6 +3,8 @@ # Copyright (C) 2011-2018 Ben Kurtovic # Released under the terms of the MIT License. See LICENSE for details. +import os + from gitup import config @@ -11,3 +13,27 @@ def test_empty_list(tmpdir, capsys): config.list_bookmarks(config_path) captured = capsys.readouterr() assert captured.out == "You have no bookmarks to display.\n" + + +def test_clean_bookmarks_preserves_comments(tmpdir, capsys): + """Comments in the bookmarks file must survive a cleanup.""" + repo_dir = tmpdir / "repo" + os.makedirs(os.fspath(repo_dir)) + missing_dir = tmpdir / "missing" + + config_path = tmpdir / "config" + comment = "# a comment line" + lines = [comment, os.fspath(repo_dir), os.fspath(missing_dir)] + with open(os.fspath(config_path), "wb") as handle: + handle.write("\n".join(lines).encode("utf8")) + + config.clean_bookmarks(config_path) + + remaining = config_path.read_binary().decode("utf8").split("\n") + assert comment in remaining + assert os.fspath(repo_dir) in remaining + assert os.fspath(missing_dir) not in remaining + + captured = capsys.readouterr() + assert "Deleted bookmarks:" in captured.out + assert os.fspath(missing_dir) in captured.out