Overview
git machete is a mega-useful workflow tool,
partially because is nicely separates the current branch state (the git repo state) from a declared target state (the machete config).
It'd be real useful to be able to overlay workflow helpers or lightweight views onto git machete;
which would be much easier if there was an easily-parsed output format.
Most interactions with machete can be represented as:
- Call
git machete status to get the branch tree and branch status information.
- Inspect the branch tree and (maybe) current repo/remote state to know what to do.
- Invoke some
git or git machete command to do the needful.
Therefor, we can implement most integrations by only adding output git machete status.
Semi-obviously, this should just be a json form of the status output.
In my experience, this best represented as an adjacency based structure akin to the output of the git machete show commands.
In dataclasses:
# single-character status, equivalent to ASCII output
class Status(str, enum.Enum):
IN_SYNC = "o"
MERGED = "m"
OUT_OF_SYNC = "x"
WEIRD_FORK = "?"
@attr.define
class MacheteConfig:
# primary data from status - must have to reconstruct full status
# all tracked branches
tracked: list[str]
# branch to parent mapping
# a branch is only present if it's non-root and has a parent
up: dict[str, str]
# branch status
status: dict[str, Status]
# branch custom annotations
anno: dict[str, str]
# derived data from status - useful views but not strictly needed
current: str | None
roots: list[str] # all roots in the tree
non_root: list[str] # all non-roots in the tree
# show output, keyed by branch
down: dict[str, list[str]]
first: dict[str, str]
last: dict[str, str]
next: dict[str, str]
prev: dict[str, str]
root: dict[str, str]
This can be semi-trivially generated during machete's current status implementation.
The easiest implementation might be to just add a --json flag to git machete status?
Happy to open a PR for comments if you're open to it.
Overview
git macheteis a mega-useful workflow tool,partially because is nicely separates the current branch state (the git repo state) from a declared target state (the machete config).
It'd be real useful to be able to overlay workflow helpers or lightweight views onto
git machete;which would be much easier if there was an easily-parsed output format.
Most interactions with machete can be represented as:
git machete statusto get the branch tree and branch status information.gitorgit machetecommand to do the needful.Therefor, we can implement most integrations by only adding output
git machete status.Semi-obviously, this should just be a json form of the status output.
In my experience, this best represented as an adjacency based structure akin to the output of the
git machete showcommands.In dataclasses:
This can be semi-trivially generated during machete's current
statusimplementation.The easiest implementation might be to just add a
--jsonflag togit machete status?Happy to open a PR for comments if you're open to it.