Add ability to run on a remote root based on the config file.
[update-copyright.git] / update_copyright / vcs / __init__.py
index 17281ab34886b293db1d4cacc54c24cd40568b36..8b589080cb0ff182286cc424811d6c8aa78a9fd8 100644 (file)
 
 """Backends for version control systems."""
 
+import os.path as _os_path
+
 from . import utils as _utils
 
 
 class VCSBackend (object):
     name = None
 
-    def __init__(self, author_hacks=None, year_hacks=None, aliases=None):
+    def __init__(self, root='.', author_hacks=None, year_hacks=None,
+                 aliases=None):
+        self._root = root
         if author_hacks is None:
             author_hacks = {}
         self._author_hacks = author_hacks
@@ -42,8 +46,10 @@ class VCSBackend (object):
         years = self._years(filename=filename)
         if filename is None:
             years.update(self._year_hacks.values())
-        elif _utils.splitpath(filename) in self._year_hacks:
-            years.add(self._year_hacks[_utils.splitpath(filename)])
+        else:
+            filename = _os_path.relpath(filename, self._root)
+            if _utils.splitpath(filename) in self._year_hacks:
+                years.add(self._year_hacks[_utils.splitpath(filename)])
         years = sorted(years)
         return years[0]