From 021ce2b078d0d1e4e5f33d3c19185130aa73c2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Sun, 24 Jun 2018 00:25:37 +0200 Subject: [PATCH] tmp --- benchmark-new/benchmark_repository.py | 31 +++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/benchmark-new/benchmark_repository.py b/benchmark-new/benchmark_repository.py index b18b463b5..57502aebf 100755 --- a/benchmark-new/benchmark_repository.py +++ b/benchmark-new/benchmark_repository.py @@ -57,25 +57,38 @@ class BenchmarkRepository: remote.fetch(callbacks = callbacks) printProgressBar("Updating the repository", 1, 1, overwrite = True) + self.forceUpdateBranch("master", self.repository) + try: - pass - #self.repository.lookup_worktree("results") - #self.repository.lookup_worktree("config") - #self.repository.lookup_worktree("status") + for branchName in ["results", "config", "status"]: + print("Updating branch {}".format(branchName)) + worktree = self.repository.lookup_worktree(branchName) + worktree = pygit2.Repository(worktree.path) + self.forceUpdateBranch(branchName, worktree) except pygit2.GitError: raise Exception("Worktrees are not properly set up") + + print(list(self.repository.branches)) else: callbacks.transfer_progress = printCloneProgress printProgressBar("Cloning the repository", 0, 1) self.repository = pygit2.clone_repository(self.remote, self.branchDir("master"), callbacks = callbacks, checkout_branch = self.branches["master"]) + self.repository = pygit2.Repository(self.repository.path) printProgressBar("Cloning the repository", 1, 1, overwrite = True) - for branchName in ["results", "config", "status"]: - worktree = self.repository.add_worktree(branchName, self.branchDir(branchName)) - worktree = pygit2.Repository(worktree.path) - branch = worktree.branches.local.create(branchName) - #worktree.checkout(self.branches["results"]) + for branchName in ["results", "config", "status"]: + print("Preparing branch {}".format(branchName)) + worktree = self.repository.add_worktree(branchName, self.branchDir(branchName)) + worktree = pygit2.Repository(worktree.path) + remoteReference = worktree.lookup_reference("refs/remotes/origin/{}".format(self.branches[branchName])) + localReference = worktree.create_reference("refs/heads/{}".format(branchName), remoteReference.resolve().target) + self.forceUpdateBranch(branchName, worktree) def branchDir(self, branchName): return os.path.join(self.basePath, branchName) + + def forceUpdateBranch(self, branchName, worktree): + worktree.checkout("refs/heads/{}".format(branchName), strategy = pygit2.GIT_CHECKOUT_FORCE | pygit2.GIT_CHECKOUT_RECREATE_MISSING) + #remoteReference = worktree.lookup_reference("refs/remotes/origin/{}".format(self.branches[branchName])) + #worktree.reset(remoteReference.target, pygit2.GIT_RESET_HARD)