diff --git a/docs/git-draft.adoc b/docs/git-draft.adoc index c970e7e..21452d9 100644 --- a/docs/git-draft.adoc +++ b/docs/git-draft.adoc @@ -1,6 +1,6 @@ ifndef::manversion[:manversion: 0.0.0] -= git-traft(1) += git-draft(1) Matthieu Monsch v{manversion} :doctype: manpage @@ -10,7 +10,7 @@ v{manversion} == Name -git-draft - a git-friendly way to edit code +git-draft - git-friendly code assistant == Synopsis @@ -21,12 +21,30 @@ git-draft - a git-friendly way to edit code *git-draft* _-A_ -*git-draft* _-D_ +*git-draft* _-D_ _[-b BRANCH]_ == Description -TODO +_git-draft_ is a git-centric way to edit code using AI. + +=== How it works + +When you create a new draft with `git draft -C $name`, a new branch called `$branch/drafts/$name-$hash` is created (`$hash` is a random suffix used to guarantee uniqueness of branch names) and checked out. +Additionally, any uncommitted changes are automatically committed (`draft! sync`). + +Once the draft is created, we can use AI to edit our code using `git draft -P`. +It expects the prompt as standard input, for example `echo "Add a test for compute_offset in chart.py" | git draft -P`. +The prompt will automatically get augmented with information about the files in the repository, and give the AI access to tools for reading and writing files. +Once the response has been received and changes, applied a commit is created (`draft! prompt: a short summary of the change`). + +The prompt step can be repeated as many times as needed. Once you are satisfied with the changes, run `git draft -A` to apply them. +This will check out the branch used when creating the draft, adding the final state of the draft to the worktree. +Note that you can come back to an existing draft anytime (by checking its branch out), but you will not be able to apply it if its origin branch has moved since the draft was created. + +Finally, calling `git draft -D` will delete all drafts associated with a branch. +By default the currently active branch is used, you can use the `-b` option to select another. +You can also delete the drafts manually by deleting their branches using `git branch`. == See also diff --git a/src/git_draft/__main__.py b/src/git_draft/__main__.py index b307ab3..798dbdc 100644 --- a/src/git_draft/__main__.py +++ b/src/git_draft/__main__.py @@ -56,16 +56,23 @@ def __call__(self, _option, _opt, value, parser, name) -> None: ) apply_command = Command.register( - "apply", help="apply the current draft to the original state" + "apply", help="apply the current draft to the original branch" ) apply_command.option_group().add_option( - "-k", - "--keep", - help="do not delete the draft after applying", + "-d", + help="delete the draft after applying", action="store_true", ) -Command.register("delete", help="delete the current draft") +delete_command = Command.register( + "delete", help="delete all drafts associated with a branch" +) +delete_command.option_group().add_option( + "-b", + help="draft source branch [default: active branch]", + type="string", + metavar="BRANCH", +) def main() -> None: