Ejemplo n.º 1
0
    def detect_scm_system(self, path, patch_directories=None):
        real_path = self._filesystem.realpath(path)

        if patch_directories == []:
            patch_directories = None

        if SVN.in_working_directory(real_path, executive=self._executive):
            return SVN(cwd=real_path,
                       patch_directories=patch_directories,
                       filesystem=self._filesystem,
                       executive=self._executive)

        if Git.in_working_directory(real_path, executive=self._executive):
            return Git(cwd=real_path,
                       patch_directories=patch_directories,
                       filesystem=self._filesystem,
                       executive=self._executive)

        if StubRepository.in_working_directory(real_path,
                                               filesystem=self._filesystem):
            return StubRepository(cwd=real_path,
                                  patch_directories=patch_directories,
                                  filesystem=self._filesystem,
                                  executive=self._executive)

        return None
Ejemplo n.º 2
0
    def initialize_scm(self):
        # TODO(qyearsley): Refactor this so that scm is initialized
        # when self.scm() is called the first time; put any initialization
        # code in the git module.
        if sys.platform == 'win32':
            self._engage_awesome_windows_hacks()

        cwd = self.filesystem.abspath(self.filesystem.getcwd())
        if Git.in_working_directory(cwd, executive=self.executive):
            self._scm = Git(cwd=cwd, filesystem=self.filesystem, executive=self.executive)
            return

        script_directory = self.filesystem.abspath(
            self.filesystem.dirname(self.filesystem.path_to_module(self.__module__)))
        _log.info('The current directory (%s) is not in a git repo, trying script directory %s.', cwd, script_directory)
        if Git.in_working_directory(script_directory, executive=self.executive):
            self._scm = Git(cwd=script_directory, filesystem=self.filesystem, executive=self.executive)
            return

        raise Exception('FATAL: Failed to find Git repo for %s or %s' % (cwd, script_directory))