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) self.revision = git.head_revision(self.repo_dir) 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) self.revision = git.head_revision(self.repo_dir) else: self.logger.info( "No local branch found for distribution version [%s] in [%s]. Checking tags.", distribution_version, self.repo_dir) tag = self._find_matching_tag(distribution_version) if tag: self.logger.info( "Checking out tag [%s] in [%s] for distribution version [%s].", tag, self.repo_dir, distribution_version) git.checkout(self.repo_dir, branch=tag) self.revision = git.head_revision(self.repo_dir) 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 test_git_version_too_old(self, run_subprocess_with_logging, run_subprocess): run_subprocess_with_logging.return_value = False run_subprocess.return_value = "1.0.0" with self.assertRaises(exceptions.SystemSetupError) as ctx: git.head_revision("/src") self.assertEqual("Your git version is [1.0.0] but Rally requires at least git 1.9. Please update git.", ctx.exception.args[0]) run_subprocess_with_logging.assert_called_with("git -C /src --version", level=logging.DEBUG)
def test_git_version_too_old(self, run_subprocess_with_logging, run_subprocess): # any non-zero return value will do run_subprocess_with_logging.return_value = 64 run_subprocess.return_value = "1.0.0" with pytest.raises(exceptions.SystemSetupError) as exc: git.head_revision("/src") assert exc.value.args[ 0] == "Your git version is [1.0.0] but Rally requires at least git 1.9. Please update git." run_subprocess_with_logging.assert_called_with("git -C /src --version", level=logging.DEBUG)
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 version(): release = __version__ try: if git.is_working_copy(io.normalize_path("%s/.." % rally_root_path())): revision = git.head_revision(rally_root_path()) return "%s (git revision: %s)" % (release, revision.strip()) except BaseException: pass # cannot determine head revision so user has probably installed Rally via pip instead of git clone return release
def revision(): """ :return: The current git revision if Rally is installed in development mode or ``None``. """ # noinspection PyBroadException try: if git.is_working_copy(io.normalize_path("%s/.." % paths.rally_root())): raw_revision = git.head_revision(paths.rally_root()) return raw_revision.strip() except BaseException: pass return None
def _update(self, revision): if revision == "latest": logger.info("Fetching latest sources from origin.") git.pull(self.src_dir) elif revision == "current": logger.info("Skip fetching sources") elif revision.startswith("@"): # convert timestamp annotated for Rally to something git understands -> we strip leading and trailing " and the @. git.pull_ts(self.src_dir, revision[1:]) else: # assume a git commit hash git.pull_revision(self.src_dir, revision) git_revision = git.head_revision(self.src_dir) logger.info("Specified revision [%s] on command line results in git revision [%s]" % (revision, git_revision))
def _update(self, revision): if revision == "latest": logger.info("Fetching latest sources for %s from origin." % self.name) git.pull(self.src_dir) elif revision == "current": logger.info("Skip fetching sources for %s." % self.name) elif revision.startswith("@"): # convert timestamp annotated for Rally to something git understands -> we strip leading and trailing " and the @. git.pull_ts(self.src_dir, revision[1:]) else: # assume a git commit hash git.pull_revision(self.src_dir, revision) git_revision = git.head_revision(self.src_dir) logger.info("Specified revision [%s] for [%s] on command line results in git revision [%s]" % (revision, self.name, git_revision))
def version(): """ :return: The release version string and an optional suffix for the current git revision if Rally is installed in development mode. """ release = __version__ # noinspection PyBroadException try: if git.is_working_copy(io.normalize_path("%s/.." % paths.rally_root())): revision = git.head_revision(paths.rally_root()) return "%s (git revision: %s)" % (release, revision.strip()) except BaseException: pass # cannot determine head revision so user has probably installed Rally via pip instead of git clone return release
def test_head_revision(self, run_subprocess_with_logging, run_subprocess): run_subprocess_with_logging.return_value = 0 run_subprocess.return_value = ["3694a07"] self.assertEqual("3694a07", git.head_revision("/src")) run_subprocess.assert_called_with("git -C /src rev-parse --short HEAD")
def correct_revision(self, revision): return git.head_revision(self.repo_dir) == revision