Commit c1ce5ba8 authored by Peter Tyser's avatar Peter Tyser Committed by Kai Willadsen

vc: Add ability to check if version control repos are valid

Sometimes meld may be ran in a directory that contains invalid or
corrupt version control information.  (eg run 'mkdir .svn; meld .' in a
git repository).  Previously meld would not gracefully handle invalid
repositories.  This patch attempts to add a quick sanity check
to most version control systems.  The checks are meant to be
as quick as possible to reduce startup time.
Signed-off-by: 's avatarPeter Tyser <ptyser@gmail.com>
parent c9131582
......@@ -141,6 +141,10 @@ class Vc(object):
def listdir_filter(self, entries):
return [f for f in entries if f != self.VC_DIR]
# Determine if a directory is a valid git/svn/hg/cvs/etc repository
def valid_repo(self):
return True
def listdir(self, start):
if start=="": start="."
cfiles = []
......
......@@ -57,6 +57,11 @@ class Vc(_vc.CachedVc):
return [self.CMD] + self.CMDARGS + ["revert"]
def resolved_command(self):
return [self.CMD] + self.CMDARGS + ["resolve"]
def valid_repo(self):
if _vc.call([self.CMD, "check"]):
return False
else:
return True
def get_working_directory(self, workdir):
return self.root
......
......@@ -49,6 +49,11 @@ class Vc(_vc.Vc):
return [self.CMD,"rm","-f"]
def revert_command(self):
return [self.CMD,"update","-C"]
def valid_repo(self):
if _vc.call([self.CMD, "version"]):
return False
else:
return True
def _get_dirsandfiles(self, directory, dirs, files):
......
......@@ -70,6 +70,12 @@ class Vc(_vc.CachedVc):
# untested
return [self.CMD, "resolve"]
def valid_repo(self):
if _vc.call([self.CMD, "query", "tags"]):
return False
else:
return True
def get_working_directory(self, workdir):
return self.root
......
......@@ -66,6 +66,11 @@ class Vc(_vc.CachedVc):
return [self.CMD,"rm"]
def revert_command(self):
return [self.CMD,"checkout"]
def valid_repo(self):
if _vc.call([self.CMD, "branch"]):
return False
else:
return True
def get_working_directory(self, workdir):
if workdir.startswith("/"):
return self.root
......
......@@ -59,6 +59,11 @@ class Vc(_vc.Vc):
return [self.CMD,"rm"]
def revert_command(self):
return [self.CMD,"revert"]
def valid_repo(self):
if _vc.call([self.CMD, "root"]):
return False
else:
return True
def get_working_directory(self, workdir):
return self.root
......
......@@ -143,6 +143,11 @@ class Vc(_vc.CachedVc):
return [self.CMD,"revert"]
def resolved_command(self):
return [self.CMD,"resolved"]
def valid_repo(self):
if _vc.call([self.CMD, "list", "tags"]):
return False
else:
return True
def get_working_directory(self, workdir):
return self.root
......
......@@ -63,6 +63,11 @@ class Vc(_vc.Vc):
return [self.CMD,"revert"]
def resolved_command(self):
return [self.CMD,"resolved"]
def valid_repo(self):
if _vc.call([self.CMD, "info"]):
return False
else:
return True
def _get_matches(self, directory):
"""return a list of tuples (file_path, status_code, revision)"""
......
......@@ -85,6 +85,12 @@ class Vc(_vc.CachedVc):
# Will only work on later versions of tla
return [self.CMD, "undo", "--"]
def valid_repo(self):
if _vc.call([self.CMD, "tree-version"]):
return False
else:
return True
def get_working_directory(self, workdir):
return self.root
......
......@@ -233,17 +233,23 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
default_active = 0
# Try to keep the same VC plugin active on refresh()
for idx, avc in enumerate(vcs):
if (self.vc is not None and
self.vc.__class__ == avc.__class__):
default_active = idx
# See if the necessary version control command exists. If not,
# make the version control choice non-selectable.
# See if the necessary version control command exists. If so,
# make sure what we're diffing is a valid respository. If either
# check fails don't let the user select the that version control
# tool and display a basic error message in the drop-down menu.
err_str = ""
if vc._vc.call(["which", avc.CMD]):
# TRANSLATORS: this is an error message when a version control
# application isn't installed or can't be found
err_str = _("%s Not Installed" % avc.CMD)
elif not avc.valid_repo():
# TRANSLATORS: this is an error message when a version
# controlled repository is invalid or corrupted
err_str = _("Invalid Repository")
else:
if (self.vc is not None and
self.vc.__class__ == avc.__class__):
default_active = idx
if err_str:
self.combobox_vcs.get_model().append( \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment