initialcommit-com/git-sim

Feature request - show branches unrelated to the current command being simulated

ryanmcfall opened this issue · 5 comments

It would be nice if there was a way to include branches that won't be changed by the command being simulated to help the user of the tool visualize which commits those branches reference in addition to the ones that will change.

For example, I have might have a main branch along with two feature branches MessagePost and PhotoPost, which share a common parent, and have a single commit that is not yet merged into main.

If I git switch main and then execute git-sim merge MessagePost, the simulation very nicely shows me that the MessagePost and main pointers now point to the same commit, the one added to the MessagePost branch. The PhotoPost tip will still point at a commit whose parent is the original common parent of MessagePost and PhotoPost. It would be instructional to see that PhotoPost doesn't move.

Maybe add an option to git-sim that allows the user to specify additional branches besides HEAD and any branches that are actually involved in the simulated operation.

For context, I am teaching a university class on Git, and I think my students could really benefit from seeing this information. It's available using git log --graph --all, but the visualizations provided by git-sim are much nicer.

@ryanmcfall Yes the main thing I'm working on at the moment is a more robust way for the tool to show multiple branches at once in addition to more complex branching structures. I will take into account your suggestion. More to come on this soon.

Thanks @initialcommit-io. If you would like someone to beta test anything you come up with, I'm happy to do so.

I made a quick stab at trying this myself, working with the git status command. Maybe status or log or both are the appropriate places to show additional branches, and the other commands don't really need them. Supporting git log --all --decorate --graph might make the most sense, since it includes options that are already available as part of the base git commands. But I can certainly see how it might get hard to generate a visualization of a very large repository.

Yes, before I get to this I need to at least update Git log to properly show branch divergences strating from a single branch head, by tracing back the parent/child relationships. For the initial version of Git-Sim I wanted to get something out there to see if anyone would be interested, so it just does something super simple by listing out X commits from the history and connecting them with arrows, but it wouldn't even necessarily properly pick up branch divergences yet. I have an initial working version of this but just hammering out the issues before releasing it. This will be released as a part of git-sim log before the other commands.

Keep in mind this is a different issue than the one you suggested, which is to show multiple branches starting from their diverged heads. My change outlined above will only show divergences in the history of a single branch, to start.

Once that's done we can start applying it to other commands, and after that, I think we can get to your suggestion :D.

I'm also curious about looking into a network-building dependency that might help better represent the DAG and make it easier to work with and draw using Manim.

If you'd like to contribute we can try to brainstorm/research/test some different options.

However, it might be beneficial for you to get a feel for the codebase before we get into that - I might recommend taking a crack at #15 which is a request to add git switch / git checkout as a supported git-sim subcommand.

Hi @ryanmcfall ! Sorry for the delay on this one. I just completed a large refactoring of how git-sim parses commit history by following the parent/child relationships recursively. This allows more accurate graphs to be drawn as well as the implementation of some new flags/options to get the "git log --all --graph" behavior you mentioned.

You'll need to update to git-sim version 0.2.6 to take advantage of these new features:

$ pip install git-sim --upgrade

There are 2 new global flags/options that you can play with:

  1. The --all global flag can be used with any subcommand that doesn't draw a table, and includes all unrelated branch heads in the graph that have no children (i.e. all true branch heads that aren't ancestors of other branches)

  2. The -n <number> global option can be used to specify the max number of commits to trace back from each branch head, and can be used with any subcommand that doesn't draw a table. By default this is set to 5 for all subcommands, but you can use it to show as many commits in the graphs as you'd like!

Give it a test and let me know how it works for you!

PS: One thing I still haven't added is the ability to specify exactly which unrelated branches would want to be seen, in the case there are very many --all could get unruly. So hopefully I'll add that sometime relatively soon...

Closing since this feature was released several weeks ago.