def test_checkout_successful(self, run_subprocess_with_logging, run_subprocess): run_subprocess_with_logging.return_value = 0 run_subprocess.return_value = False git.checkout("/src", "feature-branch") run_subprocess.assert_called_with( "git -C /src checkout --quiet feature-branch")
def test_checkout_with_error(self, run_subprocess_with_logging, run_subprocess): run_subprocess_with_logging.return_value = 0 run_subprocess.return_value = True with self.assertRaises(exceptions.SupplyError) as ctx: git.checkout("/src", "feature-branch") self.assertEqual("Could not checkout branch [feature-branch]. Do you have uncommitted changes?", ctx.exception.args[0]) run_subprocess.assert_called_with("git -C /src checkout --quiet feature-branch")
def _update(self, distribution_version): try: if self.remote and not self.offline: branch = versions.best_match(git.branches(self.tracks_dir, remote=self.remote), distribution_version) if branch: # Allow uncommitted changes iff we do not have to change the branch logger.info( "Checking out [%s] in [%s] for distribution version [%s]." % (branch, self.tracks_dir, distribution_version)) git.checkout(self.tracks_dir, branch=branch) logger.info("Rebasing on [%s] in [%s] for distribution version [%s]." % (branch, self.tracks_dir, distribution_version)) try: git.rebase(self.tracks_dir, branch=branch) except exceptions.SupplyError: logger.exception("Cannot rebase due to local changes in [%s]" % self.tracks_dir) console.warn( "Local changes in [%s] prevent track update from remote. Please commit your changes." % self.tracks_dir) return else: msg = "Could not find track data remotely for distribution version [%s]. " \ "Trying to find track data locally." % distribution_version logger.warn(msg) branch = versions.best_match(git.branches(self.tracks_dir, remote=False), distribution_version) if branch: logger.info("Checking out [%s] in [%s] for distribution version [%s]." % (branch, self.tracks_dir, distribution_version)) git.checkout(self.tracks_dir, branch=branch) else: raise exceptions.SystemSetupError("Cannot find track data for distribution version %s" % distribution_version) except exceptions.SupplyError: tb = sys.exc_info()[2] raise exceptions.DataError("Cannot update track data in [%s]." % self.tracks_dir).with_traceback(tb)
def _update(self, revision): if self.has_remote() and revision == "latest": self.logger.info("Fetching latest sources for %s from origin.", self.name) git.pull(self.src_dir) elif revision == "current": self.logger.info("Skip fetching sources for %s.", self.name) elif self.has_remote() and revision.startswith("@"): # convert timestamp annotated for Rally to something git understands -> we strip leading and trailing " and the @. git_ts_revision = revision[1:] self.logger.info( "Fetching from remote and checking out revision with timestamp [%s] for %s.", git_ts_revision, self.name) git.pull_ts(self.src_dir, git_ts_revision) elif self.has_remote(): # assume a git commit hash self.logger.info( "Fetching from remote and checking out revision [%s] for %s.", revision, self.name) git.pull_revision(self.src_dir, revision) else: self.logger.info("Checking out local revision [%s] for %s.", revision, self.name) git.checkout(self.src_dir, revision) if git.is_working_copy(self.src_dir): git_revision = git.head_revision(self.src_dir) self.logger.info( "User-specified revision [%s] for [%s] results in git revision [%s]", revision, self.name, git_revision) else: self.logger.info( "Skipping git revision resolution for %s (%s is not a git repository).", self.name, self.src_dir)
def _update(self, distribution_version): try: if self.remote and not self.offline: branch = versions.best_match( git.branches(self.tracks_dir, remote=self.remote), distribution_version) if branch: logger.info( "Rebasing on '%s' in '%s' for distribution version '%s'." % (branch, self.tracks_dir, distribution_version)) git.rebase(self.tracks_dir, branch=branch) return else: msg = "Could not find track data remotely for distribution version %s. " \ "Trying to find track data locally." % distribution_version logger.warn(msg) branch = versions.best_match( git.branches(self.tracks_dir, remote=False), distribution_version) if branch: logger.info( "Checking out '%s' in '%s' for distribution version '%s'." % (branch, self.tracks_dir, distribution_version)) git.checkout(self.tracks_dir, branch=branch) else: raise exceptions.SystemSetupError( "Cannot find track data for distribution version %s" % distribution_version) except exceptions.SupplyError as e: raise exceptions.DataError("Cannot update track data in '%s': %s" % (self.tracks_dir, e))
def test_checkout_with_error(self, run_subprocess_with_logging, run_subprocess): run_subprocess_with_logging.return_value = 0 run_subprocess.return_value = True with self.assertRaises(exceptions.SupplyError) as ctx: git.checkout("/src", "feature-branch") self.assertEqual("Could not checkout 'feature-branch'", ctx.exception.args[0]) run_subprocess.assert_called_with("git -C /src checkout --quiet feature-branch")
def update(self, distribution_version): try: if self.remote: branch = versions.best_match(git.branches(self.repo_dir, remote=self.remote), distribution_version) if branch: # Allow uncommitted changes iff we do not have to change the branch self.logger.info( "Checking out [%s] in [%s] for distribution version [%s].", branch, self.repo_dir, distribution_version) git.checkout(self.repo_dir, branch=branch) self.logger.info("Rebasing on [%s] in [%s] for distribution version [%s].", branch, self.repo_dir, distribution_version) try: git.rebase(self.repo_dir, branch=branch) except exceptions.SupplyError: self.logger.exception("Cannot rebase due to local changes in [%s]", self.repo_dir) console.warn( "Local changes in [%s] prevent %s update from remote. Please commit your changes." % (self.repo_dir, self.resource_name)) return else: msg = "Could not find %s remotely for distribution version [%s]. Trying to find %s locally." % \ (self.resource_name, distribution_version, self.resource_name) self.logger.warning(msg) branch = versions.best_match(git.branches(self.repo_dir, remote=False), distribution_version) if branch: if git.current_branch(self.repo_dir) != branch: self.logger.info("Checking out [%s] in [%s] for distribution version [%s].", branch, self.repo_dir, distribution_version) git.checkout(self.repo_dir, branch=branch) else: raise exceptions.SystemSetupError("Cannot find %s for distribution version %s" % (self.resource_name, distribution_version)) except exceptions.SupplyError as e: tb = sys.exc_info()[2] raise exceptions.DataError("Cannot update %s in [%s] (%s)." % (self.resource_name, self.repo_dir, e.message)).with_traceback(tb)
def _update(self, distribution_version): try: if self.remote and not self.offline: branch = versions.best_match(git.branches(self.tracks_dir, remote=self.remote), distribution_version) if branch: # Allow uncommitted changes iff we do not have to change the branch logger.info( "Checking out [%s] in [%s] for distribution version [%s]." % (branch, self.tracks_dir, distribution_version)) git.checkout(self.tracks_dir, branch=branch) logger.info("Rebasing on [%s] in [%s] for distribution version [%s]." % (branch, self.tracks_dir, distribution_version)) try: git.rebase(self.tracks_dir, branch=branch) except exceptions.SupplyError: logger.exception("Cannot rebase due to local changes in [%s]" % self.tracks_dir) console.warn( "Local changes in [%s] prevent track update from remote. Please commit your changes." % self.tracks_dir) return else: msg = "Could not find track data remotely for distribution version [%s]. " \ "Trying to find track data locally." % distribution_version logger.warning(msg) branch = versions.best_match(git.branches(self.tracks_dir, remote=False), distribution_version) if branch: logger.info("Checking out [%s] in [%s] for distribution version [%s]." % (branch, self.tracks_dir, distribution_version)) git.checkout(self.tracks_dir, branch=branch) else: raise exceptions.SystemSetupError("Cannot find track data for distribution version %s" % distribution_version) except exceptions.SupplyError: tb = sys.exc_info()[2] raise exceptions.DataError("Cannot update track data in [%s]." % self.tracks_dir).with_traceback(tb)
def test_checkout_with_error(self, run_subprocess): run_subprocess.return_value = True with self.assertRaises(exceptions.SupplyError) as ctx: git.checkout("/src", "feature-branch") self.assertEqual("Could not checkout 'feature-branch'", ctx.exception.args[0]) run_subprocess.assert_called_with( "git -C /src checkout --quiet feature-branch")
def test_checkout_with_error(self, run_subprocess_with_logging): # first call is to check the git version (0 -> succeeds), the second call is the failing checkout (1 -> fails) run_subprocess_with_logging.side_effect = [0, 1] with pytest.raises(exceptions.SupplyError) as exc: git.checkout("/src", "feature-branch") assert exc.value.args[ 0] == "Could not checkout [feature-branch]. Do you have uncommitted changes?" run_subprocess_with_logging.assert_called_with( "git -C /src checkout feature-branch")
def _update(self, distribution_version): try: if self.remote: branch = versions.best_match(git.branches(self.tracks_dir, remote=self.remote), distribution_version) if branch: logger.info("Rebasing on '%s' in '%s' for distribution version '%s'." % (branch, self.tracks_dir, distribution_version)) git.rebase(self.tracks_dir, branch=branch) return else: msg = "Could not find track data remotely for distribution version %s. " \ "Trying to find track data locally." % distribution_version logger.warn(msg) branch = versions.best_match(git.branches(self.tracks_dir, remote=False), distribution_version) if branch: logger.info("Checking out '%s' in '%s' for distribution version '%s'." % (branch, self.tracks_dir, distribution_version)) git.checkout(self.tracks_dir, branch=branch) else: raise exceptions.SystemSetupError("Cannot find track data for distribution version %s" % distribution_version) except exceptions.SupplyError as e: raise exceptions.DataError("Cannot update track data in '%s': %s" % (self.tracks_dir, e))
def checkout(self, revision): self.logger.info("Checking out revision [%s] in [%s].", revision, self.repo_dir) git.checkout(self.repo_dir, revision)
def test_checkout_successful(self, run_subprocess_with_logging, run_subprocess): run_subprocess_with_logging.return_value = 0 run_subprocess.return_value = False git.checkout("/src", "feature-branch") run_subprocess.assert_called_with("git -C /src checkout --quiet feature-branch")