Skip to content

Commit d2e6ae6

Browse files
authored
docs: update manpage (#81)
1 parent 1c53f96 commit d2e6ae6

File tree

1 file changed

+71
-59
lines changed

1 file changed

+71
-59
lines changed

docs/git-draft.adoc

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ IMPORTANT: `git-draft` is WIP.
1919

2020
[verse]
2121
git draft [options] [--new] [--accept... | --no-accept] [--bot BOT]
22-
[--edit] [TEMPLATE [VARIABLE...]]
22+
[--edit] [TEMPLATE [VARIABLE...] | -]
2323
git draft [options] --quit
2424
git draft [options] --templates [--json | [--edit] TEMPLATE]
2525

@@ -28,6 +28,15 @@ git draft [options] --templates [--json | [--edit] TEMPLATE]
2828

2929
`git-draft` is a git-centric way to edit code with AI.
3030

31+
Its workhorse command is `git draft --new` (and its shorthand, `git draft`) which suggests code changes using LLMs.
32+
Prompts can be specified inline or via customizable templates.
33+
Prompt templates can get augmented with information about the files in the repository, and give the LLM access to tools for reading and writing files.
34+
Once the response has been received and changes applied, a commit is created in a dedicated draft branch.
35+
The `--new` step can be repeated as many times as needed.
36+
37+
Once satisfied with the changes, run `git draft --quit` to return to the original branch.
38+
This keeps the working directory's current state.
39+
3140

3241
== Options
3342

@@ -39,7 +48,8 @@ This option can be repeated up to 3 times, with the following behavior at each l
3948
+
4049
* `-a`: Merge changes conservatively, flagging any conflicts for manual user resolution.
4150
* `-aa`: Merge changes aggressively, resolving all conflicts in favor of the generated change.
42-
* `-aaa`: Merge changes aggressively (same as `-aa`) then run `--quit` automatically.
51+
* `-aaa`: Merge changes aggressively (same as `-aa`) then run `--quit`.
52+
4353
+
4454
By default, changes are not merged - keeping the working directory untouched.
4555
A different default can be set in the configuration file.
@@ -53,29 +63,33 @@ Defaults to the first bot defined in the configuration.
5363
-e::
5464
--edit::
5565
Enable interactive editing of draft prompts and templates.
56-
See `--new` and `--templates` for details.
66+
When used with `--new`, it opens an editor with the rendered prompt.
67+
The updated prompt will be used by the bot after the editor exits.
68+
When used with `--templates`, it opens an editor with the selected template.
69+
The template will be created automatically if it did not already exist.
5770

5871
-h::
5972
--help::
6073
Show help message and exit.
6174

6275
-j::
6376
--json::
64-
Use JSON output.
77+
Use JSON output.
6578

6679
--log-path::
67-
Show log path and exit.
80+
Show log path and exit.
6881

6982
-N::
7083
--new::
71-
Create an AI-generated draft.
72-
If the `--edit` option is set, an interactive editor will be opened with the rendered prompt to allow modification before it is forwarded to the bot.
84+
Generate a draft commit for a given prompt.
85+
`-` can be specified instead of a template name to read the prompt from stdin.
86+
Otherwise if no template is specified and stdin is a TTY, `$EDITOR` will be opened to enter the prompt.
7387

7488
-Q::
7589
--quit::
7690
Go back to the draft's origin branch, keeping the working directory's current state.
7791
This will delete the draft branch and its upstream.
78-
Generated commits remain available via `ref/drafts`.
92+
Generated commits and the draft branch's final state remain available via `ref/drafts`.
7993

8094
--root::
8195
Repository search root.
@@ -84,77 +98,75 @@ Defaults to the current working directory.
8498
-T::
8599
--templates::
86100
With no argument, lists available templates.
87-
With an template name argument, displays the corresponding template's contents or, if the `--edit` option is set, opens an interactive editor.
101+
With an template name argument, displays the corresponding template's contents or, if the `--edit` option is set, opens an interactive editor with its contents.
88102

89103
--version::
90104
Show version and exit.
91105

92106

93107
== Examples
94108

95-
The workhorse command is `git draft --new` which leverages AI to edit code.
96-
A prompt can be specified as standard input, for example `echo "Add a test for compute_offset in chart.py" | git draft --generate`.
97-
If no prompt is specified and stdin is a TTY, `$EDITOR` will be opened to enter the prompt.
98-
99-
By default, the prompt gets augmented with information about the files in the repository, and give the AI access to tools for reading and writing files.
100-
Once the response has been received and changes applied, a commit is created in a separate branch.
109+
=== Commit graphs
101110

102-
The `--generate` step can be repeated as many times as needed.
103-
Once you are satisfied with the changes, run `git draft --finalize` to apply them.
104-
This will check out the branch used when creating the draft, adding the final state of the draft to the worktree.
105-
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.
111+
This section shows representative commit histories in draft branches for various scenarios.
106112

113+
When the working directory is clean, a single commit is created and set as the draft branch's upstream (suffixed with `+`).
107114

108-
o Foo (main)
109-
o Sync (drafts/123/pub)
115+
[source]
116+
----
117+
o <some commit> (main, draft/123)
118+
o draft! prompt: <prompt> (draft/123+, refs/drafts/123/1)
119+
----
110120

111-
# After generate without accept
112-
o Foo (main)
113-
o Sync (drafts/123)
114-
o draft! <prompt> (drafts/123+, refs/drafts/123/1)
121+
If the working directory is dirty, a sync commit is added to identify the LLM-generated changes.
115122

116-
# After generate with accept
117-
o Foo (main)
118-
o Sync
119-
|\
120-
| o draft! prompt: <prompt> (refs/drafts/123/1)
121-
o | Sync
122-
|/
123-
o Merge (drafts/123/pub)
123+
[source]
124+
----
125+
o <some commit> (main, draft/123)
126+
o draft! sync(prompt)
127+
o draft! prompt: <prompt> (draft/123+, refs/drafts/123/1)
128+
----
124129

130+
If merging is enabled, it have both the LLM-generated changes and manual edits as parents.
125131

126-
o Foo (main)
127-
o draft! sync
128-
|\
129-
| o draft! prompt: <prompt> (drafts/123+, refs/drafts/123/1)
130-
o Something
131-
o Also something (drafts/123)
132-
133-
134-
o Foo (main)
135-
o draft! sync
132+
[source]
133+
----
134+
o <some commit> (main)
136135
|\
136+
| o draft! sync(prompt)
137+
o | draft! sync(merge)
137138
| o draft! prompt: <prompt> (refs/drafts/123/1)
138-
o Something
139-
o Also something (drafts/123/pub)
140-
o draft! prompt: <prompt> (drafts/123+, refs/drafts/123/2)
139+
|/
140+
o Merge (draft/123, draft/123/+)
141+
----
141142

143+
Otherwise, the user is free to incorporate the changes as needed.
144+
Note that the steps above can be repeated arbitrarily many times within a given draft branch, both with and without automatic merging.
142145

143-
o Foo (main)
144-
o draft! sync (drafts/123/pub)
146+
[source]
147+
----
148+
o <some commit> (main)
145149
|\
146-
| o draft! prompt: <prompt> (refs/drafts/123/1)
147-
\
148-
o draft! prompt: <prompt> (drafts/123+, refs/drafts/123/2)
149-
150-
o Foo (main)
151-
o draft! sync (drafts/123/pub)
150+
| o draft! prompt: <prompt1> (refs/drafts/123/1)
151+
o draft! sync(prompt)
152+
o draft! prompt: <prompt2> (refs/drafts/123/2)
153+
o <a manual commit> (draft/123)
154+
o draft! prompt: <prompt3> (draft/123+, refs/drafts/123/3)
155+
----
156+
157+
Sync commits will be reused if no new changes were added.
158+
This can be useful when iterating on a prompt, and discarding results from prior iterations.
159+
160+
[source]
161+
----
162+
o <some commit> (main)
163+
o draft! sync(prompt)
152164
|\
153-
| o draft! prompt: <prompt> (refs/drafts/123/1)
154-
|/
155-
o draft! sync
156-
\
157-
o draft! prompt: <prompt> (drafts/123+, refs/drafts/123/2)
165+
| \
166+
|\ o draft! prompt: <prompt1> (refs/drafts/123/1)
167+
| o draft! prompt: <prompt2> (refs/drafts/123/2)
168+
o draft! prompt: <prompt3> (refs/drafts/123/3)
169+
----
158170

159171

160172
== See also

0 commit comments

Comments
 (0)