From b6854569134f97d9b27e724a31c9efd92dc1f6f1 Mon Sep 17 00:00:00 2001 From: Anastasia Karpinska Date: Fri, 31 May 2013 14:43:06 +0400 Subject: [PATCH] Always delete current branch before branch creation in git If repository must be checked out to current branch, it should be removed before recreating. Change-Id: I69a8c51ff7fca79a79a17c6c9420a4cb417061b7 --- anvil/downloader.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/anvil/downloader.py b/anvil/downloader.py index 08dc233f..c843b6dd 100644 --- a/anvil/downloader.py +++ b/anvil/downloader.py @@ -79,15 +79,6 @@ class GitDownloader(Downloader): sh.execute(*cmd, cwd=self.store_where) cmd = ["git", "reset", "--hard"] sh.execute(*cmd, cwd=self.store_where) - # detach, drop new_branch if it exists, and checkout to new_branch - # newer git allows branch resetting: git checkout -B $new_branch - # so, all these are for compatibility with older RHEL git - cmd = ["git", "rev-parse", "HEAD"] - git_head = sh.execute(*cmd, cwd=self.store_where)[0].strip() - cmd = ["git", "checkout", git_head] - sh.execute(*cmd, cwd=self.store_where) - cmd = ["git", "branch", "-D", new_branch] - sh.execute(*cmd, cwd=self.store_where, ignore_exit_code=True) else: LOG.info("Downloading %s (%s) to %s.", colorizer.quote(uri), branch, colorizer.quote(self.store_where)) cmd = ["git", "clone", uri, self.store_where] @@ -96,6 +87,15 @@ class GitDownloader(Downloader): LOG.info("Adjusting to tag %s.", colorizer.quote(tag)) else: LOG.info("Adjusting branch to %s.", colorizer.quote(branch)) + # detach, drop new_branch if it exists, and checkout to new_branch + # newer git allows branch resetting: git checkout -B $new_branch + # so, all these are for compatibility with older RHEL git + cmd = ["git", "rev-parse", "HEAD"] + git_head = sh.execute(*cmd, cwd=self.store_where)[0].strip() + cmd = ["git", "checkout", git_head] + sh.execute(*cmd, cwd=self.store_where) + cmd = ["git", "branch", "-D", new_branch] + sh.execute(*cmd, cwd=self.store_where, ignore_exit_code=True) cmd = ["git", "checkout"] + checkout_what sh.execute(*cmd, cwd=self.store_where)