示例#1
0
    def update(self):
        if not self.is_local:
            raise NotInstalled('{} is not installed'.format(self.name))
        git = Git(self.path)

        with git_to_msm_exceptions():
            sha_before = git.rev_parse('HEAD')

            modified_files = git.status(porcelain=True, untracked='no')
            if modified_files != '':
                raise SkillModified('Uncommitted changes:\n' + modified_files)

            git.fetch()
            current_branch = git.rev_parse('--abbrev-ref', 'HEAD').strip()
            if self.sha and current_branch in SWITCHABLE_BRANCHES:
                # Check out correct branch
                git.checkout(self._find_sha_branch())

            git.merge(self.sha or 'origin/HEAD', ff_only=True)

        sha_after = git.rev_parse('HEAD')

        if sha_before != sha_after:
            self.update_deps()
            LOG.info('Updated ' + self.name)
            # Trigger reload by modifying the timestamp
            os.utime(join(self.path, '__init__.py'))
            return True
        else:
            LOG.info('Nothing new for ' + self.name)
            return False
示例#2
0
 def get_shas(self):
     git = Git(self.path)
     with git_to_msm_exceptions():
         shas = git.ls_tree('origin/' + self.branch)
     for line in shas.split('\n'):
         size, typ, sha, folder = line.split()
         if typ != 'commit':
             continue
         yield folder, sha
示例#3
0
 def update(self):
     try:
         self.__prepare_repo()
     except (GitError, PermissionError) as e:
         LOG.warning('Could not prepare repo ({}), '
                     ' Creating temporary repo'.format(repr(e)))
         original_path = self.path
         self.path = join(gettempdir(), '.skills-repo')
         try:
             with git_to_msm_exceptions():
                 self.__prepare_repo()
         except Exception:
             LOG.warning('Could not use temporary repo either ({}), '
                         ' trying to use existing one without '
                         'update'.format(repr(e)))
             self.path = original_path  # Restore path to previous value
             raise
示例#4
0
    def update(self):
        if not exists(dirname(self.path)):
            makedirs(dirname(self.path))

        with git_to_msm_exceptions():
            if not isdir(self.path):
                Repo.clone_from(self.url, self.path)

            git = Git(self.path)
            git.config('remote.origin.url', self.url)
            git.fetch()

        try:
            git.checkout(self.branch)
            git.reset('origin/' + self.branch, hard=True)
        except GitCommandError:
            raise MsmException('Invalid branch: ' + self.branch)