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
def __prepare_repo(self): if not exists(dirname(self.path)): makedirs(dirname(self.path)) 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)