def _prepare(cls, create, **kwargs): tuto = super(MiniTutorialFactory, cls)._prepare(create, **kwargs) path = tuto.get_path() if not os.path.isdir(path): os.makedirs(path, mode=0o777) man = export_tutorial(tuto) repo = Repo.init(path, bare=False) repo = Repo(path) file = open(os.path.join(path, 'manifest.json'), "w") file.write( json_writer.dumps( man, indent=4, ensure_ascii=False).encode('utf-8')) file.close() file = open(os.path.join(path, tuto.introduction), "w") file.write(contenu.encode('utf-8')) file.close() file = open(os.path.join(path, tuto.conclusion), "w") file.write(contenu.encode('utf-8')) file.close() repo.index.add(['manifest.json', tuto.introduction, tuto.conclusion]) cm = repo.index.commit("Init Tuto") tuto.sha_draft = cm.hexsha return tuto
def setup(self): git_opts = self._config if git_opts['url'] is None: raise Exception('Remote git URL not set.') self._url = git_opts['url'] self._branch = git_opts['branch'] default_clone_dir = os.path.join(os.path.dirname(__file__), 'clones') self._local_path = git_opts.get('local_clone_path', default_clone_dir) self._poll_interval = git_opts.get('poll_interval', self._poll_interval) if os.path.exists(self._local_path): self._repo = Repo.init(self._local_path) else: try: self._repo = Repo.clone_from(self._url, self._local_path, branch=self._branch) except Exception: self._logger.exception( 'Unable to clone remote repo from %s branch %s', self._url, self._branch) raise self._remote = self._repo.remote('origin')
def _prepare_local_repository(self, opts): url = opts['url'] branch = opts['branch'] if url is None: raise Exception('Remote git URL not set.') # set local repository path to be cloned repo_name = url[url.rindex('/') + 1:] default_clone_dir = os.path.join(os.path.dirname(__file__), 'clones', repo_name) local_path = opts.get('local_clone_path', default_clone_dir) # create a directory to store cloned repositories if not os.path.exists(os.path.dirname(local_path)): os.mkdir(os.path.dirname(local_path), 0o755) if os.path.exists(local_path): repo_local = Repo.init(local_path) else: try: repo_local = Repo.clone_from(url, local_path, branch=branch) except Exception as e: raise Exception('Unable to clone remote repo from %s [%s]: %s' % (url, branch, str(e))) return repo_local, repo_local.remote('origin')
def _prepare(cls, create, **kwargs): tuto = super(MiniTutorialFactory, cls)._prepare(create, **kwargs) path = tuto.get_path() if not os.path.isdir(path): os.makedirs(path, mode=0o777) man = export_tutorial(tuto) repo = Repo.init(path, bare=False) repo = Repo(path) file = open(os.path.join(path, 'manifest.json'), "w") file.write( json_writer.dumps( man, indent=4, ensure_ascii=False).encode('utf-8')) file.close() file = open(os.path.join(path, tuto.introduction), "w") file.write(u'Test') file.close() file = open(os.path.join(path, tuto.conclusion), "w") file.write(u'Test') file.close() repo.index.add(['manifest.json', tuto.introduction, tuto.conclusion]) cm = repo.index.commit("Init Tuto") tuto.sha_draft = cm.hexsha return tuto
def _prepare(cls, create, **kwargs): light = kwargs.pop('light', False) tuto = super(BigTutorialFactory, cls)._prepare(create, **kwargs) path = tuto.get_path() real_content = content if light: real_content = content_light if not os.path.isdir(path): os.makedirs(path, mode=0o777) man = export_tutorial(tuto) repo = Repo.init(path, bare=False) repo = Repo(path) f = open(os.path.join(path, 'manifest.json'), "w") f.write(json_writer.dumps(man, indent=4, ensure_ascii=False).encode('utf-8')) f.close() f = open(os.path.join(path, tuto.introduction), "w") f.write(real_content.encode('utf-8')) f.close() f = open(os.path.join(path, tuto.conclusion), "w") f.write(real_content.encode('utf-8')) f.close() repo.index.add(['manifest.json', tuto.introduction, tuto.conclusion]) cm = repo.index.commit("Init Tuto") tuto.sha_draft = cm.hexsha tuto.sha_beta = None tuto.gallery = GalleryFactory() for author in tuto.authors.all(): UserGalleryFactory(user=author, gallery=tuto.gallery) return tuto
def temporary_repo(prefix: str=''): with tempfile.TemporaryDirectory(prefix=prefix) as repo_path, Repo.init(repo_path) as repo: try: yield repo finally: # This closes leftover git.exe processes opened by GitPython, allowing us to delete the repo directory. repo.git.clear_cache() # On Windows, the tempdir is created as read-only which prevents us from deleting it with say shutil.rmtree, # so we do this manual walk here (https://stackoverflow.com/a/2656408) for root, dirs, files in os.walk(repo_path, topdown=False): for name in files: filename = os.path.join(root, name) os.chmod(filename, stat.S_IWUSR) os.remove(filename) for name in dirs: filename = os.path.join(root, name) os.chmod(filename, stat.S_IWUSR) os.rmdir(filename)
def _prepare(cls, create, **kwargs): article = super(ArticleFactory, cls)._prepare(create, **kwargs) path = article.get_path() if not os.path.isdir(path): os.makedirs(path, mode=0o777) man = export_article(article) repo = Repo.init(path, bare=False) repo = Repo(path) f = open(os.path.join(path, 'manifest.json'), "w") f.write(json_writer.dumps(man, indent=4, ensure_ascii=False).encode('utf-8')) f.close() f = open(os.path.join(path, article.text), "w") f.write(u'Test') f.close() repo.index.add(['manifest.json', article.text]) cm = repo.index.commit("Init Article") article.sha_draft = cm.hexsha return article
def setup(self): git_opts = self._config if git_opts['url'] is None: raise Exception('Remote git URL not set.') self._url = git_opts['url'] default_clone_dir = os.path.join(os.path.dirname(__file__), 'clones') self._local_path = git_opts.get('local_clone_path', default_clone_dir) self._poll_interval = git_opts.get('poll_interval', self._poll_interval) if os.path.exists(self._local_path): self._repo = Repo.init(self._local_path) else: try: self._repo = Repo.clone_from(self._url, self._local_path) except Exception: self._logger.exception('Unable to clone remote repo from %s', self._url) raise self._remote = self._repo.remote('origin')
def _prepare(cls, create, **kwargs): light = kwargs.pop('light', False) authors = [] if "authors" in kwargs: authors = kwargs.pop("authors") article = super(ArticleFactory, cls)._prepare(create, **kwargs) for auth in authors: article.authors.add(User.objects.get(pk=auth)) path = article.get_path() if not os.path.isdir(path): os.makedirs(path, mode=0o777) man = export_article(article) repo = Repo.init(path, bare=False) repo = Repo(path) f = open(os.path.join(path, 'manifest.json'), "w") f.write( json_writer.dumps(man, indent=4, ensure_ascii=False).encode('utf-8')) f.close() f = open(os.path.join(path, article.text), "w") if light: f.write(content_light.encode('utf-8')) else: f.write(content_long.encode('utf-8')) f.close() repo.index.add(['manifest.json', article.text]) cm = repo.index.commit("Init Article") article.sha_draft = cm.hexsha return article
def prepare_historage_repo(self): historage_repo = Repo.init(self.historage_dir, bare=self.is_bare_repo) self.set_git_config(historage_repo) return historage_repo
def get_repo(filepath): fpath = os.path.expanduser(filepath) os.makedirs(fpath, exist_ok=True) return Repo.init(fpath)
def temp_git_folder(temp_folder): repo = Repo.init(temp_folder) repo.create_remote(name="origin", url="[email protected]:temp/sandbox.git") yield temp_folder
def prepare_base_repo(self): base_repo = Repo.init(self.historage_dir, bare=self.is_bare_repo) return base_repo
tree_contents = [] tree_contents.append((conf_mode, conf_binsha, ".gitmodules")) tree_contents.append(get_submodule_tree_content(submodule_commit_hexsha, "jEdit")) tree_mode, binsha = mktree_from_iter(odb, tree_contents) return bin_to_hex(binsha) if __name__ == "__main__": from kenja.git.util import get_reversed_topological_ordered_commits repo = Repo("/Users/kenjif/msr_repos/git/jEdit") commits = get_reversed_topological_ordered_commits(repo, repo.refs) new_repo = Repo.init("/Users/kenjif/test_git_repo") with open("/Users/kenjif/test_gitmodules", "wb") as f: name = "jEdit" path = "jEdit" url = "/Users/kenjif/msr_repos/git/jEdit" write_submodule_config(f, name, path, url) committed = {} tags = {} heads = {} for tag_ref in repo.tags: tags[tag_ref.commit.hexsha] = tag_ref.name for head in repo.heads: heads[head.commit.hexsha] = head.name
children = [] for parent in commit.parents: if parent.hexsha not in visited: children.append(parent.hexsha) if children: nodes.extend(children) else: nodes.pop() visited.add(node) post.append(node) return post if __name__ == '__main__': repo = Repo.init('test_git') # (mode, binsha) = write_tree(repo.odb, 'temp') # (mode, binsha) = write_tree(repo.odb, 'temp/00') # (mode, binsha) = write_tree(repo.odb, 'temp/01') paths = ['temp/00', 'temp/01'] names = ['a', 'b'] (mode, binsha) = write_paths(repo.odb, paths, names) tree = Tree.new(repo, bin_to_hex(binsha)) c = Commit.create_from_tree(repo, tree, 'test commit', None, True)
def gen_gitsecret(): with tempfile.TemporaryDirectory() as tempdir: Repo.init(tempdir) yield gitsecret.GitSecret(tempdir)