[
  {
    "path": ".gitignore",
    "content": ".DS_Store\n__pycache__\n*.pyc\nmedia/\ngit-story_media/\nbuild/\ndist/\ngit_story.egg-info/\n"
  },
  {
    "path": "MANIFEST.in",
    "content": "include git_story/logo.png\n"
  },
  {
    "path": "README.md",
    "content": "# git-story\nTell the story of your Git project by creating video animations (.mp4)\nof your commit history directly from your Git repo.\n\n## Use cases\n- Visualizing Git projects\n- Sharing desired parts of your workflow with your team\n- Creating animated Git videos for blog posts or YouTube\n- Helping newer developers learn Git\n\n## Features\n- Run a single command in the terminal to generate a custom Git animation (.mp4) from your repo\n- Specify any commit id or ref to start animating from (default: `HEAD`)\n- Specify the number of commits to include (default: `8`)\n- Ref labels are drawn by default for `HEAD`, branch names, and tags\n- Reverse commit ordering and reorient branch layout\n- Works best with simpler branching structures, but should work with more complex ones as well\n- Add custom branded intro/outro sequences if desired\n- Dark mode and light mode\n\n## Video animation example\nhttps://user-images.githubusercontent.com/49353917/179362209-48748966-6d6c-46ff-9424-b1a7266fc83f.mp4\n\n## Requirements\n* Python 3.9 or greater\n* Pip (Package manager for Python)\n* [Manim (Community version)](https://www.manim.community/)\n* GitPython\n\n## Quickstart\n1) Install [manim and manim dependencies for your OS](https://www.manim.community/)\n\n2) Install GitPython\n\n```console\n$ pip3 install gitpython\n```\n\n3) Install `git-story`:\n\n```console\n$ pip3 install git-story\n```\n\n3) Browse to the Git repository you want create an animation from:\n\n```console\n$ cd path/to/project/root\n```\n\n4) Run the program:\n\n```console\n$ git-story\n```\n\n5) A default animation `.mp4` file will be created using the most recent 8 commits on your checked-out Git branch. By default, video output file is created in the current directory, within a subdirectory called `git-story_media`. The location this subdirectory is customizeable using the command line flag `--media-dir=path/to/output`.\n\n6) Use command-line options for customization, see usage:\n\n```console\n$ git-story -h\n\nusage: git-story [-h] [--commits COMMITS] [--commit-id COMMIT_ID] [--hide-merged-chains] [--reverse] [--title TITLE] [--logo LOGO] [--outro-top-text OUTRO_TOP_TEXT]\n                 [--outro-bottom-text OUTRO_BOTTOM_TEXT] [--show-intro] [--show-outro] [--max-branches-per-commit MAX_BRANCHES_PER_COMMIT] [--max-tags-per-commit MAX_TAGS_PER_COMMIT]\n                 [--media-dir MEDIA_DIR] [--low-quality] [--light-mode] [--invert-branches]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --commits COMMITS     The number of commits to display in the Git animation (default: 8)\n  --commit-id COMMIT_ID\n                        The ref (branch/tag), or first 6 characters of the commit to animate backwards from (default: HEAD)\n  --hide-merged-chains  Hide commits from merged branches, i.e. only display mainline commits (default: False)\n  --reverse             Display commits in reverse order in the Git animation (default: False)\n  --title TITLE         Custom title to display at the beginning of the animation (default: Git Story, by initialcommit.com)\n  --logo LOGO           The path to a custom logo to use in the animation intro/outro (default: /usr/local/lib/python3.9/site-packages/git_story/logo.png)\n  --outro-top-text OUTRO_TOP_TEXT\n                        Custom text to display above the logo during the outro (default: Thanks for using Initial Commit!)\n  --outro-bottom-text OUTRO_BOTTOM_TEXT\n                        Custom text to display below the logo during the outro (default: Learn more at initialcommit.com)\n  --show-intro          Add an intro sequence with custom logo and title (default: False)\n  --show-outro          Add an outro sequence with custom logo and text (default: False)\n  --max-branches-per-commit MAX_BRANCHES_PER_COMMIT\n                        Maximum number of branch labels to display for each commit (default: 2)\n  --max-tags-per-commit MAX_TAGS_PER_COMMIT\n                        Maximum number of tags to display for each commit (default: 1)\n  --media-dir MEDIA_DIR\n                        The path to output the animation data and video file (default: .)\n  --low-quality         Render output video in low quality, useful for faster testing (default: False)\n  --light-mode          Enable light-mode with white background (default: False)\n  --invert-branches     Invert positioning of branches where applicable (default: False)\n  --speed SPEED         A multiple of the standard 1x animation speed (ex: 2 = twice as fast, 0.5 = half as fast) (default: 1)\n```\n\n## Command Examples\nDefault - draw 8 commits starting from `HEAD`, from oldest to newest:\n\n```console\n$ cd path/to/project/root\n$ git-story\n```\n\nCustomize the start commit and number of commits, and reverse their display order:\n\n```console\n$ git-story --commit-id a1b2c3 --commits=6 --reverse\n```\n\nInvert the branch orientation, if multiple branches exist in the commit range:\n\n```console\n$ git-story --invert-branches\n```\n\nAdd an intro with custom title and logo:\n\n```console\n$ git-story --commit-id dev --commits=10 --show-intro --title \"My Git Repo\" --logo path/to/logo.png\n```\n\nAdd an outro with custom text and logo:\n\n```console\n$ git-story --show-outro --outro-top-text \"My Git Repo\" --outro-bottom-text \"Thanks for watching!\" --logo path/to/logo.png\n```\n\nCustomize the output video directory location:\n\n```console\n$ git-story --media-dir=path/to/output\n```\n\nUse light mode for white background and black text, instead of the default black background with white text:\n\n```console\n$ git-story --light-mode\n```\n\nGenerate output video in low quality to speed up rendering time (useful for repeated testing):\n\n```console\n$ git-story --low-quality\n```\n\n## Installation\nSee **QuickStart** section for details on installing manim and GitPython dependencies. Then run:\n\n```console\n$ pip3 install git-story\n```\n\n## Learn More\nLearn more about this tool on the [git-story project page](https://initialcommit.com/tools/git-story).\n\n## Authors\n**Jacob Stopak** - on behalf of [Initial Commit](https://initialcommit.com)\n"
  },
  {
    "path": "git_story/__init__.py",
    "content": ""
  },
  {
    "path": "git_story/__main__.py",
    "content": "from git_story import git_story as gs\nimport os\nimport argparse\nimport pathlib\nfrom manim import config, WHITE\nfrom manim.utils.file_ops import open_file as open_media_file\n\ndef main():\n    parser = argparse.ArgumentParser(\"git-story\", formatter_class=argparse.ArgumentDefaultsHelpFormatter)\n    parser.add_argument(\"--commits\", help=\"The number of commits to display in the Git animation\", type=int, default=8)\n    parser.add_argument(\"--commit-id\", help=\"The ref (branch/tag), or first 6 characters of the commit to animate backwards from\", type=str, default=\"HEAD\")\n    parser.add_argument(\"--hide-merged-chains\", help=\"Hide commits from merged branches, i.e. only display mainline commits\", action=\"store_true\")\n    parser.add_argument(\"--reverse\", help=\"Display commits in reverse order in the Git animation\", action=\"store_true\")\n    parser.add_argument(\"--title\", help=\"Custom title to display at the beginning of the animation\", type=str, default=\"Git Story, by initialcommit.com\")\n    parser.add_argument(\"--logo\", help=\"The path to a custom logo to use in the animation intro/outro\", type=str, default=os.path.join(str(pathlib.Path(__file__).parent.resolve()), \"logo.png\"))\n    parser.add_argument(\"--outro-top-text\", help=\"Custom text to display above the logo during the outro\", type=str, default=\"Thanks for using Initial Commit!\")\n    parser.add_argument(\"--outro-bottom-text\", help=\"Custom text to display below the logo during the outro\", type=str, default=\"Learn more at initialcommit.com\")\n    parser.add_argument(\"--show-intro\", help=\"Add an intro sequence with custom logo and title\", action=\"store_true\")\n    parser.add_argument(\"--show-outro\", help=\"Add an outro sequence with custom logo and text\", action=\"store_true\")\n    parser.add_argument(\"--max-branches-per-commit\", help=\"Maximum number of branch labels to display for each commit\", type=int, default=2)\n    parser.add_argument(\"--max-tags-per-commit\", help=\"Maximum number of tags to display for each commit\", type=int, default=1)\n    parser.add_argument(\"--media-dir\", help=\"The path to output the animation data and video file\", type=str, default=\".\")\n    parser.add_argument(\"--low-quality\", help=\"Render output video in low quality, useful for faster testing\", action=\"store_true\")\n    parser.add_argument(\"--light-mode\", help=\"Enable light-mode with white background\", action=\"store_true\")\n    parser.add_argument(\"--invert-branches\", help=\"Invert positioning of branches where applicable\", action=\"store_true\")\n    parser.add_argument(\"--speed\", help=\"A multiple of the standard 1x animation speed (ex: 2 = twice as fast, 0.5 = half as fast)\", type=float, default=1)\n\n    args = parser.parse_args()\n\n    config.media_dir = os.path.join(args.media_dir, \"git-story_media\")\n\n    if ( args.low_quality ):\n        config.quality = \"low_quality\"\n\n    if ( args.light_mode ):\n        config.background_color = WHITE\n\n    scene = gs.GitStory(args)\n    scene.render()\n\n    try:\n        open_media_file(scene.renderer.file_writer.movie_file_path)\n    except FileNotFoundError:\n        print(\"Error automatically opening video player, please manually open the video file to view animation.\")\n\nif __name__ == '__main__':\n    main()\n"
  },
  {
    "path": "git_story/git_story.py",
    "content": "from manim import *\nimport git, sys, numpy\n\nclass GitStory(MovingCameraScene):\n    def __init__(self, args):\n        super().__init__()\n        self.args = args\n        self.drawnCommits = {}\n        self.commits = []\n        self.children = {}\n        self.childChainLength = 0\n        self.zoomOuts = 0\n\n        if ( self.args.light_mode ):\n            self.fontColor = BLACK\n        else:\n            self.fontColor = WHITE\n\n    def measureChildChain(self, commit):\n        try:\n            if ( len(self.children[commit.hexsha]) > 0 ):\n                for child in self.children[commit.hexsha]:\n                    self.childChainLength += 1\n                    return self.measureChildChain(child)\n            else:\n                return self.childChainLength\n        except KeyError:\n            return self.childChainLength\n\n    def construct(self):\n        try:\n            self.repo = git.Repo(search_parent_directories=True)\n        except git.exc.InvalidGitRepositoryError:\n            print(\"git-story error: No Git repository found at current path.\")\n            sys.exit(1)\n        \n        try:\n            self.commits = list(self.repo.iter_commits(self.args.commit_id))[:self.args.commits]\n        except git.exc.GitCommandError:\n            print(\"git-story error: No commits in current Git repository.\")\n            sys.exit(1)\n\n        if ( len(self.commits) < self.args.commits ):\n            self.args.commits = len(self.commits)\n\n        if ( not self.args.reverse ):\n            self.commits.reverse()\n            for commit in self.commits:\n                if ( len(commit.parents) > 0 ):\n                    for parent in commit.parents:\n                        self.children.setdefault(parent.hexsha, []).append(commit)\n            z = 1\n            while ( self.measureChildChain(self.commits[0]) < self.args.commits-1 ):\n                self.commits = list(self.repo.iter_commits(self.args.commit_id))[:self.args.commits + z]\n                self.commits.reverse()\n                self.children = {}\n                for commit in self.commits:\n                    if ( len(commit.parents) > 0 ):\n                        for parent in commit.parents:\n                            self.children.setdefault(parent.hexsha, []).append(commit)\n                z += 1\n\n            if ( self.args.invert_branches ):\n                for d in self.children:\n                    if ( len(self.children[d]) > 1 ):\n                        self.children[d].reverse()\n\n        commit = self.commits[0]\n\n        logo = ImageMobject(self.args.logo)\n        logo.width = 3\n\n        if ( self.args.show_intro ):\n            self.add(logo)\n\n            initialCommitText = Text(self.args.title, font=\"Monospace\", font_size=36, color=self.fontColor).to_edge(UP, buff=1)\n            self.add(initialCommitText)\n            self.wait(2)\n            self.play(FadeOut(initialCommitText))\n            self.play(logo.animate.scale(0.25).to_edge(UP, buff=0).to_edge(RIGHT, buff=0))\n    \n            self.camera.frame.save_state()\n            self.play(FadeOut(logo))\n\n        else:\n            logo.scale(0.25).to_edge(UP, buff=0).to_edge(RIGHT, buff=0)\n            self.camera.frame.save_state()\n\n        i = 0\n        prevCircle = None\n        toFadeOut = Group()\n        self.parseCommits(commit, i, prevCircle, toFadeOut)\n\n        self.play(self.camera.frame.animate.move_to(toFadeOut.get_center()), run_time=1/self.args.speed)\n        self.play(self.camera.frame.animate.scale_to_fit_width(toFadeOut.get_width()*1.1), run_time=1/self.args.speed)\n\n        if ( toFadeOut.get_height() >= self.camera.frame.get_height() ):\n            self.play(self.camera.frame.animate.scale_to_fit_height(toFadeOut.get_height()*1.25), run_time=1/self.args.speed)\n\n        self.wait(3)\n\n        self.play(FadeOut(toFadeOut), run_time=1/self.args.speed)\n\n        if ( self.args.show_outro ):\n\n            self.play(Restore(self.camera.frame))\n\n            self.play(logo.animate.scale(4).set_x(0).set_y(0))\n\n            outroTopText = Text(self.args.outro_top_text, font=\"Monospace\", font_size=36, color=self.fontColor).to_edge(UP, buff=1)\n            self.play(AddTextLetterByLetter(outroTopText))\n\n            outroBottomText = Text(self.args.outro_bottom_text, font=\"Monospace\", font_size=36, color=self.fontColor).to_edge(DOWN, buff=1)\n            self.play(AddTextLetterByLetter(outroBottomText))\n\n            self.wait(3)\n\n    def parseCommits(self, commit, i, prevCircle, toFadeOut):\n        if ( i < self.args.commits and commit in self.commits ):\n\n            if ( len(commit.parents) <= 1 ):\n                commitFill = RED\n            else:\n                commitFill = GRAY\n\n            circle = Circle(stroke_color=commitFill, fill_color=commitFill, fill_opacity=0.25)\n            circle.height = 1\n\n            if prevCircle:\n                circle.next_to(prevCircle, RIGHT, buff=1.5)\n\n            offset = 0\n            while ( any((circle.get_center() == c).all() for c in self.getCenters()) ):\n                circle.next_to(circle, DOWN, buff=3.5)\n                offset += 1\n                if ( self.zoomOuts == 0 ):\n                    self.play(self.camera.frame.animate.scale(1.5), run_time=1/self.args.speed)\n                self.zoomOuts += 1\n\n            isNewCommit = commit.hexsha not in self.drawnCommits\n\n            if ( not self.args.reverse ):\n                if ( isNewCommit ):\n                    start = circle.get_center()\n                    end = prevCircle.get_center() if prevCircle else LEFT\n                else:\n                    start = self.drawnCommits[commit.hexsha].get_center()\n                    end = prevCircle.get_center()\n\n            else:\n                if ( isNewCommit ):\n                    start = prevCircle.get_center() if prevCircle else LEFT\n                    end = circle.get_center()\n                else:\n                    start = prevCircle.get_center()\n                    end = self.drawnCommits[commit.hexsha].get_center()\n\n            arrow = Arrow(start, end, color=self.fontColor)\n            length = numpy.linalg.norm(start-end) - ( 1.5 if start[1] == end[1] else 3  )\n            arrow.set_length(length)\n\n            angle = arrow.get_angle()\n            lineRect = Rectangle(height=0.1, width=length, color=\"#123456\").move_to(arrow.get_center()).rotate(angle)\n\n            for commitCircle in self.drawnCommits.values():\n                inter = Intersection(lineRect, commitCircle)\n                if ( inter.has_points() ):\n                    arrow = CurvedArrow(start, end)\n                    if ( start[1] == end[1]  ):\n                        arrow.shift(UP*1.25)\n                    if ( start[0] < end[0] and start[1] == end[1] ):\n                        arrow.flip(RIGHT).shift(UP)\n                \n            commitId = Text(commit.hexsha[0:6], font=\"Monospace\", font_size=20, color=self.fontColor).next_to(circle, UP)\n\n            commitMessage = commit.message[:40].replace(\"\\n\", \" \")\n            message = Text('\\n'.join(commitMessage[j:j+20] for j in range(0, len(commitMessage), 20))[:100], font=\"Monospace\", font_size=14, color=self.fontColor).next_to(circle, DOWN)\n\n            if ( isNewCommit ):\n\n                self.play(self.camera.frame.animate.move_to(circle.get_center()), Create(circle), AddTextLetterByLetter(commitId), AddTextLetterByLetter(message), run_time=1/self.args.speed)\n                self.drawnCommits[commit.hexsha] = circle\n\n                prevRef = commitId\n                if ( commit.hexsha == self.repo.head.commit.hexsha ):\n                    head = Rectangle(color=BLUE, fill_color=BLUE, fill_opacity=0.25)\n                    head.width = 1\n                    head.height = 0.4\n                    head.next_to(commitId, UP)\n                    headText = Text(\"HEAD\", font=\"Monospace\", font_size=20, color=self.fontColor).move_to(head.get_center())\n                    self.play(Create(head), Create(headText), run_time=1/self.args.speed)\n                    toFadeOut.add(head, headText)\n                    prevRef = head\n\n                x = 0\n                for branch in self.repo.heads:\n                    if ( commit.hexsha == branch.commit.hexsha ):\n                        branchText = Text(branch.name, font=\"Monospace\", font_size=20, color=self.fontColor)\n                        branchRec = Rectangle(color=GREEN, fill_color=GREEN, fill_opacity=0.25, height=0.4, width=branchText.width+0.25)\n\n                        branchRec.next_to(prevRef, UP)\n                        branchText.move_to(branchRec.get_center())\n\n                        prevRef = branchRec \n\n                        self.play(Create(branchRec), Create(branchText), run_time=1/self.args.speed)\n                        toFadeOut.add(branchRec, branchText)\n\n                        x += 1\n                        if ( x >= self.args.max_branches_per_commit ):\n                            break\n\n                x = 0\n                for tag in self.repo.tags:\n                    if ( commit.hexsha == tag.commit.hexsha ):\n                        tagText = Text(tag.name, font=\"Monospace\", font_size=20, color=self.fontColor)\n                        tagRec = Rectangle(color=YELLOW, fill_color=YELLOW, fill_opacity=0.25, height=0.4, width=tagText.width+0.25)\n\n                        tagRec.next_to(prevRef, UP)\n                        tagText.move_to(tagRec.get_center())\n\n                        prevRef = tagRec\n\n                        self.play(Create(tagRec), Create(tagText), run_time=1/self.args.speed)\n                        toFadeOut.add(tagRec, tagText)\n\n                        x += 1\n                        if ( x >= self.args.max_tags_per_commit ):\n                            break\n\n            else:\n                self.play(self.camera.frame.animate.move_to(self.drawnCommits[commit.hexsha].get_center()), run_time=1/self.args.speed)\n                self.play(Create(arrow), run_time=1/self.args.speed)\n                toFadeOut.add(arrow)\n                return\n\n\n            if ( prevCircle ):\n                self.play(Create(arrow), run_time=1/self.args.speed)\n                toFadeOut.add(arrow)\n\n            prevCircle = circle\n\n            toFadeOut.add(circle, commitId, message)\n\n            if ( self.args.reverse ):\n                commitParents = list(commit.parents)\n                if ( len(commitParents) > 0 ):\n                    if ( self.args.invert_branches ):\n                        commitParents.reverse()\n\n                    if ( self.args.hide_merged_chains ):\n                        self.parseCommits(commitParents[0], i+1,  prevCircle, toFadeOut)\n                    else:\n                        for p in range(len(commitParents)):\n                            self.parseCommits(commitParents[p], i+1, prevCircle, toFadeOut)\n\n            else:\n                try:\n                    if ( len(self.children[commit.hexsha]) > 0 ):\n                        if ( self.args.hide_merged_chains ):\n                            self.parseCommits(self.children[commit.hexsha][0], i+1, prevCircle, toFadeOut)\n                        else:\n                            for p in range(len(self.children[commit.hexsha])):\n                                self.parseCommits(self.children[commit.hexsha][p], i+1, prevCircle, toFadeOut)\n                except KeyError:\n                    pass\n\n        else:\n            return\n\n    def getCenters(self):\n        centers = []\n        for commit in self.drawnCommits.values():\n            centers.append(commit.get_center())\n        return centers\n"
  },
  {
    "path": "license",
    "content": "Copyright 2022 Jacob Stopak, initialcommit.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "setup.py",
    "content": "import setuptools\n\nwith open(\"README.md\", \"r\") as fh:\n    long_description = fh.read()\n\nsetuptools.setup(\n    name=\"git-story\",\n    version=\"0.1.4\",\n    author=\"Jacob Stopak\",\n    author_email=\"jacob@initialcommit.io\",\n    description=\"Tell the story of your Git project by creating video animations (.mp4) of your commit history directly from your Git repo.\",\n    long_description=long_description,\n    long_description_content_type=\"text/markdown\",\n    url=\"https://initialcommit.com/tools/git-story\",\n    packages=setuptools.find_packages(),\n    classifiers=[\n        \"Programming Language :: Python :: 3\",\n        \"License :: OSI Approved :: MIT License\",\n        \"Operating System :: OS Independent\",\n    ],\n    python_requires='>=3.7',\n    install_requires=[\n        'gitpython',\n        'manim'\n    ],\n    keywords='git story git-story manim animation gitanimation',\n    project_urls={\n        'Homepage': 'https://initialcommit.com/tools/git-story',\n    },\n    entry_points={\n        'console_scripts': [\n            'git-story=git_story.__main__:main',\n        ],\n    },\n    include_package_data=True\n)\n"
  },
  {
    "path": "test.py",
    "content": "import unittest, git, argparse\nfrom manim import *\n\nfrom git_story.git_story import GitStory\n\n\nclass TestGitStory(unittest.TestCase):\n\n    def test_git_story(self):\n        \"\"\"Test git story.\"\"\"\n\n        gs = GitStory(argparse.Namespace())\n\n        self.assertEqual(1, 1)\n\n\nif __name__ == '__main__':\n    unittest.main()\n"
  }
]