def get_package_env(version=None, release=None, dist=None, patches_branch=None, local_patches_branch=None): branch = git.current_branch() if branch.endswith('-patches'): branch = branch[:-8] if git.branch_exists(branch): log.info("This looks like -patches branch. Assuming distgit branch: " "%s" % branch) git.checkout(branch) else: raise exception.InvalidUsage( why="This action must be run on a distgit branch.") args = { 'package': guess.package(), 'branch': branch, } if not release or not dist: _release, _dist = guess.osreleasedist(branch, default=(None, None)) if not release and _release: args['release'] = _release if not dist and _dist: args['dist'] = _dist osdist = guess.osdist() if osdist == 'RHOS': log.info("RHOS package detected.") args['fedpkg'] = ['rhpkg'] if not patches_branch: patches_branch = guess.patches_branch(branch, pkg=args['package'], osdist=osdist) args['patches_branch'] = patches_branch if not local_patches_branch: args['local_patches_branch'] = patches_branch.partition('/')[2] if not version: args['version'] = guess.current_version() return args
def get_package_env(version=None, release=None, dist=None, patches_branch=None, local_patches_branch=None): branch = git.current_branch() if branch.endswith("-patches"): branch = branch[:-8] if git.branch_exists(branch): log.info("This looks like -patches branch. Assuming distgit branch: " "%s" % branch) git.checkout(branch) else: raise exception.InvalidUsage(why="This action must be run on a distgit branch.") args = {"package": guess.package(), "branch": branch} if not release or not dist: _release, _dist = guess.osreleasedist(branch, default=(None, None)) if not release and _release: args["release"] = _release if not dist and _dist: args["dist"] = _dist osdist = guess.osdist() if osdist == "RHOS": log.info("RHOS package detected.") args["fedpkg"] = ["rhpkg"] if not patches_branch: patches_branch = guess.patches_branch(branch, pkg=args["package"], osdist=osdist) args["patches_branch"] = patches_branch if not local_patches_branch: args["local_patches_branch"] = patches_branch.partition("/")[2] if not version: version = guess.current_version() args["version"] = version args["version_tag_style"] = guess.version_tag_style(version=version) return args
def current_branch(default=exception.CantGuess): try: branch = git.current_branch() except exception.CommandFailed: if default is exception.CantGuess: raise exception.CantGuess( what="branch", why="git command failed (not in a git repo?)") else: return default if not branch: if default is exception.CantGuess: raise exception.CantGuess(what="branch", why="git command returned no output") else: return default return branch
def _ensure_branch(branch): if not branch: return if git.current_branch() != branch: git.checkout(branch)