Skip to content

Commit ddfc205

Browse files
committed
settings: Auto-remove repositories from the "Select Repository" dialog
Adjust the settings reader so that it skips over entries that no longer exist. This is done for both bookmarks and the recent repositories list. Closes git-cola#145 Signed-off-by: David Aguilar <davvid@gmail.com>
1 parent c9a79c0 commit ddfc205

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

cola/settings.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
except ImportError:
1111
import json
1212

13+
from cola import core
1314
from cola import xdg
1415

1516

@@ -38,6 +39,32 @@ def __init__(self):
3839
'recent': [],
3940
}
4041
self.load()
42+
self.remove_missing()
43+
44+
45+
def remove_missing(self):
46+
missing_bookmarks = []
47+
missing_recent = []
48+
49+
for bookmark in self.bookmarks:
50+
if not os.path.exists(core.encode(bookmark)):
51+
missing_bookmarks.append(bookmark)
52+
53+
for bookmark in missing_bookmarks:
54+
try:
55+
self.bookmarks.remove(bookmark)
56+
except:
57+
pass
58+
59+
for recent in self.recent:
60+
if not os.path.exists(core.encode(recent)):
61+
missing_recent.append(recent)
62+
63+
for recent in missing_recent:
64+
try:
65+
self.recent.remove(recent)
66+
except:
67+
pass
4168

4269
# properties
4370
def _get_bookmarks(self):

share/doc/git-cola/relnotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
git-cola v1.8.2 (DRAFT)
2+
=======================
3+
Usability, bells and whistles
4+
-----------------------------
5+
* We now automatically remove missing repositories from the
6+
"Select Repository" dialog.
7+
8+
http://github.com/git-cola/git-cola/issues/145
9+
110
git-cola v1.8.1
211
===============
312
Usability, bells and whistles

test/test_cola_settings.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,46 @@ def test_gui_save_restore(self):
3030

3131
def test_bookmarks_save_restore(self):
3232
"""Test the bookmark save/restore feature"""
33+
34+
# We automatically purge missing entries so we mock-out
35+
# os.path.exists so that this bookmark is kept.
36+
37+
bookmark = '/tmp/python/thinks/this/exists'
38+
os_path_exists = os.path.exists
39+
40+
def mock_exists(path):
41+
return path == bookmark or os_path_exists(path)
42+
43+
os.path.exists = mock_exists
44+
3345
model = self.model()
34-
model.add_bookmark('test-bookmark')
46+
model.add_bookmark(bookmark)
3547
model.save()
3648

3749
model = self.model()
50+
os.path.exists = os_path_exists # undo mock
51+
3852
bookmarks = model.bookmarks
3953
self.assertEqual(len(model.bookmarks), 1)
40-
self.assertTrue('test-bookmark' in bookmarks)
54+
self.assertTrue(bookmark in bookmarks)
4155

42-
model.remove_bookmark('test-bookmark')
56+
model.remove_bookmark(bookmark)
4357
bookmarks = model.bookmarks
4458
self.assertEqual(len(bookmarks), 0)
45-
self.assertFalse('test-bookmark' in bookmarks)
59+
self.assertFalse(bookmark in bookmarks)
60+
61+
def test_bookmarks_removes_missing_entries(self):
62+
"""Test that missing entries are removed after a reload"""
63+
bookmark = '/tmp/this/does/not/exist'
64+
model = self.model()
65+
model.add_bookmark(bookmark)
66+
model.save()
67+
68+
model = self.model()
69+
bookmarks = model.bookmarks
70+
self.assertEqual(len(model.bookmarks), 0)
71+
self.assertFalse(bookmark in bookmarks)
72+
4673

4774

4875
if __name__ == '__main__':

0 commit comments

Comments
 (0)