Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

settings: Tighten the "repo exists" check

Instead of checking for existence, check that the bookmarked or recent-
repositories list contains git worktrees only.

Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information...
commit 0399e3af734ba67fd1bd1791695c93c0f0bbdcb8 1 parent ddfc205
@davvid davvid authored
Showing with 16 additions and 13 deletions.
  1. +4 −0 cola/git.py
  2. +5 −3 cola/settings.py
  3. +7 −10 test/test_cola_settings.py
View
4 cola/git.py
@@ -34,6 +34,10 @@ def is_git_file(f):
return os.path.isfile(f) and '.git' == os.path.basename(f)
+def is_git_worktree(d):
+ return is_git_dir(os.path.join(d, '.git'))
+
+
def read_git_file(f):
if f is None:
return None
View
8 cola/settings.py
@@ -11,6 +11,7 @@
import json
from cola import core
+from cola import git
from cola import xdg
@@ -31,13 +32,14 @@ def mklist(obj):
class Settings(object):
_file = xdg.config_home('settings')
- def __init__(self):
+ def __init__(self, verify=git.is_git_worktree):
"""Load existing settings if they exist"""
self.values = {
'bookmarks': [],
'gui_state': {},
'recent': [],
}
+ self.verify = verify
self.load()
self.remove_missing()
@@ -47,7 +49,7 @@ def remove_missing(self):
missing_recent = []
for bookmark in self.bookmarks:
- if not os.path.exists(core.encode(bookmark)):
+ if not self.verify(core.encode(bookmark)):
missing_bookmarks.append(bookmark)
for bookmark in missing_bookmarks:
@@ -57,7 +59,7 @@ def remove_missing(self):
pass
for recent in self.recent:
- if not os.path.exists(core.encode(recent)):
+ if not self.verify(core.encode(recent)):
missing_recent.append(recent)
for recent in missing_recent:
View
17 test/test_cola_settings.py
@@ -1,6 +1,7 @@
import unittest
import os
+from cola import git
from cola import settings
import helper
@@ -14,8 +15,8 @@ def tearDown(self):
if os.path.exists(self._file):
os.remove(self._file)
- def model(self):
- return settings.Settings()
+ def model(self, **kwargs):
+ return settings.Settings(**kwargs)
def test_gui_save_restore(self):
"""Test saving and restoring gui state"""
@@ -32,22 +33,18 @@ def test_bookmarks_save_restore(self):
"""Test the bookmark save/restore feature"""
# We automatically purge missing entries so we mock-out
- # os.path.exists so that this bookmark is kept.
+ # git.is_git_worktree() so that this bookmark is kept.
bookmark = '/tmp/python/thinks/this/exists'
- os_path_exists = os.path.exists
- def mock_exists(path):
- return path == bookmark or os_path_exists(path)
-
- os.path.exists = mock_exists
+ def mock_verify(path):
+ return path == bookmark
model = self.model()
model.add_bookmark(bookmark)
model.save()
- model = self.model()
- os.path.exists = os_path_exists # undo mock
+ model = self.model(verify=mock_verify)
bookmarks = model.bookmarks
self.assertEqual(len(model.bookmarks), 1)
Please sign in to comment.
Something went wrong with that request. Please try again.