def final_spec_diff(branch=None): _ensure_branch(branch) print("Important distgit changes:") spec = specfile.Spec() git("--no-pager", "diff", "HEAD~..HEAD", "--", spec.fn, direct=True) print("") git("--no-pager", "log", "--name-status", "HEAD~..HEAD", direct=True) print("\nRequested distgit update finished, see last commit.")
def final_spec_diff(branch=None): _ensure_branch(branch) print("Important distgit changes:") spec = specfile.Spec() git('--no-pager', 'diff', 'HEAD~..HEAD', '--', spec.fn, direct=True) print("") git('--no-pager', 'log', '--name-status', 'HEAD~..HEAD', direct=True) print("\nRequested distgit update finished, see last commit.")
def diff(version, new_version, bump_only=False, no_diff=False): if bump_only or no_diff: return git('--no-pager', 'diff', '--stat', '%s..%s' % (version, new_version), direct=True) try: reqdiff(version, new_version) except Exception: pass raw_input("Press <Enter> to continue after you inspected the diff. ")
def diff(version, new_version, bump_only=False, no_diff=False, version_tag_style=None): if bump_only or no_diff: return vtag_from = guess.version2tag(version, version_tag_style) vtag_to = guess.version2tag(new_version, version_tag_style) git("--no-pager", "diff", "--stat", "%s..%s" % (vtag_from, vtag_to), direct=True) try: reqdiff(vtag_from, vtag_to) except Exception: pass raw_input("Press <Enter> to continue after you inspected the diff. ")
def koji_build(update_file=None, skip_build=False): if skip_build: log.info("\nSkipping koji build due to -s/--skip-build") fcmd = kojibuild.get_fedpkg_commands() build_id = fcmd.nvr else: if git.branch_needs_push(): helpers.confirm("It seems local distgit branch needs push. Push " "now?") git('push') build_id = kojibuild.new_build() build = kojibuild.guess_build(build_id) _show_update_entry(build) if update_file: _update.dump_build(build, update_file)
def koji_build(update_file=None, skip_build=False): if skip_build: log.info("\nSkipping koji build due to -s/--skip-build") fcmd = kojibuild.get_fedpkg_commands() build_id = fcmd.nvr else: if git.branch_needs_push(): helpers.confirm("It seems local distgit branch needs push. Push " "now?") git("push") build_id = kojibuild.new_build() build = kojibuild.guess_build(build_id) if not build: raise exception.CantGuess(what="build arguments", why="Unknown branch? Check `rdopkg pkgenv` and `rdopkg info`") _show_update_entry(build) if update_file: _update.dump_build(build, update_file)
def gerrit_from_repo(): # assuming we're in a git repository gerrit = [p for p in git('remote', '-v', log_cmd=False).split('\n') if p.startswith('review-patches')][0] # discard ssh://, pick user@hostname + port from uri and split them gerrit_url = [g[len('ssh://'):].split('/')[0] for g in gerrit.split('\t') if g.startswith('ssh://')][0].split(':') return gerrit_url
def move_files(files, to_dir=None): for from_path in files: bn = os.path.basename(from_path) if to_dir: _to_dir = to_dir else: # ready dir depends on update tag update = check_file(from_path) _to_dir = update.get_ready_dir() if not os.path.exists(_to_dir): os.makedirs(_to_dir) to_path = "%s/%s" % (_to_dir, bn) assert(from_path and to_path) author = git.get_file_authors(from_path)[0] git('mv', from_path, to_path) msg = "Move %s to %s/" % (core.pp_update(from_path), _to_dir) git('commit', '-a', '-F', '-', '--author', author, input=msg, print_output=True)
def project_from_repo(): # assuming we're in a git repository proj = [p for p in git('remote', '-v', log_cmd=False).split('\n') if p.startswith('patches')][0] project = '/'.join(proj.split('/')[-2:]) # remove (fetch) or (push) project = project.split(' ')[0] if project.endswith('.git'): project = project[:-len('.git')] return project
def update_patches(branch, local_patches_branch, version=None, new_version=None, version_tag_style=None, amend=False, bump_only=False): if bump_only: return target_version = new_version or version if not target_version: raise exception.RequiredActionArgumentNotAvailable( action='update_patches', arg='version or new_version') tag = guess.version2tag(target_version, version_tag_style) _ensure_branch(local_patches_branch) patches = git.get_commits(tag, local_patches_branch) n_patches = len(patches) _ensure_branch(branch) spec = specfile.Spec() spec.sanity_check() n_excluded = spec.get_n_excluded_patches() patch_fns = spec.get_patch_fns() for pfn in patch_fns: git('rm', '--ignore-unmatch', pfn) patch_fns = [] if n_excluded > 0: patches = patches[:-n_excluded] log.info("\n{t.bold}{n} patches{t.normal} on top of {t.bold}{tag}{t.normal}" ", {t.bold}{ne}{t.normal} excluded".format( t=log.term, n=n_patches, tag=tag, ne=n_excluded)) if patches: start_commit = patches[-1][0] for hsh, title in patches: log.info("%s %s" % (log.term.green(hsh), title)) rng = git.rev_range(start_commit + '~', local_patches_branch) o = git('format-patch', '--no-renames', '--no-signature', '-N', '--ignore-submodules', rng) patch_fns = git._parse_output(o) for pfn in patch_fns: git('add', pfn) spec.set_new_patches(patch_fns) patches_branch_ref = git('rev-parse', local_patches_branch) spec.set_commit_ref_macro(patches_branch_ref) spec.save() if git.is_clean(): log.info('No new patches.') return msg = 'Updated patches from ' + local_patches_branch git('commit', '-a', '-m', msg) if amend: git.squash_last()
def project_from_repo(): # assuming we're in a git repository proj = [ p for p in git('remote', '-v', log_cmd=False).split('\n') if p.startswith('patches') ][0] project = '/'.join(proj.split('/')[-2:]) # remove (fetch) or (push) project = project.split(' ')[0] if project.endswith('.git'): project = project[:-len('.git')] return project
def gerrit_from_repo(): # assuming we're in a git repository gerrit = [ p for p in git('remote', '-v', log_cmd=False).split('\n') if p.startswith('review-patches') ][0] # discard ssh://, pick user@hostname + port from uri and split them gerrit_url = [ g[len('ssh://'):].split('/')[0] for g in gerrit.split('\t') if g.startswith('ssh://') ][0].split(':') return gerrit_url
def clone(package, force_fetch=False, use_master_distgit=False): inforepo = rdoinfo.get_default_inforepo() inforepo.init(force_fetch=force_fetch) pkg = inforepo.get_package(package) if not pkg: raise exception.InvalidRDOPackage(package=package) if use_master_distgit: try: distgit = pkg['master-distgit'] distgit_str = 'master-distgit' except KeyError: raise exception.InvalidUsage( msg="-m/--use-master-distgit used but 'master-distgit' " "missing in rdoinfo for package: %s" % package) else: distgit = pkg['distgit'] distgit_str = 'distgit' log.info("Cloning {dg} into ./{t.bold}{pkg}{t.normal}/".format( t=log.term, dg=distgit_str, pkg=package)) patches = pkg.get('patches') upstream = pkg.get('upstream') git('clone', distgit, package) with helpers.cdir(package): if patches: log.info('Adding patches remote...') git('remote', 'add', 'patches', patches) else: log.warn("'patches' remote information not available in rdoinfo.") if upstream: log.info('Adding upstrem remote...') git('remote', 'add', 'upstream', upstream) else: log.warn("'upstream' remote information not available in rdoinfo.") if patches or upstream: git('fetch', '--all') git('remote', '-v', direct=True)
def clone(package, force_fetch=False, use_master_distgit=False): inforepo = rdoinfo.get_default_inforepo() inforepo.init(force_fetch=force_fetch) pkg = inforepo.get_package(package) if not pkg: raise exception.InvalidRDOPackage(package=package) if use_master_distgit: try: distgit = pkg["master-distgit"] distgit_str = "master-distgit" except KeyError: raise exception.InvalidUsage( msg="-m/--use-master-distgit used but 'master-distgit' " "missing in rdoinfo for package: %s" % package ) else: distgit = pkg["distgit"] distgit_str = "distgit" log.info("Cloning {dg} into ./{t.bold}{pkg}{t.normal}/".format(t=log.term, dg=distgit_str, pkg=package)) patches = pkg.get("patches") upstream = pkg.get("upstream") git("clone", distgit, package) with helpers.cdir(package): if patches: log.info("Adding patches remote...") git("remote", "add", "patches", patches) else: log.warn("'patches' remote information not available in rdoinfo.") if upstream: log.info("Adding upstream remote...") git("remote", "add", "upstream", upstream) else: log.warn("'upstream' remote information not available in rdoinfo.") if patches or upstream: git("fetch", "--all") git("remote", "-v", direct=True)
def get_last_commit_update(dir='.'): with helpers.cdir(dir): out = git('diff', '--name-status', 'HEAD~..HEAD', log_cmd=False).strip() if out.find("\n") != -1: raise exception.InvalidUpdateCommit( msg="Last commit changes more than one file.") m = re.match('^([A-Z])\s+(\S+)$', out) if not m: raise exception.ParsingError(what="git diff output", str=out) status = m.group(1) if status != 'A' and status != 'M': raise exception.InvalidUpdateCommit( msg=("Invalid file status %s, should be A(dded) or M(odified)" % status)) fn = m.group(2) return fn
def get_upstream_patches(version, local_patches_branch, patches_branch=None, upstream_branch=None, new_milestone=None): patches = git( "log", "--cherry-pick", "--pretty=format:\%s", "%(remote)s...%(local)s" % {"remote": patches_branch, "local": local_patches_branch}, ) changes = [p.strip().replace("\\", "") for p in patches.split("\n") if p != ""] if not changes: log.warn("No new patches detected in %s." % local_patches_branch) helpers.confirm("Do you want to continue anyway?", default_yes=False) n_patches = len(changes) changes.insert(0, ("Rebase %s changes from %s" % (n_patches, upstream_branch))) args = {"changes": changes} if n_patches > 0: if new_milestone: new_milestone += ".p%d" % n_patches else: new_milestone = "p%d" % n_patches args["new_milestone"] = new_milestone return args
def get_upstream_patches(version, local_patches_branch, patches_branch=None, upstream_branch=None, new_milestone=None): patches = git("log", "--cherry-pick", "--pretty=format:\%s", "%(remote)s...%(local)s" % {'remote': patches_branch, 'local': local_patches_branch}) changes = [p.strip().replace('\\', '') for p in patches.split('\n') if p != ''] if not changes: log.warn("No new patches detected in %s." % local_patches_branch) helpers.confirm("Do you want to continue anyway?", default_yes=False) n_patches = len(changes) changes.insert(0, ("Rebase %s changes from %s" % (n_patches, upstream_branch))) args = {'changes': changes} if n_patches > 0: if new_milestone: new_milestone += '.p%d' % n_patches else: new_milestone = 'p%d' % n_patches args['new_milestone'] = new_milestone return args
def rebase_patches_branch( new_version, local_patches_branch, patches_branch=None, local_patches=False, bump_only=False, version_tag_style=None ): if bump_only: return git.checkout(local_patches_branch) new_version_tag = guess.version2tag(new_version, version_tag_style) git("rebase", new_version_tag, direct=True) if local_patches or not patches_branch: return if _is_same_commit(local_patches_branch, patches_branch): log.info("%s is up to date, no need for push." % patches_branch) return try: remote, branch = git.remote_branch_split(patches_branch) helpers.confirm("Push %s to %s / %s (with --force)?" % (local_patches_branch, remote, branch)) git("push", "--force", remote, "%s:%s" % (local_patches_branch, branch)) # push the tag git("push", "--force", remote, new_version_tag) except exception.UserAbort: pass
def rebase_patches_branch(new_version, local_patches_branch, patches_branch=None, local_patches=False, bump_only=False): if bump_only: return git.checkout(local_patches_branch) git('rebase', new_version, direct=True) if local_patches or not patches_branch: return if _is_same_commit(local_patches_branch, patches_branch): log.info("%s is up to date, no need for push." % patches_branch) return try: remote, branch = git.remote_branch_split(patches_branch) helpers.confirm("Push %s to %s / %s (with --force)?" % ( local_patches_branch, remote, branch)) git('push', '--force', remote, '%s:%s' % (local_patches_branch, branch)) # push the tag git('push', '--force', remote, new_version) except exception.UserAbort: pass
def fetch_all(): git('fetch', '--all', direct=True)
def _is_same_commit(ref1, ref2): h1 = git('rev-parse', ref1, log_cmd=False) h2 = git('rev-parse', ref2, log_cmd=False) return h1 and h1 == h2
def _reset_branch(branch, remote_branch): if git.branch_exists(branch): git('update-ref', 'refs/heads/%s' % branch, 'refs/remotes/%s' % remote_branch) else: git.create_branch(branch, remote_branch)
def amend(): msg = _commit_message() git("commit", "-a", "--amend", "-F", "-", input=msg, print_output=True) print("") git("--no-pager", "log", "--name-status", "HEAD~..HEAD", direct=True)
def amend(): msg = _commit_message() git('commit', '-a', '--amend', '-F', '-', input=msg, print_output=True) print("") git('--no-pager', 'log', '--name-status', 'HEAD~..HEAD', direct=True)
def _reset_branch(branch, remote_branch): if git.branch_exists(branch): git("update-ref", "refs/heads/%s" % branch, "refs/remotes/%s" % remote_branch) else: git.create_branch(branch, remote_branch)
def fetch_all(): git("fetch", "--all", direct=True)
def email(): email = git('config', 'user.email', log_cmd=False, fatal=False) if not email: raise exception.CantGuess(what="user email", why='git config user.email not set') return email
def user(): user = git('config', 'user.name', log_cmd=False, fatal=False) if not user: raise exception.CantGuess(what="user name", why='git config user.name not set') return user.decode('utf-8')
def commit_distgit_update(branch=None): _ensure_branch(branch) msg = _commit_message() git('commit', '-a', '-F', '-', input=msg, print_output=True)
def commit_distgit_update(branch=None): _ensure_branch(branch) msg = _commit_message() git("commit", "-a", "-F", "-", input=msg, print_output=True)