Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions docs/git-draft.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ifndef::manversion[:manversion: 0.0.0]

= git-traft(1)
= git-draft(1)
Matthieu Monsch
v{manversion}
:doctype: manpage
Expand All @@ -10,7 +10,7 @@ v{manversion}

== Name

git-draft - a git-friendly way to edit code
git-draft - git-friendly code assistant


== Synopsis
Expand All @@ -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
Expand Down
17 changes: 12 additions & 5 deletions src/git_draft/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down