initialcommit-com / git-sim

Visually simulate Git operations in your own repos with a single terminal command.
GNU General Public License v2.0
4.17k stars 107 forks source link

Error on simple actions #75

Closed bendem closed 1 year ago

bendem commented 1 year ago

Here is a simple reproducer of an error for a simple rebase (one root commit, two branches with one commit in each, rebase on on the other).

> git init
Initialized empty Git repository in /home/demarteaub/projects/version-sample/.git/

> git commit --allow-empty -m "initial commit"
[main (root-commit) d41bc20] initial commit

> git switch -c dev

> git commit --allow-empty -m "some development"
[dev 938ab0b] some development

> git switch main
Switched to branch 'main'

> git commit --allow-empty -m "bugfix"
[main bd7e0e7] bugfix

> git switch dev
Switched to branch 'dev'

> git_sim_media_dir=../version-sample.git-sim git-sim rebase main
Simulating: git rebase main
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/demarteaub/.local/pipx/venvs/git-sim/lib64/python3.9/site-packages/git_sim/rebase.py:191   │
│ in rebase                                                                                        │
│                                                                                                  │
│   188 │   )                                                                                      │
│   189 ):                                                                                         │
│   190 │   scene = Rebase(branch=branch)                                                          │
│ ❱ 191 │   handle_animations(scene=scene)                                                         │
│   192                                                                                            │
│                                                                                                  │
│ ╭───────────────────────── locals ──────────────────────────╮                                    │
│ │ branch = 'main'                                           │                                    │
│ │  scene = <git_sim.rebase.Rebase object at 0x7f0ff5ab3520> │                                    │
│ ╰───────────────────────────────────────────────────────────╯                                    │
│                                                                                                  │
│ /home/demarteaub/.local/pipx/venvs/git-sim/lib64/python3.9/site-packages/git_sim/animations.py:1 │
│ 7 in handle_animations                                                                           │
│                                                                                                  │
│   14                                                                                             │
│   15                                                                                             │
│   16 def handle_animations(scene: Scene) -> None:                                                │
│ ❱ 17 │   scene.render()                                                                          │
│   18 │                                                                                           │
│   19 │   if settings.video_format == "webm":                                                     │
│   20 │   │   webm_file_path = str(scene.renderer.file_writer.movie_file_path)[:-3] + "webm"      │
│                                                                                                  │
│ ╭───────────────────────── locals ─────────────────────────╮                                     │
│ │ scene = <git_sim.rebase.Rebase object at 0x7f0ff5ab3520> │                                     │
│ ╰──────────────────────────────────────────────────────────╯                                     │
│                                                                                                  │
│ /home/demarteaub/.local/pipx/venvs/git-sim/lib64/python3.9/site-packages/manim/scene/scene.py:22 │
│ 3 in render                                                                                      │
│                                                                                                  │
│    220 │   │   """                                                                               │
│    221 │   │   self.setup()                                                                      │
│    222 │   │   try:                                                                              │
│ ❱  223 │   │   │   self.construct()                                                              │
│    224 │   │   except EndSceneEarlyException:                                                    │
│    225 │   │   │   pass                                                                          │
│    226 │   │   except RerunSceneException as e:                                                  │
│                                                                                                  │
│ ╭────────────────────────── locals ──────────────────────────╮                                   │
│ │ preview = False                                            │                                   │
│ │    self = <git_sim.rebase.Rebase object at 0x7f0ff5ab3520> │                                   │
│ ╰────────────────────────────────────────────────────────────╯                                   │
│                                                                                                  │
│ /home/demarteaub/.local/pipx/venvs/git-sim/lib64/python3.9/site-packages/git_sim/rebase.py:72 in │
│ construct                                                                                        │
│                                                                                                  │
│    69 │   │   head_commit = self.get_commit()                                                    │
│    70 │   │                                                                                      │
│    71 │   │   reached_base = False                                                               │
│ ❱  72 │   │   for commit in self.get_default_commits():                                          │
│    73 │   │   │   if commit != "dark" and self.branch in self.repo.git.branch(                   │
│    74 │   │   │   │   "--contains", commit                                                       │
│    75 │   │   │   ):                                                                             │
│                                                                                                  │
│ ╭──────────────────────────────── locals ─────────────────────────────────╮                      │
│ │ branch_commit = <git.Commit "bd7e0e7e24bc655b1e25f73645a5b24f5823058b"> │                      │
│ │   head_commit = <git.Commit "938ab0b25e2e6f0ed9b3b6f40be43ad2b6409f64"> │                      │
│ │  reached_base = False                                                   │                      │
│ │          self = <git_sim.rebase.Rebase object at 0x7f0ff5ab3520>        │                      │
│ ╰─────────────────────────────────────────────────────────────────────────╯                      │
│                                                                                                  │
│ /home/demarteaub/.local/pipx/venvs/git-sim/lib64/python3.9/site-packages/git_sim/git_sim_base_co │
│ mmand.py:68 in get_default_commits                                                               │
│                                                                                                  │
│     65 │   def get_default_commits(self):                                                        │
│     66 │   │   defaultCommits = [self.get_commit()]                                              │
│     67 │   │   for x in range(self.n_default - 1):                                               │
│ ❱   68 │   │   │   defaultCommits.append(defaultCommits[-1].parents[0])                          │
│     69 │   │   return defaultCommits                                                             │
│     70 │                                                                                         │
│     71 │   def parse_commits(                                                                    │
│                                                                                                  │
│ ╭─────────────────────────────────── locals ────────────────────────────────────╮                │
│ │ defaultCommits = [                                                            │                │
│ │                  │   <git.Commit "938ab0b25e2e6f0ed9b3b6f40be43ad2b6409f64">, │                │
│ │                  │   <git.Commit "d41bc20b7c357301d89b3c3c515b1122850864d2">  │                │
│ │                  ]                                                            │                │
│ │           self = <git_sim.rebase.Rebase object at 0x7f0ff5ab3520>             │                │
│ │              x = 1                                                            │                │
│ ╰───────────────────────────────────────────────────────────────────────────────╯                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
IndexError: tuple index out of range
bendem commented 1 year ago

bisect in the hope it helps:

82f51f0cb1cc03b415690439ad6b563749788f9c is the first bad commit
commit 82f51f0cb1cc03b415690439ad6b563749788f9c
Author: Jacob Stopak <jacob@initialcommit.io>
Date:   Thu Mar 2 06:21:32 2023 -0800

    Consolidate get_commits and parse_commits methods

    Signed-off-by: Jacob Stopak <jacob@initialcommit.io>

 git_sim/add.py                  |  3 +-
 git_sim/branch.py               |  3 +-
 git_sim/cherrypick.py           | 17 ++++++------
 git_sim/commit.py               | 14 +++++-----
 git_sim/git_sim_base_command.py | 61 ++++++++++++-----------------------------
 git_sim/log.py                  | 14 ++++------
 git_sim/merge.py                | 38 +++++++++++--------------
 git_sim/rebase.py               | 21 +++++++-------
 git_sim/reset.py                |  9 +++---
 git_sim/restore.py              |  3 +-
 git_sim/revert.py               | 16 +++++------
 git_sim/stash.py                |  3 +-
 git_sim/status.py               |  3 +-
 git_sim/tag.py                  |  3 +-
 14 files changed, 82 insertions(+), 126 deletions(-)
initialcommit-io commented 1 year ago

@bendem Thanks I'll test this out and get back to you.

initialcommit-io commented 1 year ago

@bendem This also appears to be related to repos with less than 5 commits on the branch being rebased. I will try and fix this and the other related issue at the same time.

initialcommit-io commented 1 year ago

@bendem For now, the rebase for diverged branches should work for you as long as both branches have more than 5 commits.

initialcommit-io commented 1 year ago

Just released a fix for this! Please use git-sim version 0.2.9 to take advantage of the fixes. You can upgrade git-sim with: pip install git-sim --upgrade.

I'll close this for now since it's implemented, but please let me know if you have any questions or run into any issues!

bendem commented 1 year ago

Awesome! This is great work.

initialcommit-io commented 1 year ago

@bendem There are a bunch of other new features in v0.2.9 if you want to check them out and let me know if you run into any issues or if anything is unclear 😄