summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authornfnty <git@nfnty.se>2015-10-09 04:47:32 +0200
committernfnty <git@nfnty.se>2016-02-08 04:43:04 +0100
commit8c1403d6533fb8ef3d651ce026f0a92310f65da5 (patch)
tree4c1d738c813bc55bc969d4f2c6024ea41e6cf169 /ranger
parent9645b056c6fc5d1b8882f500ed5e231ed16c02fa (diff)
downloadranger-8c1403d6533fb8ef3d651ce026f0a92310f65da5.tar.gz
VCS: Implement vcs.track
Diffstat (limited to 'ranger')
-rw-r--r--ranger/container/directory.py9
-rw-r--r--ranger/ext/vcs/vcs.py28
-rw-r--r--ranger/gui/widgets/browsercolumn.py16
-rw-r--r--ranger/gui/widgets/statusbar.py14
4 files changed, 32 insertions, 35 deletions
diff --git a/ranger/container/directory.py b/ranger/container/directory.py
index 6d6e3e88..77c2e250 100644
--- a/ranger/container/directory.py
+++ b/ranger/container/directory.py
@@ -306,8 +306,7 @@ class Directory(FileSystemObject, Accumulator, Loadable):
                 files = []
                 disk_usage = 0
 
-                if self.settings.vcs_aware and \
-                        self.vcs.root and not self.vcs.in_repodir:
+                if self.vcs and self.vcs.track:
                     self.vcs.update(self)
 
                 for name in filenames:
@@ -334,8 +333,7 @@ class Directory(FileSystemObject, Accumulator, Loadable):
                             except:
                                 item = Directory(name, preload=stats, path_is_abs=True)
                                 item.load()
-                        if item.settings.vcs_aware and \
-                                item.vcs.root and not item.vcs.in_repodir:
+                        if item.vcs and item.vcs.track:
                             item.vcs.update(item, child=True)
                             if item.vcs.is_root:
                                 self.has_vcschild = True
@@ -344,8 +342,7 @@ class Directory(FileSystemObject, Accumulator, Loadable):
                                     basename_is_rel_to=basename_is_rel_to)
                         item.load()
                         disk_usage += item.size
-                        if self.settings.vcs_aware and \
-                                self.vcs.root and not self.vcs.in_repodir:
+                        if self.vcs and self.vcs.track:
                             item.vcspathstatus = self.vcs.get_status_subpath(item.path)
 
                     files.append(item)
diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py
index 1764122b..ffc581f1 100644
--- a/ranger/ext/vcs/vcs.py
+++ b/ranger/ext/vcs/vcs.py
@@ -74,9 +74,9 @@ class Vcs(object):
             repotype for repotype, setting in \
             (
                 ('git', directoryobject.settings.vcs_backend_git),
-                ('hg', directoryobject.settings.vcs_backend_git),
-                ('bzr', directoryobject.settings.vcs_backend_git),
-                ('svn', directoryobject.settings.vcs_backend_git),
+                ('hg', directoryobject.settings.vcs_backend_hg),
+                ('bzr', directoryobject.settings.vcs_backend_bzr),
+                ('svn', directoryobject.settings.vcs_backend_svn),
             )
             if setting in ('enabled', 'local')
         ]
@@ -90,19 +90,19 @@ class Vcs(object):
         self.is_root = True if self.path == self.root else False
 
         if self.root:
+            self.track = True
+            self.__class__ = self.repotypes[self.repotype]
+
+            if not os.access(self.repodir, os.R_OK):
+                self.track = False
+                if self.is_root:
+                    directoryobject.vcspathstatus = 'unknown'
+                    self.remotestatus = 'unknown'
             # Do not track self.repodir or its subpaths
             if self.path == self.repodir or self.path.startswith(self.repodir + '/'):
-                self.in_repodir = True
-            else:
-                self.in_repodir = False
-
-            if self.is_root:
-                self.root = self.path
-                self.__class__ = self.repotypes[self.repotype]
-            else:
-                root = directoryobject.fm.get_directory(self.root)
-                self.repotype = root.vcs.repotype
-                self.__class__ = root.vcs.__class__
+                self.track = False
+        else:
+            self.track = False
 
     # Auxiliar
     #---------------------------
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index 50bf2e2f..dc2c193e 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -258,7 +258,7 @@ class BrowserColumn(Pager):
             key = (self.wid, selected_i == i, drawn.marked, self.main_column,
                     drawn.path in copied, tagged_marker, drawn.infostring,
                     drawn.vcspathstatus,
-                    drawn.vcs.remotestatus if drawn.is_directory and drawn.vcs.is_root else None,
+                    drawn.vcs.remotestatus if drawn.is_directory and drawn.vcs and drawn.vcs.is_root else None,
                     self.fm.do_cut,
                     current_linemode.name, metakey)
 
@@ -375,18 +375,20 @@ class BrowserColumn(Pager):
     def _draw_vcsstring_display(self, drawn):
         vcsstring_display = []
         directory = drawn if drawn.is_directory else self.target
-        if self.settings.vcs_aware and directory.vcs.root:
-            if drawn.vcspathstatus:
-                vcsstr, vcscol = self.vcspathstatus_symb[drawn.vcspathstatus]
-                vcsstring_display.append([vcsstr, ['vcsfile'] + vcscol])
-            else:
-                vcsstring_display.append([" ", []])
+        if directory.vcs and \
+                (directory.vcs.track or (drawn.is_directory and drawn.vcs.is_root)):
             if drawn.is_directory and drawn.vcs.remotestatus:
                 vcsstr, vcscol = self.vcsremotestatus_symb[drawn.vcs.remotestatus]
                 vcsstring_display.append([vcsstr, ['vcsremote'] + vcscol])
             else:
                 if self.target.has_vcschild:
                     vcsstring_display.insert(-1, [" ", []])
+            if drawn.vcspathstatus:
+                vcsstr, vcscol = self.vcspathstatus_symb[drawn.vcspathstatus]
+                vcsstring_display.append([vcsstr, ['vcsfile'] + vcscol])
+            else:
+                vcsstring_display.append([" ", []])
+
         elif self.target.has_vcschild:
             vcsstring_display.append(["  ", []])
 
diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py
index 8e5b0376..20875ac9 100644
--- a/ranger/gui/widgets/statusbar.py
+++ b/ranger/gui/widgets/statusbar.py
@@ -181,16 +181,14 @@ class StatusBar(Widget):
             left.add(strftime(self.timeformat,
                     localtime(stat.st_mtime)), 'mtime')
 
-        if target.settings.vcs_aware:
-            if target.is_directory and target.vcs.root:
-                directory = target
-            else:
-                directory = target.fm.get_directory(os.path.dirname(target.path))
+        directory = target if target.is_directory else \
+            target.fm.get_directory(os.path.dirname(target.path))
 
+        if directory.vcs and directory.vcs.track:
             if directory.vcs.branch:
-                vcsinfo = '(%s: %s)' % (directory.vcs.vcsname, directory.vcs.branch)
+                vcsinfo = '(%s: %s)' % (directory.vcs.repotype, directory.vcs.branch)
             else:
-                vcsinfo = '(%s)' % (directory.vcs.vcsname)
+                vcsinfo = '(%s)' % (directory.vcs.repotype)
 
             left.add_space()
             left.add(vcsinfo, 'vcsinfo')
@@ -199,7 +197,7 @@ class StatusBar(Widget):
                 left.add_space()
                 vcsstr, vcscol = self.vcspathstatus_symb[target.vcspathstatus]
                 left.add(vcsstr.strip(), 'vcsfile', *vcscol)
-            if directory.vcs.remotestatus:
+            if target.is_directory and target.vcs.is_root and directory.vcs.remotestatus:
                 vcsstr, vcscol = self.vcsremotestatus_symb[directory.vcs.remotestatus]
                 left.add(vcsstr.strip(), 'vcsremote', *vcscol)
             if directory.vcs.head: