def main(args, stdout=sys.stdout, stderr=sys.stderr): parser = argparse.ArgumentParser( prog='git hyper-blame', description='git blame with support for ignoring certain commits.') parser.add_argument('-i', metavar='REVISION', action='append', dest='ignored', default=[], help='a revision to ignore') parser.add_argument('--ignore-file', metavar='FILE', type=argparse.FileType('r'), dest='ignore_file', help='a file containing a list of revisions to ignore') parser.add_argument('--no-default-ignores', dest='no_default_ignores', action='store_true', help='Do not ignore commits from .git-blame-ignore-revs.') parser.add_argument('revision', nargs='?', default='HEAD', metavar='REVISION', help='revision to look at') parser.add_argument('filename', metavar='FILE', help='filename to blame') args = parser.parse_args(args) try: repo_root = git_common.repo_root() except subprocess2.CalledProcessError as e: stderr.write(e.stderr.decode()) return e.returncode # Make filename relative to the repository root, and cd to the root dir (so # all filenames throughout this script are relative to the root). filename = os.path.relpath(args.filename, repo_root) os.chdir(repo_root) # Normalize filename so we can compare it to other filenames git gives us. filename = os.path.normpath(filename) filename = os.path.normcase(filename) ignored_list = list(args.ignored) if not args.no_default_ignores and os.path.exists(DEFAULT_IGNORE_FILE_NAME): with open(DEFAULT_IGNORE_FILE_NAME) as ignore_file: ignored_list.extend(parse_ignore_file(ignore_file)) if args.ignore_file: ignored_list.extend(parse_ignore_file(args.ignore_file)) ignored = set() for c in ignored_list: try: ignored.add(git_common.hash_one(c)) except subprocess2.CalledProcessError as e: # Custom warning string (the message from git-rev-parse is inappropriate). stderr.write('warning: unknown revision \'%s\'.\n' % c) return hyper_blame(ignored, filename, args.revision, out=stdout, err=stderr)
def main(args, stdout=sys.stdout, stderr=sys.stderr): parser = argparse.ArgumentParser( prog='git hyper-blame', description='git blame with support for ignoring certain commits.') parser.add_argument('-i', metavar='REVISION', action='append', dest='ignored', default=[], help='a revision to ignore') parser.add_argument('--ignore-file', metavar='FILE', type=argparse.FileType('r'), dest='ignore_file', help='a file containing a list of revisions to ignore') parser.add_argument('--no-default-ignores', dest='no_default_ignores', action='store_true', help='Do not ignore commits from .git-blame-ignore-revs.') parser.add_argument('revision', nargs='?', default='HEAD', metavar='REVISION', help='revision to look at') parser.add_argument('filename', metavar='FILE', help='filename to blame') args = parser.parse_args(args) try: repo_root = git_common.repo_root() except subprocess2.CalledProcessError as e: stderr.write(e.stderr) return e.returncode # Make filename relative to the repository root, and cd to the root dir (so # all filenames throughout this script are relative to the root). filename = os.path.relpath(args.filename, repo_root) os.chdir(repo_root) # Normalize filename so we can compare it to other filenames git gives us. filename = os.path.normpath(filename) filename = os.path.normcase(filename) ignored_list = list(args.ignored) if not args.no_default_ignores and os.path.exists(DEFAULT_IGNORE_FILE_NAME): with open(DEFAULT_IGNORE_FILE_NAME) as ignore_file: ignored_list.extend(parse_ignore_file(ignore_file)) if args.ignore_file: ignored_list.extend(parse_ignore_file(args.ignore_file)) ignored = set() for c in ignored_list: try: ignored.add(git_common.hash_one(c)) except subprocess2.CalledProcessError as e: # Custom warning string (the message from git-rev-parse is inappropriate). stderr.write('warning: unknown revision \'%s\'.\n' % c) return hyper_blame(ignored, filename, args.revision, out=stdout, err=stderr)
def main(): remote = git_common.run('remote') # Use first remote as source of truth remote = remote.split("\n")[0] if not remote: raise RuntimeError('Could not find any remote') url = scm.GIT.GetConfig(git_common.repo_root(), 'remote.%s.url' % remote) host = urllib.parse.urlparse(url).netloc if not host: raise RuntimeError('Could not find remote host') project_head = gerrit_util.GetProjectHead(GetGerritHost(host), GetGerritProject(url)) if project_head != 'refs/heads/main': raise RuntimeError("The repository is not migrated yet.") logging.info("Running fetch...") git_common.run('fetch', remote) logging.info("Updating remote HEAD...") git_common.run('remote', 'set-head', '-a', remote) branches = git_common.get_branches_info(True) if 'master' in branches: logging.info("Migrating master branch...") if 'main' in branches: logging.info( 'You already have master and main branch, consider removing ' 'master manually:\n' ' $ git branch -d master\n') else: git_common.run('branch', '-m', 'master', 'main') branches = git_common.get_branches_info(True) for name in branches: branch = branches[name] if not branch: continue if 'master' in branch.upstream: logging.info("Migrating %s branch..." % name) new_upstream = branch.upstream.replace('master', 'main') git_common.run('branch', '--set-upstream-to', new_upstream, name) git_common.remove_merge_base(name)
def main(args, stdout=sys.stdout, stderr=sys.stderr): parser = argparse.ArgumentParser( prog='git hyper-blame', description='git blame with support for ignoring certain commits.') parser.add_argument('-i', metavar='REVISION', action='append', dest='ignored', default=[], help='a revision to ignore') parser.add_argument('revision', nargs='?', default='HEAD', metavar='REVISION', help='revision to look at') parser.add_argument('filename', metavar='FILE', help='filename to blame') args = parser.parse_args(args) try: repo_root = git_common.repo_root() except subprocess2.CalledProcessError as e: stderr.write(e.stderr) return e.returncode # Make filename relative to the repository root, and cd to the root dir (so # all filenames throughout this script are relative to the root). filename = os.path.relpath(args.filename, repo_root) os.chdir(repo_root) # Normalize filename so we can compare it to other filenames git gives us. filename = os.path.normpath(filename) filename = os.path.normcase(filename) ignored = set() for c in args.ignored: try: ignored.add(git_common.hash_one(c)) except subprocess2.CalledProcessError as e: # Custom error message (the message from git-rev-parse is inappropriate). stderr.write('fatal: unknown revision \'%s\'.\n' % c) return e.returncode return hyper_blame(ignored, filename, args.revision, out=stdout, err=stderr)