[
  {
    "path": ".gitignore",
    "content": "git_rewrite_author.egg-info/\nbuild/\ndist/\n"
  },
  {
    "path": "README.rst",
    "content": "Rewrite author/committer history of a git repository\n====================================================\n\nHave you ever accidentally committed to a git repository with a broken\nuser config?  No?  But your co-workers have?\n\nSo, you're stuck with commits like this::\n\n    Author: root <root@localhost>\n\n        Hotfix on the production server.  This was urgent!\n\nNasty.  Or::\n\n    Author: John Doe <john@localhost>\n\n        Fixed bug #1.  Committed on my laptop.\n\nWould it be nice to rewrite history?  And take care of committers, as\nwell as of authors?  Without all the hassle?  Now, you can!\n\nUsage::\n\n    $ git rewrite-author -w \"John Doe <john@localhost>\" \"John Doe <dearjohn@example.com>\"\n\nThen, to push your changes to the default remote::\n\n    $ git push --force\n\nNot using --force may duplicate the commits on origin, not replace them, so be careful with that.\n\nYou're not sure which authors/committers are hidden in your repository?\nWhat about::\n\n    $ git rewrite-author -l\n\nTags are rewritten automagically, too!\n\nAfter you've checked everything is okay, you may wish to remove the original refs backed up by git --filter-branch::\n\n    $ git for-each-ref --format=\"%(refname)\" refs/original/ | xargs -r -n 1 git update-ref -d\n\n\nEnjoy!\n\n\nInstallation\n------------\n\nClone or download this repository and run::\n\n    $ python setup.py install\n"
  },
  {
    "path": "git-rewrite-author",
    "content": "#!/usr/bin/env python\n\n\"\"\"Rewrite author/committer history of a git repository\n\nHave you ever accidentally committed to a git repository with a broken\nuser config?  No?  But your co-workers have?\n\nSo, you're stuck with commits like this::\n\n    Author: root <root@localhost>\n\n        Hotfix on the production server.  This was urgent!\n\nNasty.  Or::\n\n    Author: John Doe <john@localhost>\n\n        Fixed bug #1.  Committed on my laptop.\n\nWould it be nice to rewrite history?  And take care of committers, as\nwell as of authors?  Without all the hassle?  Now, you can!\n\nUsage::\n\n    $ git rewrite-author -w \"John Doe <john@localhost>\" \"John Doe <dearjohn@example.com>\"\n\nThen, to push your changes to the default remote::\n\n    $ git push --force\n\nNot using --force may duplicate the commits on origin, not replace them, so be careful with that.\n\nYou're not sure which authors/committers are hidden in your repository?\nWhat about::\n\n    $ git rewrite-author -l\n\nTags are rewritten automagically, too!\n\nEnjoy!\n\n\nInstallation\n------------\n\nClone or download this repository and run::\n\n    $ python setup.py install\n\n\"\"\"\nimport argparse\nimport re\nimport subprocess\nimport textwrap\n\n\ndescription = \"Rewrite author/committer in git history\"\nepilog = \"\"\"\nExample:\n\n$ git-rewrite-author -w \"Name <me@localhost>\" \"Full Name <me@example.com>\"\n\"\"\"\n\ngit_rewrite_command = \"\"\"git filter-branch --env-filter '\n    if [ \"$GIT_AUTHOR_NAME\" = \"%(old_name)s\" -a \"$GIT_AUTHOR_EMAIL\" = \"%(old_email)s\" ]; then\n        export GIT_AUTHOR_NAME=\"%(new_name)s\";\n        export GIT_AUTHOR_EMAIL=\"%(new_email)s\";\n    fi;\n' --tag-name-filter cat -f -- --all\"\"\"\ngit_log_command = \"git log --pretty=full\"\n\n\ndef parse_args():\n    \"\"\"Parse command-line arguments\"\"\"\n\n    parser = argparse.ArgumentParser(description=description,\n                         epilog=epilog,\n                         formatter_class=argparse.RawDescriptionHelpFormatter)\n    parser.add_argument('-l', '--list', action='store_true',\n                        help=\"List all authors and committers\")\n    parser.add_argument('-w', '--rewrite', nargs=2,\n                        metavar=('old', 'new'), type=str,\n                        help=\"Rewrite authors and committers\")\n    return parser.parse_args()\n\n\ndef main(args):\n    \"\"\"Rewrite history using args\"\"\"\n\n    if args.list:\n        list_git_authors()\n    elif args.rewrite:\n        old_name, old_email = parse_author_arg(args.rewrite[0])\n        new_name, new_email = parse_author_arg(args.rewrite[1])\n\n        rewrite_git_author(old_name, old_email, new_name, new_email)\n        rewrite_git_committer(old_name, old_email, new_name, new_email)\n    else:\n        print(\"Doing nothing.  Invoke with -h for help.\")\n\n\ndef parse_author_arg(arg):\n    \"\"\"Parse name/email argument\"\"\"\n\n    name, email = re.match(\"(.+)\\s<(.*)>\", arg).groups()\n    return name, email\n\n\ndef rewrite_git_author(old_name, old_email, new_name, new_email):\n    \"\"\"Rewrite author history in git\"\"\"\n\n    command = git_rewrite_command % \\\n        { 'old_name': old_name, 'old_email': old_email, 'new_name': new_name, 'new_email': new_email}\n    subprocess.call(command, shell=True)\n\n\ndef rewrite_git_committer(old_name, old_email, new_name, new_email):\n    \"\"\"Rewrite committer history in git\"\"\"\n\n    command = git_rewrite_command.replace('AUTHOR', 'COMMITTER') % \\\n        { 'old_name': old_name, 'old_email': old_email, 'new_name': new_name, 'new_email': new_email}\n    subprocess.call(command, shell=True)\n\n\ndef list_git_authors():\n    \"\"\"List authors and committers\"\"\"\n\n    output = subprocess.check_output(git_log_command.split(' '))\n    matches = re.findall(b'(Author|Commit): (.*)\\n', output)\n    names = [u[1].decode('utf-8') for u in matches]\n    unique_names = sorted(set(names))\n\n    print(\"The following authors and committers have contributed:\\n\")\n    for name in unique_names:\n        print(name)\n\n\nif __name__ == '__main__':\n    args = parse_args()\n    main(args)\n"
  },
  {
    "path": "setup.py",
    "content": "#!/usr/bin/env python\n\nfrom setuptools import setup\n\nsetup(name='git rewrite author',\n      version='1.0',\n      description='Rewrite author/committer history of a git repository',\n      author='David Fokkema',\n      author_email='davidfokkema@icloud.com',\n      url='https://github.com/davidfokkema/git-rewrite-author',\n      classifiers=['Intended Audience :: Developers',\n                   'Environment :: Console',\n                   'Programming Language :: Python :: 2.7',\n                   'Topic :: Software Development :: Version Control',\n                   'License :: OSI Approved :: GNU General Public License v3 (GPLv3)'],\n      scripts=['git-rewrite-author'])\n"
  }
]