def update_w3d(branch="master"): target_ref = 'refs/heads/{}'.format(branch).encode() w3d_repo = dulwich.repo.Repo(W3D_PATH) porcelain.reset(w3d_repo, "hard") porcelain.pull(W3D_PATH, REMOTE_PATH, target_ref) w3d_repo.refs.set_symbolic_ref('HEAD'.encode(), target_ref) porcelain.reset(w3d_repo, "hard")
def test_hard_head(self): f = open(os.path.join(self.repo.path, 'foo'), 'w') try: f.write("BAR") finally: f.close() porcelain.add(self.repo.path, paths=["foo"]) porcelain.commit(self.repo.path, message="Some message", committer="Jane <*****@*****.**>", author="John <*****@*****.**>") f = open(os.path.join(self.repo.path, 'foo'), 'w') try: f.write("OOH") finally: f.close() porcelain.reset(self.repo, "hard", "HEAD") index = self.repo.open_index() changes = list( tree_changes(self.repo, index.commit(self.repo.object_store), self.repo['HEAD'].tree)) self.assertEquals([], changes)
def test_hard_commit(self): with open(os.path.join(self.repo.path, "foo"), "w") as f: f.write("BAR") porcelain.add(self.repo.path, paths=["foo"]) sha = porcelain.commit( self.repo.path, message=b"Some message", committer=b"Jane <*****@*****.**>", author=b"John <*****@*****.**>", ) with open(os.path.join(self.repo.path, "foo"), "wb") as f: f.write(b"BAZ") porcelain.add(self.repo.path, paths=["foo"]) porcelain.commit( self.repo.path, message=b"Some other message", committer=b"Jane <*****@*****.**>", author=b"John <*****@*****.**>", ) porcelain.reset(self.repo, "hard", sha) index = self.repo.open_index() changes = list(tree_changes(self.repo, index.commit(self.repo.object_store), self.repo[sha].tree)) self.assertEqual([], changes)
def test_hard_commit(self): fullpath = os.path.join(self.repo.path, 'foo') with open(fullpath, 'w') as f: f.write("BAR") porcelain.add(self.repo.path, paths=[fullpath]) sha = porcelain.commit(self.repo.path, message=b"Some message", committer=b"Jane <*****@*****.**>", author=b"John <*****@*****.**>") with open(fullpath, 'wb') as f: f.write(b"BAZ") porcelain.add(self.repo.path, paths=[fullpath]) porcelain.commit(self.repo.path, message=b"Some other message", committer=b"Jane <*****@*****.**>", author=b"John <*****@*****.**>") porcelain.reset(self.repo, "hard", sha) index = self.repo.open_index() changes = list( tree_changes(self.repo, index.commit(self.repo.object_store), self.repo[sha].tree)) self.assertEqual([], changes)
def test_hard_head(self): f = open(os.path.join(self.repo.path, 'foo'), 'w') try: f.write("BAR") finally: f.close() porcelain.add(self.repo.path, paths=["foo"]) porcelain.commit(self.repo.path, message="Some message", committer="Jane <*****@*****.**>", author="John <*****@*****.**>") f = open(os.path.join(self.repo.path, 'foo'), 'w') try: f.write("OOH") finally: f.close() porcelain.reset(self.repo, "hard", "HEAD") index = self.repo.open_index() changes = list(tree_changes(self.repo, index.commit(self.repo.object_store), self.repo['HEAD'].tree)) self.assertEqual([], changes)
def restore(self, commit): """ does a hard reset to a given commit :param commit: list-of-dulwich.objects.Commit; commit to reset to """ porcelain.reset(self.repo, 'hard', str.encode(commit.sha().hexdigest())) self.commit("Restored setting and data.") Config.read_config()
def __exit__(self, exc_type, value, tb): if value is None: self.repo.refs.set_symbolic_ref('HEAD', self.start) # lol, only reset --hard is supported if self.delete: self.repo.refs.remove_if_equals(self.branch, None) else: six.reraise(exc_type, value, tb) git.reset(self.repo, "hard")
def reset_to_remote(self, workspace, branch=None): outstream = BytesIO() errstream = BytesIO() # XXX not actually resetting to remote # XXX assuming 'master' is the current branch if branch is None: branch = 'master' porcelain.reset(workspace.working_dir, 'hard', committish=b'HEAD') return outstream.getvalue().decode(), errstream.getvalue().decode()
def run(self, args): opts, args = getopt(args, "", ["hard", "soft", "mixed"]) opts = dict(opts) mode = "" if "--hard" in opts: mode = "hard" elif "--soft" in opts: mode = "soft" elif "--mixed" in opts: mode = "mixed" porcelain.reset('.', mode=mode, *args)
def git_reset_repo_to_origin(): try: repo = porcelain.Repo(database) porcelain.fetch(repo) tree_head_id = repo[repo[b'refs/heads/master'].tree].id tree_origin_master_id = repo[ repo[b'refs/remotes/origin/master'].tree].id store = repo.object_store list_all_files_head = list_all_files(store, tree_head_id) list_all_files_origin_master = list_all_files(store, tree_origin_master_id) deleted_files = list( set(list_all_files_head) - set(list_all_files_origin_master)) # print(deleted_files) if deleted_files != []: for all in deleted_files: file_path = os.path.join(database, all.decode('utf-8')) os.remove(file_path) status = porcelain.status(repo) repo.stage(status.unstaged) porcelain.commit(repo, message="delete files") ###working### porcelain.reset(repo, "hard", treeish=b"refs/remotes/origin/master") porcelain.clean(repo=repo, target_dir=database) resolve_divergence() ######## return True except MaxRetryError: print('MaxRetryError') return False except ProtocolError: print('ProtocolError') return False
def test_hard_head(self): with open(os.path.join(self.repo.path, 'foo'), 'w') as f: f.write("BAR") porcelain.add(self.repo.path, paths=["foo"]) porcelain.commit(self.repo.path, message=b"Some message", committer=b"Jane <*****@*****.**>", author=b"John <*****@*****.**>") with open(os.path.join(self.repo.path, 'foo'), 'wb') as f: f.write(b"OOH") porcelain.reset(self.repo, "hard", b"HEAD") index = self.repo.open_index() changes = list(tree_changes(self.repo, index.commit(self.repo.object_store), self.repo[b'HEAD'].tree)) self.assertEqual([], changes)
def test_hard_head(self): fullpath = os.path.join(self.repo.path, 'foo') with open(fullpath, 'w') as f: f.write("BAR") porcelain.add(self.repo.path, paths=[fullpath]) porcelain.commit(self.repo.path, message=b"Some message", committer=b"Jane <*****@*****.**>", author=b"John <*****@*****.**>") with open(os.path.join(self.repo.path, 'foo'), 'wb') as f: f.write(b"OOH") porcelain.reset(self.repo, "hard", b"HEAD") index = self.repo.open_index() changes = list(tree_changes(self.repo, index.commit(self.repo.object_store), self.repo[b'HEAD'].tree)) self.assertEqual([], changes)
def update_dulwich(): try: import dulwich.repo from dulwich import porcelain except ImportError: install_dulwich() return try: dulwich_repo = dulwich.repo.Repo(os.path.join(INSTALL_PATH, "dulwich")) except dulwich.errors.NotGitRepository: try: shutil.rmtree(os.path.join(INSTALL_PATH, "dulwich")) except FileNotFoundError: pass # Directory already gone dulwich_repo = porcelain.clone("https://github.com/jelmer/dulwich.git", os.path.join(INSTALL_PATH, "dulwich")) porcelain.reset(dulwich_repo, "hard") porcelain.pull(dulwich_repo, remote_location="https://github.com/jelmer/dulwich.git") install_dulwich()
def push(name, api, domain): repo = git.Repo(os.getcwd()) branch = "temp-{}".format(str(uuid.uuid4())[:8]) set_deploy_branch(name, branch, api, domain) remote = git_url(name, api, domain) if is_dirty(): print("Nuking changes.") git.reset(repo, "hard") with TempBranch(branch, repo, delete=True): for fname, file_info in openshift_files.items(): with open(fname, 'w') as f: f.write(file_info.get("contents", "")) repo.stage(fname) repo.do_commit("Commit openshift files") push_out = StringIO() push_err = StringIO() print("Pushing to openshift (may take a few minutes)") git.push(repo, remote, "refs/heads/{}".format(branch), outstream=push_out, errstream=push_err) push_out.seek(0) out = push_out.read() if not re.match(r'^Push to .* successful.', out): print("There was a failure while pushing") print("---BEGIN STDERR---") push_err.seek(0) print(push_err.read()) print("---BEGIN STDOUT---") print(out) print("There was a failure while pushing") git.rm(repo, openshift_files.keys()) map(os.remove, openshift_files.keys()) return get_app(name, api, domain)['app_url']
def run_nextflow(run, params, rundir, gitwfdir, profiles, nf_version=False): """Fairly generalized code for kantele celery task to run a WF in NXF""" print('Starting nextflow workflow {}'.format(run['nxf_wf_fn'])) outdir = os.path.join(rundir, 'output') try: clone(run['repo'], gitwfdir, checkout=run['wf_commit']) except FileExistsError: pull(gitwfdir, run['repo']) reset(gitwfdir, 'hard', run['wf_commit']) # FIXME dulwich does not seem to checkout anything, use this until it does subprocess.run(['git', 'checkout', run['wf_commit']], check=True, cwd=gitwfdir) print('Checked out repo {} at commit {}'.format(run['repo'], run['wf_commit'])) # There will be files inside data dir of WF repo so we must be in # that dir for WF to find them cmd = ['nextflow', 'run', run['nxf_wf_fn'], *params, '--outdir', outdir, '-profile', profiles, '-with-trace', '-resume'] print(cmd) env = os.environ if nf_version: env['NXF_VER'] = nf_version log_analysis(run['analysis_id'], 'Running command {}, nextflow version {}'.format(' '.join(cmd), env.get('NXF_VER', 'default'))) subprocess.run(cmd, check=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE, cwd=gitwfdir, env=env) return rundir
def reset(self, sender): porcelain.reset(self.g.path, mode="hard", committish="HEAD") self.refresh()
def reset(self,sender): porcelain.reset(self.g.path,mode='hard',committish='HEAD') self.refresh()
def git_reset(args): if len(args) == 0: repo = _get_repo() porcelain.reset(repo.repo, 'hard') else: print command_help['reset']
def reset(self, sender): porcelain.reset(self.g.path, mode='hard', committish='HEAD') self.refresh()