Ver a proveniência

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.
pull/93/head
dajiaohuang há 3 dias
ascendente
cometimento
680a635a4b
2 ficheiros alterados com 31 adições e 1 eliminações
  1. +5
    -1
      src/gitup/config.py
  2. +26
    -0
      src/gitup/test/test_bookmarks.py

+ 5
- 1
src/gitup/config.py Ver ficheiro

@@ -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.")


+ 26
- 0
src/gitup/test/test_bookmarks.py Ver ficheiro

@@ -3,6 +3,8 @@
# Copyright (C) 2011-2018 Ben Kurtovic <ben.kurtovic@gmail.com>
# 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

Carregando…
Cancelar
Guardar