1. Trent Mick
  2. sandbox

Commits

Trent Mick  committed b14620f

add git support to `vc` tool

  • Participants
  • Parent commits 9b90f5a
  • Branches default

Comments (0)

Files changed (1)

File tools/vc.py

View file
  • Ignore whitespace
         return cwd_bits[:len(source_dir_bits)] == source_dir_bits
 
 
+class GitSource(Source):
+    type = 'git'
+    def _parse_config_line(self, config_line):
+        self.url = config_line.strip()
+    def __repr__(self):
+        return "<git: %s>" % self.url
+    @property
+    def desc(self):
+        return self.url
+    def update(self, path):
+        assert not path.startswith("~")
+        _run('git pull "%s"' % path, log.debug)
+    def checkout(self, path):
+        xlocal_path = expanduser(self.local_path)
+        xpath = _relpath(xlocal_path)
+        if xpath.startswith(".."):
+            xpath = xlocal_path
+        _run('git clone %s "%s"' % (self.url, xpath), log.debug)
+    def diff(self, path):
+        assert not path.startswith("~")
+        _run('git diff "%s"' % path, log.debug)
+    def status(self, path, show_updates=False, verbose=False):
+        assert not path.startswith("~")
+        opts = []
+        if verbose: opts.append("--uall")
+        opts = opts and (' ' + ' '.join(opts)) or ''
+        _run('git status%s "%s"' % (opts, path), log.debug)
+        if show_updates:
+            _run_in_dir('hg incoming', path, log.debug)
+    def changes(self, path, show_diffs=False):
+        assert not path.startswith("~")
+        opts = []
+        if show_diffs: opts.append("-p")
+        opts = opts and (' ' + ' '.join(opts)) or ''
+        _run('git log%s "%s"' % (opts, path), log.debug)
+
 class HGSource(Source):
     type = 'hg'
     def _parse_config_line(self, config_line):
             if not isabs(xpath):
                 raise VCError("%s: %d: vc config paths must be absolute: `%s'"
                               % (self.path, i, path))
-            source = {"svn": SVNSource,
-                      "p4":  P4Source,
-                      "cvs": CVSSource,
-                      "hg": HGSource}[repo_type](path, source_info)
+            source = {
+                "svn": SVNSource,
+                "p4":  P4Source,
+                "cvs": CVSSource,
+                "hg": HGSource,
+                "git": GitSource,
+            }[repo_type](path, source_info)
             path_bits = _splitall(normcase(normpath(xpath)))
             self._sources[tuple(path_bits)] = source