From d9ad7022706db3eaa3717d0d4d144307986dc890 Mon Sep 17 00:00:00 2001 From: Matthieu Monsch Date: Tue, 25 Feb 2025 21:15:08 -0800 Subject: [PATCH 1/3] docs: add minimal flow description --- docs/git-draft.adoc | 23 +++++++++++++++++++---- src/git_draft/__main__.py | 17 ++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/docs/git-draft.adoc b/docs/git-draft.adoc index c970e7e..5739da3 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,27 @@ git-draft - a git-friendly way to edit code *git-draft* _-A_ -*git-draft* _-D_ +*git-draft* _-D_ _[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`).draft + +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. + + == 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: From 5f21262e7eb7f299221905f8c4ad73f0def7a738 Mon Sep 17 00:00:00 2001 From: Matthieu Monsch Date: Tue, 25 Feb 2025 21:18:14 -0800 Subject: [PATCH 2/3] fixup! docs: add minimal flow description --- docs/git-draft.adoc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/git-draft.adoc b/docs/git-draft.adoc index 5739da3..d099a0f 100644 --- a/docs/git-draft.adoc +++ b/docs/git-draft.adoc @@ -21,7 +21,7 @@ git-draft - git-friendly code assistant *git-draft* _-A_ -*git-draft* _-D_ _[BRANCH]_ +*git-draft* _-D_ _[-b BRANCH]_ == Description @@ -31,7 +31,7 @@ _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`).draft +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`. @@ -41,7 +41,8 @@ Once the response has been received and changes, applied a commit is created (`d 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. - +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. == See also From c73a5b9400666e41d7e142bd764e37bc5888221a Mon Sep 17 00:00:00 2001 From: Matthieu Monsch Date: Tue, 25 Feb 2025 21:20:32 -0800 Subject: [PATCH 3/3] fixup! docs: add minimal flow description --- docs/git-draft.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/git-draft.adoc b/docs/git-draft.adoc index d099a0f..21452d9 100644 --- a/docs/git-draft.adoc +++ b/docs/git-draft.adoc @@ -40,9 +40,11 @@ Once the response has been received and changes, applied a commit is created (`d 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