Exemplo n.º 1
0
 def get_status(self, basepath=None, untracked=False):
     response = None
     if basepath is None:
         basepath = self._path
     if self.path_exists():
         rel_path = normalized_rel_path(self._path, basepath)
         # git command only works inside repo
         # self._path is safe against command injection, as long as we check path.exists
         command = "git status -s "
         if not untracked:
             command += " -uno"
         _, response, _ = run_shell_command(command, shell=True, cwd=self._path)
         response_processed = ""
         for line in response.split("\n"):
             if len(line.strip()) > 0:
                 # prepend relative path
                 response_processed += "%s%s/%s\n" % (line[0:3], rel_path, line[3:])
         if LooseVersion(self.gitversion) > LooseVersion("1.7"):
             command = "git submodule foreach --recursive git status -s"
             if not untracked:
                 command += " -uno"
             _, response2, _ = run_shell_command(command, shell=True, cwd=self._path)
             for line in response2.split("\n"):
                 if line.startswith("Entering"):
                     continue
                 if len(line.strip()) > 0:
                     # prepend relative path
                     response_processed += line[0:3] + rel_path + "/" + line[3:] + "\n"
         response = response_processed
     return response
Exemplo n.º 2
0
 def test_normalized_rel_path(self):
     self.assertEqual(None, normalized_rel_path(None, None))
     self.assertEqual('foo', normalized_rel_path(None, 'foo'))
     self.assertEqual('/foo', normalized_rel_path(None, '/foo'))
     self.assertEqual('../bar', normalized_rel_path('/bar', '/foo'))
     self.assertEqual('../bar', normalized_rel_path('/bar', '/foo/baz/..'))
     self.assertEqual('../bar', normalized_rel_path('/bar/bam/foo/../..', '/foo/baz/..'))
     self.assertEqual('bar', normalized_rel_path('bar/bam/foo/../..', '/foo/baz/..'))
Exemplo n.º 3
0
 def get_diff(self, basepath=None):
     response = None
     if basepath is None:
         basepath = self._path
     if self.path_exists():
         rel_path = normalized_rel_path(self._path, basepath)
         command = "hg diff -g %(path)s --repository %(path)s" % {'path': sanitized(rel_path)}
         _, response, _ = run_shell_command(command, shell=True, cwd=basepath)
         response = _hg_diff_path_change(response, rel_path)
     return response
Exemplo n.º 4
0
 def get_diff(self, basepath=None):
     response = None
     if basepath is None:
         basepath = self._path
     if self.path_exists():
         rel_path = sanitized(normalized_rel_path(self._path, basepath))
         command = "bzr diff %s" % rel_path
         command += " -p1 --prefix %s/:%s/" % (rel_path, rel_path)
         _, response, _ = run_shell_command(command, shell=True, cwd=basepath)
     return response
Exemplo n.º 5
0
 def get_diff(self, basepath=None):
     response = None
     if basepath is None:
         basepath = self._path
     if self.path_exists():
         rel_path = normalized_rel_path(self._path, basepath)
         command = 'svn diff %s' % sanitized(rel_path)
         _, response, _ = run_shell_command(command,
                                            shell=True,
                                            cwd=basepath)
     return response
Exemplo n.º 6
0
 def get_diff(self, basepath=None):
     response = ''
     if basepath is None:
         basepath = self._path
     if self.path_exists():
         rel_path = normalized_rel_path(self._path, basepath)
         # git needs special treatment as it only works from inside
         # use HEAD to also show staged changes. Maybe should be option?
         # injection should be impossible using relpath, but to be sure, we check
         cmd = "git diff HEAD --src-prefix=%s/ --dst-prefix=%s/ ."%(sanitized(rel_path), sanitized(rel_path))
         _, response, _ = run_shell_command(cmd, shell=True, cwd=self._path)
         if LooseVersion(self.gitversion) > LooseVersion('1.7'):
             cmd = 'git submodule foreach --recursive git diff HEAD'
             _, output, _ = run_shell_command(cmd, shell=True, cwd=self._path)
             response += _git_diff_path_submodule_change(output, rel_path)
     return response
Exemplo n.º 7
0
 def get_status(self, basepath=None, untracked=False):
     response = None
     if basepath is None:
         basepath = self._path
     if self.path_exists():
         rel_path = normalized_rel_path(self._path, basepath)
         command = "bzr status %s -S" % sanitized(rel_path)
         if not untracked:
             command += " -V"
         _, response, _ = run_shell_command(command, shell=True, cwd=basepath)
         response_processed = ""
         for line in response.split('\n'):
             if len(line.strip()) > 0:
                 response_processed += line[0:4] + rel_path + '/'
                 response_processed += line[4:] + '\n'
         response = response_processed
     return response
Exemplo n.º 8
0
 def get_status(self, basepath=None, untracked=False):
     response = None
     if basepath is None:
         basepath = self._path
     if self.path_exists():
         rel_path = normalized_rel_path(self._path, basepath)
         # protect against shell injection
         command = "hg status %(path)s --repository %(path)s" % {"path": sanitized(rel_path)}
         if not untracked:
             command += " -mard"
         _, response, _ = run_shell_command(command, shell=True, cwd=basepath)
         if response is not None:
             if response.startswith("abort"):
                 raise VcsError("Probable Bug; Could not call %s, cwd=%s" % (command, basepath))
             if len(response) > 0 and response[-1] != "\n":
                 response += "\n"
     return response
Exemplo n.º 9
0
 def get_status(self, basepath=None, untracked=False):
     response = None
     if basepath is None:
         basepath = self._path
     if self.path_exists():
         rel_path = normalized_rel_path(self._path, basepath)
         # protect against shell injection
         command = 'svn status %s' % sanitized(rel_path)
         if not untracked:
             command += " -q"
         _, response, _ = run_shell_command(command,
                                            shell=True,
                                            cwd=basepath)
         if response is not None and \
            len(response) > 0 and \
            response[-1] != '\n':
             response += '\n'
     return response
Exemplo n.º 10
0
 def get_status(self, basepath=None, untracked=False, porcelain=False):
     status_flag = '--porcelain' if porcelain else '-s'
     response = None
     if basepath is None:
         basepath = self._path
     if self.path_exists():
         rel_path = normalized_rel_path(self._path, basepath)
         # git command only works inside repo
         # self._path is safe against command injection, as long as we check path.exists
         command = "git status {0} ".format(status_flag)
         if not untracked:
             command += " -uno"
         _, response, _ = run_shell_command(command,
                                            shell=True,
                                            cwd=self._path)
         response_processed = ""
         for line in response.split('\n'):
             if len(line.strip()) > 0:
                 # prepend relative path
                 response_processed += '%s%s/%s\n' % (line[0:3], rel_path,
                                                      line[3:])
         if LooseVersion(self.gitversion) > LooseVersion('1.7'):
             command = "git submodule foreach --recursive git status {0}".format(
                 status_flag)
             if not untracked:
                 command += " -uno"
             _, response2, _ = run_shell_command(command,
                                                 shell=True,
                                                 cwd=self._path)
             for line in response2.split('\n'):
                 if line.startswith("Entering"):
                     continue
                 if len(line.strip()) > 0:
                     # prepend relative path
                     response_processed += line[
                         0:3] + rel_path + '/' + line[3:] + '\n'
         response = response_processed
     return response