tg-summary.sh: add --heads-only option
[topgit/pro.git] / README
blob370b6243542749321c950de983bea79e9482ebc1
1 =========================================
2 TopGit -- A different patch queue manager
3 =========================================
6 DESCRIPTION
7 -----------
9 TopGit aims to make handling of large amounts of interdependent topic
10 branches easier. In fact, it is designed especially for the case where
11 you maintain a queue of third-party patches on top of another (perhaps
12 Git-controlled) project and want to easily organize, maintain and submit
13 them -- TopGit achieves that by keeping a separate topic branch for each
14 patch and providing some tools to maintain the branches.
16 See also:
18         :USAGE_:            Command Line details
19         :`NO UNDO`_:        Where's the undo!!!
20         :CONVENTIONS_:      Suggestions for organizing your TopGit branches
21         :GLOSSARY_:         All the TopGit vocabulary in one place
22         :TECHNICAL_:        How it works behind the scenes
25 INSTALLATION
26 ------------
28 See the file ``INSTALL``.
31 GIT REPOSITORY
32 --------------
34 The TopGit git repository can be found at <http://repo.or.cz/topgit/pro>.
37 RATIONALE
38 ---------
40 Why not use something like StGIT or Guilt or ``rebase -i`` for maintaining
41 your patch queue?  The advantage of these tools is their simplicity;
42 they work with patch *series* and defer to the reflog facility for
43 version control of patches (reordering of patches is not
44 version-controlled at all).  But there are several disadvantages -- for
45 one, these tools (especially StGIT) do not actually fit well with plain
46 Git at all: it is basically impossible to take advantage of the index
47 effectively when using StGIT.  But more importantly, these tools
48 horribly fail in the face of a distributed environment.
50 TopGit has been designed around three main tenets:
52         (i) TopGit is as thin a layer on top of Git as possible.  You
53         still maintain your index and commit using Git; TopGit will only
54         automate a few indispensable tasks.
56         (ii) TopGit is anxious about *keeping* your history.  It will
57         never rewrite your history, and all metadata is also tracked
58         by Git, smoothly and non-obnoxiously.  It is good to have a
59         *single* point when the history is cleaned up, and that is at
60         the point of inclusion in the upstream project; locally, you
61         can see how your patch has evolved and easily return to older
62         versions.
64         (iii) TopGit is specifically designed to work in a
65         distributed environment.  You can have several instances of
66         TopGit-aware repositories and smoothly keep them all
67         up-to-date and transfer your changes between them.
69 As mentioned above, the main intended use-case for TopGit is tracking
70 third-party patches, where each patch is effectively a single topic
71 branch.  In order to flexibly accommodate even complex scenarios when
72 you track many patches where many are independent but some depend on
73 others, TopGit ignores the ancient Quilt heritage of patch series and
74 instead allows the patches to freely form graphs (DAGs just like Git
75 history itself, only "one level higher").  For now, you have to manually
76 specify which patches the current one depends on, but TopGit might help
77 you with that in the future in a darcs-like fashion.
79 A glossary_ plug: The union (i.e. merge) of patch dependencies is called
80 a *base* of the patch (topic branch).
82 Of course, TopGit is perhaps not the right tool for you:
84         (i) TopGit is not complicated, but StGIT et al. are somewhat
85         simpler, conceptually.  If you just want to make a linear
86         purely-local patch queue, deferring to StGIT instead might
87         make more sense.
89         (ii) When using TopGit, your history can get a little hairy
90         over time, especially with all the merges rippling through.
91         ;-)
94 SYNOPSIS
95 --------
99         ## Create and evolve a topic branch
100         $ tg create t/gitweb/pathinfo-action
101         tg: Automatically marking dependency on master
102         tg: Creating t/gitweb/pathinfo-action base from master...
103         $ ..hack..
104         $ git commit
105         $ ..fix a mistake..
106         $ git commit
108         ## Create another topic branch on top of the former one
109         $ tg create t/gitweb/nifty-links
110         tg: Automatically marking dependency on t/gitweb/pathinfo-action
111         tg: Creating t/gitweb/nifty-links base from t/gitweb/pathinfo-action...
112         $ ..hack..
113         $ git commit
115         ## Create another topic branch on top of master and submit
116         ## the resulting patch upstream
117         $ tg create t/revlist/author-fixed master
118         tg: Creating t/revlist/author-fixed base from master...
119         $ ..hack..
120         $ git commit
121         $ tg patch -m
122         tg: Sent t/revlist/author-fixed
123         From: pasky@suse.cz
124         To: git@vger.kernel.org
125         Cc: gitster@pobox.com
126         Subject: [PATCH] Fix broken revlist --author when --fixed-string
128         ## Create another topic branch depending on two others non-trivially
129         $ tg create t/whatever t/revlist/author-fixed t/gitweb/nifty-links
130         tg: Creating t/whatever base from t/revlist/author-fixed...
131         tg: Merging t/whatever base with t/gitweb/nifty-links...
132         Merge failed!
133         tg: Please commit merge resolution and call: tg create --continue
134         tg: It is also safe to abort this operation using `git reset --hard`
135         tg: but please remember you are on the base branch now;
136         tg: you will want to switch to a different branch.
137         $ ..resolve..
138         $ git commit
139         $ tg create --continue
140         tg: Resuming t/whatever setup...
141         $ ..hack..
142         $ git commit
144         ## Update a single topic branch and propagate the changes to
145         ## a different one
146         $ git checkout t/gitweb/nifty-links
147         $ ..hack..
148         $ git commit
149         $ git checkout t/whatever
150         $ tg info
151         Topic Branch: t/whatever (1 commit)
152         Subject: [PATCH] Whatever patch
153         Base: 3f47ebc1
154         Depends: t/revlist/author-fixed t/gitweb/nifty-links
155         Needs update from:
156                 t/gitweb/nifty-links (1 commit)
157         $ tg update
158         tg: Updating base with t/gitweb/nifty-links changes...
159         Merge failed!
160         tg: Please commit merge resolution and call `tg update --continue`
161         tg: (use `tg status` to see more options)
162         $ ..resolve..
163         $ git commit
164         $ tg update --continue
165         tg: Updating t/whatever against new base...
166         Merge failed!
167         tg: Please commit merge resolution and call `tg update --continue`
168         tg: (use `tg status` to see more options)
169         $ ..resolve..
170         $ git commit
171         $ tg update --continue
173         ## Update a single topic branch and propagate the changes
174         ## further through the dependency chain
175         $ git checkout t/gitweb/pathinfo-action
176         $ ..hack..
177         $ git commit
178         $ git checkout t/whatever
179         $ tg info
180         Topic Branch: t/whatever (1/2 commits)
181         Subject: [PATCH] Whatever patch
182         Base: 0ab2c9b3
183         Depends: t/revlist/author-fixed t/gitweb/nifty-links
184         Needs update from:
185                 t/gitweb/pathinfo-action (<= t/gitweb/nifty-links) (1 commit)
186         $ tg update
187         tg: Recursing to t/gitweb/nifty-links...
188         [t/gitweb/nifty-links] tg: Updating base with t/gitweb/pathinfo-action changes...
189         Merge failed!
190         [t/gitweb/nifty-links] tg: Please commit merge resolution and call `tg update --continue`
191         [t/gitweb/nifty-links] tg: (use `tg status` to see more options)
192         $ ..resolve..
193         $ git commit
194         $ tg update --continue
195         [t/gitweb/nifty-links] tg: Updating t/gitweb/nifty-links against new base...
196         Merge failed!
197         [t/gitweb/nifty-links] tg: Please commit merge resolution and call `tg update --continue`
198         [t/gitweb/nifty-links] tg: (use `tg status` to see more options)
199         $ ..resolve..
200         $ git commit
201         $ tg update --continue
202         tg: Updating base with t/gitweb/nifty-links changes...
203         tg: Updating t/whatever against new base...
205         ## Clone a TopGit-controlled repository
206         $ git clone URL repo
207         $ cd repo
208         $ tg remote --populate origin
209         ...
210         $ git fetch
211         $ tg update
213         ## Add a TopGit remote to a repository and push to it
214         $ git remote add foo URL
215         $ tg remote foo
216         $ tg push -r foo
218         ## Update from a non-default TopGit remote
219         $ git fetch foo
220         $ tg -r foo summary
221         $ tg -r foo update
224 CONVENTIONS
225 -----------
227 When using TopGit there are several common conventions used when working with
228 TopGit branches.  None of them are enforced, they are only suggestions.
230 There are three typical uses for a TopGit branch:
232     1. [PATCH]
233        Normal TopGit branches that represent a single patch.  These are known
234        as "patch" TopGit branches.
235     2. [BASE]
236        Empty TopGit branches with no dependencies (an empty ``.topdeps`` file)
237        that represent a base upon which other "normal" TopGit branches depend.
238        These are known as "base" TopGit branches (not to be confused with
239        the refs/top-bases/... refs).
240     3. [STAGE]
241        Empty TopGit branches that serve as a staging area to bring together
242        several other TopGit branches into one place so they can be used/tested
243        all together.  These are known as "stage" TopGit branches.
245 An "empty" TopGit branch is one that does not have any changes of its own --
246 it may still have dependencies though ("stage" branches do, "base" branches do
247 not).  The ``tg summary`` output shows empty branches with a ``0`` in the
248 listing.  Normal "patch" branches that have not been annihilated, "base" and
249 "stage" branches fall into this category.  (Annihilated branches are normally
250 omitted from the ``tg summary`` output but can be shown if given explicitly as
251 an argument to the ``tg summary`` command.  However, the message line will be
252 incorrect since an annihilated branch has no ``.topmsg`` file of its own.)
254 A "patch" branch name typically starts with ``t/`` whereas "base" and "stage"
255 branch names often do not.
257 A "base" branch is created by using the ``--no-deps`` option of ``tg create``
258 which will automatically suggest a "[BASE]" message prefix rather than
259 "[PATCH]".  A "stage" branch is created like a normal patch branch except that
260 the only changes that will ever be made to it are typically to add/remove
261 dependencies.  Its subject prefix must be manually changed to "[STAGE]" to
262 reflect its purpose.
264 Since both "base" and "stage" branches typically only have a use for the
265 "Subject:" ilne from their ``.topmsg`` file, they are quite easily created
266 using the ``--topmsg`` option of ``tg create``.
268 Use of "stage" and "base" branches is completely optional.  However, without
269 use of a "stage" branch it will be difficult to test multiple independent
270 patches together all at once.  A "base" branch is merely a convenience that
271 provides more explicit control over when a common base for a set of patches
272 gets updated as well as providing a branch that shows in ``tg summary`` output
273 and participates in ``tg remote --populate`` setup.
275 When using the ``tg tag`` command to create tags that record the current state
276 of one or more TopGit branches, the tags are often created with a name that
277 starts with ``t/``.
279 One last thing, you have enabled ``git rerere`` haven't you?
282 NO UNDO
283 -------
285 Beware, there is no "undo" after running a ``tg update``!
287 Well, that's not entirely correct.  Since ``tg update`` never discards commits
288 an "undo" operation is technically feasible provided the old values of all the
289 refs that were affected by the ``tg update`` operation can be determined and
290 then they are simply changed back to their previous values.
292 In practice though, it can be extremely tedious and error prone looking through
293 log information to try and determine what the correct previous values were.
294 Although, since TopGit tries to make sure reflogs are enabled for top-bases
295 refs, using Git's ``@{date}`` notation on all the refs dumped out by a
296 ``tg tag --refs foo``, where "foo" is the branch that was updated whose update
297 needs to be undone, may work.
299 Alternatively, ``tg tag --stash`` can be used prior to the update and then
300 ``tg revert`` used after the update to restore the previous state.  This
301 assumes, of course, that you remember to run ``tg tag --stash`` first.
303 The ``tg update`` command understands a ``--stash`` option that tells it to
304 automatically run ``tg tag --stash`` before it starts making changes (if
305 everything is up-to-date it won't run the stash command at all).
307 The ``--stash`` option is the default nowadays when running ``tg update``,
308 add the ``--no-stash`` option to turn it off.
310 There is a preference for this.  Setting the config value ``topgit.autostash``
311 to ``false`` will implicitly add the ``--no-stash`` option to any ``tg update``
312 command unless an explicit ``--stash`` option is given.
314 If you are likely to ever want to undo a ``tg update``, setting
315 ``topgit.autostash`` to ``false`` is highly discouraged!
317 Note that the tags saved by ``tg tag --stash`` are stored in the
318 ``refs/tgstash`` ref and its reflog.  Unfortunately, while Git is happy to
319 maintain the reflog (once it's been enabled which ``tg tag`` guarantees for
320 ``refs/tgstash``), Git is unable to view an annotated/signed tag's reflog!
321 Instead Git dereferences the tag and shows the wrong thing.  Use the
322 ``tg tag -g`` command to view the ``refs/tgstash`` reflog instead.
325 SEQUESTRATION
326 -------------
328 No, this is not a section about budget nonsense.  ;)
330 TopGit keeps its metadata in ``.topdeps`` and ``.topmsg`` files.  In an effort
331 to facilitate cherry-picking and other Git activities on the patch changes
332 themselves while ignoring the TopGit metadata, TopGit attempts to keep all
333 changes to ``.topdeps`` and ``.topmsg`` files limited to commits that do NOT
334 contain changes to any other files.
336 This is a departure from previous TopGit versions that made no such effort.
338 Primarily this affects ``tg create`` and ``tg import`` (which makes use of
339 ``tg create``) as ``tg create`` will commit the initial versions of
340 ``.topdeps`` and ``.topmsg`` for a new TopGit-controlled branch in their own
341 commit instead of mixing them in with changes to other files.
343 The ``pre-commit`` hook will also attempt to separate out any ``.topdeps`` and
344 ``.topmsg`` changes from commits that include changes to other files.
346 It is possible to defeat these checks without much effort (``pre-commit`` hooks
347 can easily be bypassed, ``tg create`` has a ``--no-commit`` option, many Git
348 commands simply do not run the ``pre-commit`` hook, etc.).
350 If you really, really, really, really want to change the default back to the
351 old behavior of previous TopGit versions where no such sequestration took
352 place, then set the ``topgit.sequester`` config variable explicitly to the
353 value ``false``.  But this is not recommended.
356 AMENDING AND REBASING AND UPDATE-REF'ING
357 ----------------------------------------
359 In a word, "don't".
361 It is okay to manually update a top-bases/... ref when a) it has no depedencies
362 (i.e. it was created with the ``tg create`` ``--no-deps`` option) and b) the
363 old top-bases/... ref value can be fast-forwarded to the new top-bases/...
364 value OR the new value contains ALL of the changes in the old value through
365 some other mechanism (perhaps they were cherry-picked or otherwise applied to
366 the new top-bases/... ref).  The same rules apply to non-TopGit-controlled
367 dependencies.
369 Ignoring this rule and proceeding anyway with a non-fast-forward update to a
370 top-bases/... ref will result in changes present in the new value being merged
371 into the branch (at ``tg update`` time) as expected (possibly with conflicts),
372 but any changes that were contained in the old version of the top-bases/... ref
373 which have been dropped (i.e. are NOT contained in the new version of the
374 top-bases/... ref) will continue to be present in the branch!  To get rid of
375 the dropped commits, one or more "revert" commits will have to be manually
376 applied to the tip of the new top-bases/... value (which will then be merged
377 into the branch at next ``tg update`` time).
379 The only time it's safe to amend, rebase, filter or otherwise rewrite commits
380 contained in a TopGit controlled branch or non-TopGit branch is when those
381 commits are NOT reachable via any other ref!
383 Furthermore, while it is safe to rewrite merge commits (provided they meet the
384 same conditions) the merge commits themselves and the branches they are merging
385 in must be preserved during the rewrite and that can be rather tricky to get
386 right so it's not recommended.
388 For example, if, while working on a TopGit-controlled branch ``foo``, a bad
389 typo is noticed, it's okay to ammend/rebase to fix that provided neither
390 ``tg update`` nor ``tg create`` has already been used to cause some other ref
391 to be able to reach the commit with the typo.
393 If an amend or rerwite is done anyway even though the commit with the typo is
394 reachable from some other ref, the typo won't really be removed.  What will
395 happen instead is that the new version without the typo will ultimately be
396 merged into the other ref(s) (at ``tg update`` time) likely causing a conflict
397 that will have to be manually resolved and the commit with the typo will
398 continue to be reachable from those other refs!
400 Instead just make a new commit to fix the typo.  The end result will end up
401 being the same but without the merge conflicts.
403 See also the discussion in the `NO UNDO`_ section.
406 SPEED AND CACHING
407 -----------------
409 TopGit needs to check many thing to determine whether a TopGit branch is
410 up-to-date or not.  This can involve a LOT of git commands for a complex
411 dependency tree.  In order to speed things up, TopGit keeps a cache of results
412 in a ``tg-cache`` subdirectory in the ``.git`` directory.
414 Results are tagged with the original hash values used to get that result so
415 that items which have not been changed return their results quickly and items
416 which have been changed compute their new result and cache it for future use.
418 The ``.git/tg-cache`` directory may be removed at any time and the cache will
419 simply be recreated in an on-demand fashion as needed, at some speed penalty,
420 until it's fully rebuilt.
422 To force the cache to be fully pre-loaded, run the ``tg summary`` command
423 without any arguments.  Otherwise, normal day-to-day TopGit operations should
424 keep it more-or-less up-to-date.
426 While each TopGit command is running, it uses a temporary subdirectory also
427 located in the ``.git`` directory.  These directories are named
428 ``tg-tmp.XXXXXX`` where the ``XXXXXX`` part will be random letters and digits.
430 These temporary directories should always be removed automatically after each
431 TopGit command finishes running.  As long as you are not in a subshell as a
432 result of a TopGit command stopping and waiting for a manual merge resolution,
433 it's safe to remove any of these directories that may have somehow accidentally
434 been left behind as a result of some failure that occurred while running a
435 TopGit command (provided, of course, it's not actually being used by a TopGit
436 command currently running in another terminal window or by another user on the
437 same repository).
440 USAGE
441 -----
442 ``tg [-C <dir>] [-r <remote> | -u] [-c <name>=<val>] <subcommand> [<subcommand option/argument>...]``
444         -C <dir>        Change directory to <dir> before doing anything
445         -r <remote>     Pretend ``topgit.remote`` is set to <remote>
446         -u              Pretend ``topgit.remote`` is not set
447         -c <name=val>   Pass config option to git, may be repeated
449 The ``tg`` tool has several subcommands:
451         :`tg annihilate`_:  Mark a TopGit-controlled branch as defunct
452         :`tg base`_:        Show base commit for one or more TopGit branches
453         :`tg checkout`_:    Shortcut for git checkout with name matching
454         :`tg create`_:      Create a new TopGit-controlled branch
455         :`tg delete`_:      Delete a TopGit-controlled branch cleanly
456         :`tg depend`_:      Add a new dependency to a TopGit-controlled branch
457         :`tg export`_:      Export TopGit branch patches to files or a branch
458         :`tg files`_:       Show files changed by a TopGit branch
459         :`tg help`_:        Show TopGit help optionally using a browser
460         :`tg import`_:      Import commit(s) to separate TopGit branches
461         :`tg info`_:        Show status information about a TopGit branch
462         :`tg log`_:         Run git log limiting revisions to a TopGit branch
463         :`tg mail`_:        Shortcut for git send-email with ``tg patch`` output
464         :`tg migrate-bases`_: Transition top-bases to new location
465         :`tg next`_:        Show branches directly depending on a TopGit branch
466         :`tg patch`_:       Generate a patch file for a TopGit branch
467         :`tg prev`_:        Show non-annihilated TopGit dependencies for a branch
468         :`tg push`_:        Run git push on TopGit branch(es) and depedencies
469         :`tg rebase`_:      Auto continue git rebase if rerere resolves conflicts
470         :`tg remote`_:      Set up remote for fetching/pushing TopGit branches
471         :`tg revert`_:      Revert ref(s) to a state stored in a ``tg tag``
472         :`tg status`_:      Show current TopGit status (e.g. in-progress update)
473         :`tg summary`_:     Show various information about TopGit branches
474         :`tg tag`_:         Create tag that records current TopGit branch state
475         :`tg update`_:      Update TopGit branch(es) with respect to dependencies
477 tg help
478 ~~~~~~~
479         Our sophisticated integrated help facility.  Mostly duplicates
480         what is below::
482          # to list commands:
483          $ tg help
484          # to get help for a particular command:
485          $ tg help <command>
486          # to get help for a particular command in a browser window:
487          $ tg help -w <command>
488          # to get help on TopGit itself
489          $ tg help tg
490          # to get help on TopGit itself in a browser
491          $ tg help -w tg
493 tg status
494 ~~~~~~~~~
495         Our sophisticated status facility.  Similar to Git's status command
496         but shows any in-progress update that's awaiting a merge resolution
497         or any other on-going TopGit activity (such as a branch creation).
499         With the ``--exit-code`` option the exit code will be non-zero if any
500         TopGit or Git operation is currently in progress or the working
501         tree is unclean.
503 tg create
504 ~~~~~~~~~
505         Create a new TopGit-controlled topic branch of the given name
506         (required argument) and switch to it.  If no dependencies are
507         specified (by extra arguments passed after the first one), the
508         current branch is assumed to be the only dependency.
510         By default ``tg create`` opens an editor on the new ``.topmsg`` file
511         and then commits the new ``.topmsg`` and ``.topdeps`` files
512         automatically with a suitable default commit message.
514         The commit message can be changed with the ``-m`` (or ``--message``) or
515         ``-F`` (or ``--file``) option.  The automatic commit can be suppressed
516         by using the ``--no-ccmmit`` option.  Running the editor on the new
517         ``.topmsg`` file can be suppressed by using ``-n`` (or ``--no-edit``)
518         (which also suppresses the automatic commit) or by providing an
519         explicit value for the new ``.topmsg`` file using the ``--topmsg`` or
520         ``--topmsg-file`` option.  In any case the ``.topmsg`` content will be
521         automatically reformated to have a ``Subject:`` header line if needed.
523         If more than one dependency is listed, the automatic commit will not
524         take place until AFTER all the listed dependencies have been merged
525         into a base commit which will require some manual merge resolutions if
526         conflicts occur during the merge operations.
528         Previous versions of TopGit behaved as though the ``--no-edit`` option
529         was always given on the command line.
531         The default behavior has been changed to promote a separation between
532         commits that modify ``.topmsg`` and/or ``.topdeps`` and commits that
533         modify other files.  This facilitates cleaner cherry picking and other
534         patch maintenance activities.
536         You should edit the patch description (contained in the ``.topmsg``
537         file) as appropriate.  It will already contain some prefilled bits.
538         You can set the ``topgit.to``, ``topgit.cc`` and ``topgit.bcc``
539         git configuration variables (see ``man git-config``) in order to
540         have ``tg create`` add these headers with the given default values
541         to ``.topmsg`` before invoking the editor.
543         The main task of ``tg create`` is to set up the topic branch base
544         from the dependencies.  This may fail due to merge conflicts if more
545         than one dependencie is given.  In that case, after you commit the
546         conflict resolution, you should call ``tg create`` again (without any
547         arguments or with the single argument ``--continue``); it will then
548         detect that you are on a topic branch base ref and resume the topic
549         branch creation operation.
551         With the ``--no-deps`` option at most one dependency may be listed
552         which may be any valid committish (instead of just refs/heads/...) and
553         the newly created TopGit-controlled branch will have an empty
554         ``.topdeps`` file.  This may be desirable in order to create a TopGit-
555         controlled branch that has no changes of its own and serves merely to
556         mark the common dependency that all other TopGit-controlled branches
557         in some set of TopGit-controlled branches depend on.  A plain,
558         non-TopGit-controlled branch can be used for the same purpose, but the
559         advantage of a TopGit-controlled branch with no dependencies is that it
560         will be pushed with ``tg push``, it will show up in the ``tg summary``
561         and ``tg info`` output with the subject from its ``.topmsg`` file
562         thereby documenting what it's for and finally it can be set up with
563         ``tg create -r`` and/or ``tg remote --populate`` to facilitate sharing.
565         For example, ``tg create --no-deps release v2.1`` will create a TopGit-
566         controlled ``release`` branch based off the ``v2.1`` tag that can then
567         be used as a base for creation of other TopGit-controlled branches.
568         Then when the time comes to move the base for an entire set of changes
569         up to ``v2.2`` the command ``git update-ref top-bases/release v2.2^0``
570         can be used followed by ``tg update --all``.  Note that it's only safe
571         to update ``top-bases/release`` directly in this manner because a) it
572         has no depedencies since it was created with the ``--no-deps`` option
573         and b) the old ``top-bases/release`` value can be fast-forwarded to the
574         new ``top-bases/release`` value.
576         Using ``--no-deps`` it's also possible to use ``tg create`` on an
577         unborn branch (omit the dependency name or specify ``HEAD``).  The
578         unborn branch itself can be made into the new TopGit branch (rather
579         than being born empty and then having the new TopGit branch based off
580         that) by specifying ``HEAD`` as the new branch's name (which is
581         probably what you normally want to do in this case anyway so you can
582         just run ``tg create --no-deps HEAD`` to accomplish that).
584         In an alternative use case, if ``-r <branch>`` is given instead of a
585         dependency list, the topic branch is created based on the given
586         remote branch.  With just ``-r`` the remote branch name is assumed
587         to be the same as the local topic branch being created.  Since no
588         new commits are created in this mode (only two refs will be updated)
589         the editor will never be run for this use case.  Note that no other
590         options may be combined with ``-r``.
592         The ``--quiet`` (or ``-q``) option suppresses most informational
593         messages.
595 tg delete
596 ~~~~~~~~~
597         Remove a TopGit-controlled topic branch of the given name
598         (required argument). Normally, this command will remove only an
599         empty branch (base == head) without dependendents; use ``-f`` to
600         remove a non-empty branch or a branch that is depended upon by
601         another branch.
603         The ``-f`` option is also useful to force removal of a branch's
604         base, if you used ``git branch -D B`` to remove branch B, and then
605         certain TopGit commands complain, because the base of branch B
606         is still there.
608         Normally ``tg delete`` will refuse to delete the current branch.
609         However, giving ``-f`` twice (or more) will force it to do so but it
610         will first detach your HEAD.
612         IMPORTANT: Currently, this command will *NOT* remove the branch
613         from the dependency list in other branches. You need to take
614         care of this *manually*.  This is even more complicated in
615         combination with ``-f`` -- in that case, you need to manually
616         unmerge the removed branch's changes from the branches depending
617         on it.
619         See also ``tg annihilate``.
621         | TODO: ``-a`` to delete all empty branches, depfix, revert
623 tg annihilate
624 ~~~~~~~~~~~~~
625         Make a commit on the current TopGit-controlled topic branch
626         that makes it equal to its base, including the presence or
627         absence of .topmsg and .topdeps.  Annihilated branches are not
628         displayed by ``tg summary``, so they effectively get out of your
629         way.  However, the branch still exists, and ``tg push`` will
630         push it (except if given the ``-a`` option).  This way, you can
631         communicate that the branch is no longer wanted.
633         When annihilating a branch that has dependents (i.e. branches
634         that depend on it), those dependents have the dependencies of
635         the branch being annihilated added to them if they do not already
636         have them as dependencies.  Essentially the DAG is repaired to
637         skip over the annihilated branch.
639         Normally, this command will remove only an empty branch
640         (base == head, except for changes to the .top* files); use
641         ``-f`` to annihilate a non-empty branch.
643         After completing the annihilation itself, normally ``tg update``
644         is run on any modified dependents.  Use the ``--no-update`` option
645         to suppress running ``tg update``.
647 tg depend
648 ~~~~~~~~~
649         Change the dependencies of a TopGit-controlled topic branch.
650         This should have several subcommands, but only ``add`` is
651         supported right now.
653         The ``add`` subcommand takes an argument naming a topic branch to
654         be added, adds it to ``.topdeps``, performs a commit and then
655         updates your topic branch accordingly.  If you want to do other
656         things related to the dependency addition, like adjusting
657         ``.topmsg``, use the option ``--no-commit``.  Adding the
658         ``--no-update`` (or ``--no-commit``) option will suppress the
659         ``tg update`` normally performed after committing the change.
661         It is safe to run ``tg depend add`` in a dirty worktree, but the
662         normally performed ``tg update`` will be suppressed in that case
663         (even if neither ``--no-update`` nor ``--no-commit`` is given).
665         You have enabled ``git rerere`` haven't you?
667         | TODO: Subcommand for removing dependencies, obviously
669 tg files
670 ~~~~~~~~
671         List files changed by the current or specified topic branch.
673         Options:
674           -i            list files based on index instead of branch
675           -w            list files based on working tree instead of branch
677 tg info
678 ~~~~~~~
679         Show summary information about the current or specified topic
680         branch.
682         Numbers in parenthesis after a branch name such as "(11/3 commits)"
683         indicate how many commits on the branch (11) and how many of those
684         are non-merge commits (3).
686         Alternatively, if ``--heads`` is used then which of the independent
687         TopGit branch heads (as output by ``tg summary --tgish-only --heads)``
688         contains the specified commit (which may be any committish -- defaults
689         to ``HEAD`` if not given).  Zero or more results will be output.
691 tg patch
692 ~~~~~~~~
693         Generate a patch from the current or specified topic branch.
694         This means that the diff between the topic branch base and head
695         (latest commit) is shown, appended to the description found in
696         the ``.topmsg`` file.
698         The patch is simply dumped to stdout.  In the future, ``tg patch``
699         will be able to automatically send the patches by mail or save
700         them to files. (TODO)
702         Options:
703           -i            base patch generation on index instead of branch
704           -w            base patch generation on working tree instead of branch
705           --binary      pass --binary to ``git diff-tree`` to enable generation
706                         of binary patches
707           --diff-opt    options after the branch name (and an optional ``--``)
708                         are passed directly to ``git diff-tree``
710         In order to pass a sole explicit ``-w`` through to ``git diff-tree`` it
711         must be separated from the ``tg`` options by an explicit ``--``.
712         Or it can be spelled as ``--ignore-all-space`` to distinguuish it from
713         ``tg``'s ``-w`` option.
715         If additional non-``tg`` options are passed through to
716         ``git diff-tree`` (other than ``--binary`` which is fully supported)
717         the resulting ``tg patch`` output may not be appliable.
719 tg mail
720 ~~~~~~~
721         Send a patch from the current or specified topic branch as
722         email(s).
724         Takes the patch given on the command line and emails it out.
725         Destination addresses such as To, Cc and Bcc are taken from the
726         patch header.
728         Since it actually boils down to ``git send-email``, please refer
729         to the documentation for that for details on how to setup email
730         for git.  You can pass arbitrary options to this command through
731         the ``-s`` parameter, but you must double-quote everything.  The
732         ``-r`` parameter with a msgid can be used to generate in-reply-to
733         and reference headers to an earlier mail.
735         WARNING: be careful when using this command.  It easily sends
736         out several mails.  You might want to run::
738                 git config sendemail.confirm always
740         to let ``git send-email`` ask for confirmation before sending any
741         mail.
743         Options:
744           -i            base patch generation on index instead of branch
745           -w            base patch generation on working tree instead of branch
747         | TODO: ``tg mail patchfile`` to mail an already exported patch
748         | TODO: mailing patch series
749         | TODO: specifying additional options and addresses on command line
751 tg remote
752 ~~~~~~~~~
753         Register the given remote as TopGit-controlled. This will create
754         the namespace for the remote branch bases and teach ``git fetch``
755         to operate on them. However, from TopGit 0.8 onwards you need to
756         use ``tg push``, or ``git push --mirror``, for pushing
757         TopGit-controlled branches.
759         ``tg remote`` takes an optional remote name argument, and an
760         optional ``--populate`` switch.  Use ``--populate`` for your
761         origin-style remotes: it will seed the local topic branch system
762         based on the remote topic branches.  ``--populate`` will also make
763         ``tg remote`` automatically fetch the remote, and ``tg update`` look
764         at branches of this remote for updates by default.
766         Using ``--populate`` with a remote name causes the ``topgit.remote``
767         git configuration variable to be set to the given remote name.
769 tg summary
770 ~~~~~~~~~~
771         Show overview of all TopGit-tracked topic branches and their
772         up-to-date status.  With a branch name limit output to that branch.
773         Using ``--deps-only`` or ``--rdeps`` changes the default from all
774         branches to just the current ``HEAD`` branch but using ``--all`` as
775         the branch name will show results for all branches instead of ``HEAD``.
777                 ``>``
778                         marks the current topic branch
780                 ``0``
781                         indicates that it introduces no changes of its own
783                 ``l``/``r``
784                         indicates respectively whether it is local-only
785                         or has a remote mate
787                 ``L``/``R``
788                         indicates respectively if it is ahead or out-of-date
789                         with respect to its remote mate
791                 ``D``
792                         indicates that it is out-of-date with respect to its
793                         dependencies
795                 ``!``
796                         indicates that it has missing dependencies [even if
797                         they are recursive ones]
799                 ``B``
800                         indicates that it is out-of-date with respect to
801                         its base
803         This can take a longish time to accurately determine all the
804         relevant information about each branch; you can pass ``-t`` (or ``-l``
805         or ``--list``) to get just a terse list of topic branch names quickly.
807         Passing ``--heads`` shows independent topic branch names and when
808         combined with ``--rdeps`` behaves as though ``--rdeps`` were run with
809         the output of ``--heads``.
811         Using ``--heads-only`` behaves as though the output of ``--heads`` was
812         passed as the list of branches along with ``--without-deps``.
814         Alternatively, you can pass ``--graphviz`` to get a dot-suitable output
815         for drawing a dependency graph between the topic branches.
817         You can also use the ``--sort`` option to sort the branches using
818         a topological sort.  This is especially useful if each
819         TopGit-tracked topic branch depends on a single parent branch,
820         since it will then print the branches in the dependency order.
821         In more complex scenarios, a text graph view would be much more
822         useful, but that has not yet been implemented.
824         The ``--deps`` option outputs dependency information between
825         branches in a machine-readable format.  Feed this to ``tsort`` to
826         get the output from --sort.
828         The ``--deps-only`` option outputs a sorted list of the unique branch
829         names given on the command line plus all of their recursive
830         dependencies (subject to ``--exclude`` of course).  When
831         ``--deps-only`` is given the default is to just display information for
832         ``HEAD``, but that can be changed by using ``--all`` as the branch
833         name.  Each branch name will appear only once in the output no matter
834         how many times it's visited while tracing the dependency graph or how
835         many branch names are given on the command line to process.
837         The ``--rdeps`` option outputs dependency information in an indented
838         text format that clearly shows all the dependencies and their
839         relationships to one another.  When ``--rdeps`` is given the default is
840         to just display information for ``HEAD``, but that can be changed by
841         using ``--all`` as the branch name or by adding the ``--heads`` option.
842         Note that ``tg summary --rdeps --heads`` can be particularly helpful in
843         seeing all the TopGit-controlled branches in the repository and their
844         relationships to one another.
846         Adding ``--with-deps`` replaces the given list of branches (which will
847         default to ``HEAD`` if none are given) with the result of running
848         ``tg summary --deps-only --tgish`` on the list of branches.  This can
849         be helpful in limiting ``tg summary`` output to only the list of given
850         branches and their dependencies when many TopGit-controlled branches
851         are present in the repository.  When it would be allowed,
852         ``--with-deps`` is now the default.  Use ``--without-deps`` to switch
853         back to the old behavior.
855         With ``--exclude branch``, branch can be excluded from the output
856         meaning it will be skipped and its name will be omitted from any
857         dependency output.  The ``--exclude`` option may be repeated to omit
858         more than one branch from the output.  Limiting the output to a single
859         branch that has been excluded will result in no output at all.
861         The ``--tgish-only`` option behaves as though any non-TopGit-controlled
862         dependencies encountered during processing had been listed after an
863         ``--exclude`` option.
865         Note that the branch name can be specified as ``HEAD`` or ``@`` as a
866         shortcut for the TopGit-controlled branch that ``HEAD`` is a
867         symbolic ref to.  The ``tg summary @`` command can be quite useful.
869         Options:
870           -i            Use TopGit metadata from the index instead of the branch
871           -w            Use TopGit metadata from the working tree instead of the branch
874 tg checkout
875 ~~~~~~~~~~~
876         Switch to a topic branch.  You can use ``git checkout <branch>``
877         to get the same effect, but this command helps you navigate
878         the dependency graph, or allows you to match the topic branch
879         name using a regular expression, so it can be more convenient.
881         There following subcommands are available:
883             ``tg checkout push``
884                                 Check out a branch that directly
885                                 depends on your current branch.
887             ``tg checkout pop``
888                                 Check out a branch that this branch
889                                 directly depends on.
891             ``tg checkout [goto] [--] <pattern>``
892                                 Check out a topic branch that
893                                 matches ``<pattern>``.  ``<pattern>``
894                                 is used as a sed pattern to filter
895                                 all the topic branches.  Both ``goto`` and
896                                 ``--`` may be omitted provided ``<pattern>``
897                                 is not ``push``, ``pop``, ``-a``, ``--all``,
898                                 ``goto``, ``..``, ``--``, ``next``, ``child``,
899                                 ``prev``, ``parent``, ``-h`` or ``--help``.
901             ``tg checkout next``
902                                 An alias for ``push``.
904             ``tg checkout child``
905                                 An alias for ``push``.
907             ``tg checkout``
908                                 An alias for ``push``.
910             ``tg checkout prev``
911                                 An alias for ``pop``.
913             ``tg checkout parent``
914                                 An alias for ``pop``.
916             ``tg checkout ..``
917                                 An alias for ``pop``.
919         If any of the above commands can find more than one possible
920         branch to switch to, you will be presented with the matches
921         and asked to select one of them.
923         The ``<pattern>`` of ``tg checkout goto`` is optional.  If you don't
924         supply it, all the available topic branches are listed and you
925         can select one of them.
927         Normally, the ``push`` and ``pop`` commands moves one step in
928         the dependency graph of the topic branches.  The ``-a`` option
929         causes them (and their aliases) to move as far as possible.
930         That is, ``tg checkout push -a`` moves to a topic branch that
931         depends (directly or indirectly) on the current branch and
932         that no other branch depends on.  ``tg checkout pop -a``
933         moves to a regular branch that the current topic branch
934         depends on (directly or indirectly).  If there is more than
935         one possibility, you will be prompted for your selection.
937 tg export
938 ~~~~~~~~~
939         Export a tidied-up history of the current topic branch and its
940         dependencies, suitable for feeding upstream.  Each topic branch
941         corresponds to a single commit or patch in the cleaned up
942         history (corresponding basically exactly to ``tg patch`` output
943         for the topic branch).
945         The command has three possible outputs now -- either a Git branch
946         with the collapsed history, a Git branch with a linearized
947         history, or a quilt series in new directory.
949         In the case where you are producing collapsed history in a new
950         branch, you can use this collapsed structure either for
951         providing a pull source for upstream, or for further
952         linearization e.g. for creation of a quilt series using git log::
954                 git log --pretty=email -p --topo-order origin..exported
956         To better understand the function of ``tg export``, consider this
957         dependency structure::
959          origin/master - t/foo/blue - t/foo/red - master
960                       `- t/bar/good <,----------'
961                       `- t/baz      ------------'
963         (where each of the branches may have a hefty history). Then::
965          master$ tg export for-linus
967         will create this commit structure on the branch ``for-linus``::
969          origin/master - t/foo/blue -. merge - t/foo/red -.. merge - master
970                       `- t/bar/good <,-------------------'/
971                       `- t/baz      ---------------------'
973         In this mode, ``tg export`` works on the current topic branch, and
974         can be called either without an option (in that case,
975         ``--collapse`` is assumed), or with the ``--collapse`` option, and
976         with one mandatory argument: the name of the branch where the
977         exported result will be stored.
979         When using the linearize mode::
981          master$ tg export --linearize for-linus
983         you get a linear history respecting the dependencies of your
984         patches in a new branch ``for-linus``.  The result should be more
985         or less the same as using quilt mode and then reimporting it
986         into a Git branch.  (More or less because the topological order
987         can usually be extended in more than one way into a total order,
988         and the two methods may choose different ones.)  The result
989         might be more appropriate for merging upstream, as it contains
990         fewer merges.
992         Note that you might get conflicts during linearization because
993         the patches are reordered to get a linear history.  If linearization
994         would produce conflicts then using ``--quilt`` will also likely result
995         in conflicts when the exported quilt series is applied.  Since the
996         ``--quilt`` mode simply runs a series of ``tg patch`` commands to
997         generate the patches in the exported quilt series and those patches
998         will end up being applied linearly, the same conflicts that would be
999         produced by the ``--linearize`` option will then occur at that time.
1001         To avoid conflicts produced by ``--linearize`` (or by applying the
1002         ``--quilt`` output), use the default ``--collapse`` mode and then use
1003         ``tg rebase`` (or ``git rebase -m`` directly) on the collapsed branch
1004         (with a suitable <upstream>) followed by ``git format-patch`` on the
1005         rebased result to produce a conflict-free patch set.
1007         You have enabled ``git rerere`` haven't you?
1009         When using the quilt mode::
1011          master$ tg export --quilt for-linus
1013         would create the following directory ``for-linus``::
1015          for-linus/t/foo/blue.diff
1016          for-linus/t/foo/red.diff
1017          for-linus/t/bar/good.diff
1018          for-linus/t/baz.diff
1019          for-linus/series:
1020                 t/foo/blue.diff -p1
1021                 t/bar/good.diff -p1
1022                 t/foo/red.diff -p1
1023                 t/baz.diff -p1
1025         With ``--quilt``, you can also pass the ``-b`` parameter followed
1026         by a comma-separated explicit list of branches to export, or
1027         the ``--all`` parameter (which can be shortened to ``-a``) to
1028         export them all.  The ``--binary`` option enables producing Git
1029         binary patches.  These options are currently only supported
1030         with ``--quilt``.
1032         In ``--quilt`` mode the patches are named like the originating
1033         topgit branch.  So usually they end up in subdirectories of the
1034         output directory.  With the ``--flatten`` option the names are
1035         mangled so that they end up directly in the output dir (slashes
1036         are replaced with underscores).  With the ``--strip[=N]`` option
1037         the first ``N`` subdirectories (all if no ``N`` is given) get
1038         stripped off.  Names are always ``--strip``'d before being
1039         ``--flatten``'d.  With the option ``--numbered`` (which implies
1040         ``--flatten``) the patch names get a number as prefix to allow
1041         getting the order without consulting the series file, which
1042         eases sending out the patches.
1044         | TODO: Make stripping of non-essential headers configurable
1045         | TODO: Make stripping of [PATCH] and other prefixes configurable
1046         | TODO: ``--mbox`` option to export instead as an mbox file
1047         | TODO: support ``--all`` option in other modes of operation
1048         | TODO: For quilt exporting, export the linearized history created in
1049                 a temporary branch--this would allow producing conflict-less
1050                 series
1052 tg import
1053 ~~~~~~~~~
1054         Import commits within the given revision range into TopGit,
1055         creating one topic branch per commit. The dependencies are set
1056         up to form a linear sequence starting on your current branch --
1057         or a branch specified by the ``-d`` parameter, if present.
1059         The branch names are auto-guessed from the commit messages and
1060         prefixed by ``t/`` by default; use ``-p <prefix>`` to specify an
1061         alternative prefix (even an empty one).
1063         Alternatively, you can use the ``-s NAME`` parameter to specify
1064         the name of the target branch; the command will then take one
1065         more argument describing a *single* commit to import.
1067 tg update
1068 ~~~~~~~~~
1069         Update the current, specified or all topic branches with respect
1070         to changes in the branches they depend on and remote branches.
1071         This is performed in two phases -- first, changes within the
1072         dependencies are merged to the base, then the base is merged
1073         into the topic branch.  The output will guide you on what to do
1074         next in case of conflicts.
1076         You have enabled ``git rerere`` haven't you?
1078         When ``-a`` (or ``--all``) is specifed, updates all topic branches
1079         matched by ``<pattern>``'s (see ``git-for-each-ref(1)`` for details),
1080         or all if no ``<pattern>`` is given.  Any topic branches with missing
1081         dependencies will be skipped entirely unless ``--skip-missing`` is
1082         specified.
1084         When ``--skip-missing`` is specifed, an attempt is made to update topic
1085         branches with missing dependencies by skipping only the dependencies
1086         that are missing.  Caveat utilitor.
1088         When ``--stash`` is specified (or the ``topgit.autostash`` config
1089         value is set to ``true``), a ref stash will be automatically created
1090         just before beginning updates if any are needed.  The ``--no-stash``
1091         option may be used to disable a ``topgit.autostash=true`` setting.
1092         See the ``tg tag`` ``--stash`` option for details.
1094         After the update, if a single topic branch was specified, it is
1095         left as the current one; if ``-a`` was specified, it returns to
1096         the branch which was current at the beginning.
1098         If your dependencies are not up-to-date, ``tg update`` will first
1099         recurse into them and update them.
1101         If a remote branch update brings in dependencies on branches
1102         that are not yet instantiated locally, you can either bring in
1103         all the new branches from the remote using ``tg remote
1104         --populate``, or only pick out the missing ones using ``tg create
1105         -r`` (``tg summary`` will point out branches with incomplete
1106         dependencies by showing an ``!`` next to them).
1108         | TODO: ``tg update -a -c`` to autoremove (clean) up-to-date branches
1110 tg push
1111 ~~~~~~~
1112         If ``-a`` or ``--all`` was specified, pushes all non-annihilated
1113         TopGit-controlled topic branches, to a remote repository.
1114         Otherwise, pushes the specified topic branches -- or the
1115         current branch, if you don't specify which.  By default, the
1116         remote gets all the dependencies (both TopGit-controlled and
1117         non-TopGit-controlled) and bases pushed to it too.  If
1118         ``--tgish-only`` was specified, only TopGit-controlled
1119         dependencies will be pushed, and if ``--no-deps`` was specified,
1120         no dependencies at all will be pushed.
1122         The ``--dry-run`` and ``--force`` options are passed directly to
1123         ``git push`` if given.
1125         The remote may be specified with the ``-r`` option. If no remote
1126         was specified, the configured default TopGit remote will be
1127         used.
1129 tg base
1130 ~~~~~~~
1131         Prints the base commit of each of the named topic branches, or
1132         the current branch if no branches are named.  Prints an error
1133         message and exits with exit code 1 if the named branch is not
1134         a TopGit branch.
1136 tg log
1137 ~~~~~~
1138         Prints the git log of the named topgit branch -- or the current
1139         branch, if you don't specify a name.
1141         NOTE: if you have merged changes from a different repository, this
1142         command might not list all interesting commits.
1144 tg tag
1145 ~~~~~~
1146         Creates a TopGit annotated/signed tag or lists the reflog of one.
1148         A TopGit annotated tag records the current state of one or more TopGit
1149         branches and their dependencies and may be used to revert to the tagged
1150         state at any point in the future.
1152         When reflogs are enabled (the default in a non-bare repository) and
1153         combined with the ``--force`` option a single tag name may be used as a
1154         sort of TopGit branch state stash.  The special branch name ``--all``
1155         may be used to tag the state of all current TopGit branches to
1156         facilitate this function and has the side-effect of suppressing the
1157         out-of-date check allowing out-of-date branches to be included.
1159         As a special feature, ``--stash`` may be used as the tag name in which
1160         case ``--all`` is implied if no branch name is listed (instead of the
1161         normal default of ``HEAD``), ``--force`` and ``--no-edit`` (use
1162         ``--edit`` to change that) are automatically activated and the tag will
1163         be saved to ``refs/tgstash`` instead of ``refs/tags/<tagname>``.
1164         The ``--stash`` tag name may also be used with the ``-g``/``--reflog``
1165         option.
1167         The mostly undocumented option ``--allow-outdated`` will bypass the
1168         out-of-date check and is implied when ``--stash`` or ``--all`` is used.
1170         A TopGit annotated/signed tag is simply a Git annotated/signed tag with
1171         a "TOPGIT REFS" section appended to the end of the tag message (and
1172         preceding the signature for signed tags).  PEM-style begin and end
1173         lines surround one line per ref where the format of each line is
1174         full-hash SP ref-name.  A line will be included for each branch given
1175         on the command line and each ref they depend on either directly or
1176         indirectly.
1178         If more than one TopGit branch is given on the command line, a new
1179         commit will be created that has an empty tree and all of the given
1180         TopGit branches as parents and that commit will be tagged.  If a single
1181         TopGit branch is given, then it will be tagged.  If the ``--tree``
1182         option is used then it will be used instead of an empty tree (a new
1183         commit will be created if necessary to guarantee the specified tree is
1184         what's in the commit the newly created tag refers to).  The argument to
1185         the ``--tree`` option may be any valid treeish.
1187         All the options for creating a tag serve the same purpose as their Git
1188         equivalents except for two.  The ``--refs`` option suppresses tag
1189         creation entirely and emits the "TOPGIT REFS" section that would have
1190         been included with the tag.  If the ``--no-edit`` option is given and
1191         no message is supplied (via the ``-m`` or ``-F`` option) then the
1192         default message created by TopGit will be used without running the
1193         editor.
1195         With ``-g`` or ``--reflog`` show the reflog for a tag.  With the
1196         ``--reflog-message`` option the message from the reflog is shown.
1197         With the ``--commit-message`` option the first line of the tag's
1198         message (if the object is a tag) or the commit message (if the object
1199         is a commit) falling back to the reflog message for tree and blob
1200         objects is shown.  The default is ``--reflog-message`` unless the
1201         ``--stash`` (``refs/tgstash``) is being shown in which case the default
1202         is then ``--commit-message``.  Just add either option explicitly to
1203         override the default.
1205         When showing reflogs, non-tag entries are annotated with their type
1206         unless ``--no-type`` is given.
1208         TopGit tags are created with a reflog if core.logallrefupdates is
1209         enabled (the default for non-bare repositories).  Unfortunately Git
1210         is incapable of showing an annotated/signed tag's reflog
1211         (using git log -g) as it will first resolve the tag before checking to
1212         see if it has a reflog.  Git can, however, show reflogs for lightweight
1213         tags (using git log -g) just fine but that's not helpful here.  Use
1214         ``tg tag`` with the ``-g`` or ``--reflog`` option to see the reflog for
1215         an actual tag object.  This also works on non-TopGit annotated/signed
1216         tags as well provided they have a reflog.
1218         The number of entries shown may be limited with the ``-n`` option.  If
1219         the tagname is omitted then ``--stash`` is assumed.
1221         The ``--delete`` option is a convenience option that runs the
1222         ``git update-ref -d`` command on the specified tag removing it and its
1223         reflog (if it has one).
1225         The ``--clear`` option clears all but the most recent (the ``@{0}``)
1226         reflog entries from the reflog for the specified tag.  It's equivalent
1227         to dropping all the higher numbered reflog entries.
1229         The ``--drop`` option drops the specified reflog entry and requires the
1230         given tagname to have an ``@{n}`` suffix where ``n`` is the reflog
1231         entry number to be dropped.   This is really just a convenience option
1232         that runs the appropriate ``git reflog delete`` command.
1234         Note that when combined with ``tg revert``, a tag created by ``tg tag``
1235         can be used to transfer TopGit branches.  Simply create the tag, push
1236         it somewhere and then have the recipient run ``tg revert`` to recreate
1237         the TopGit branches.  This may be helpful in situations where it's not
1238         feasible to push all the refs corresponding to the TopGit-controlled
1239         branches and their top-bases.
1241 tg rebase
1242 ~~~~~~~~~
1243         Provides a ``git rebase`` rerere auto continue function.  It may be
1244         used as a drop-in replacement front-end for ``git rebase -m`` that
1245         automatically continues the rebase when ``git rerere`` information is
1246         sufficient to resolve all conflicts.
1248         You have enabled ``git rerere`` haven't you?
1250         If the ``-m`` or ``--merge`` option is not present then ``tg rebase``
1251         will complain and not do anything.
1253         When ``git rerere`` is enabled, previously resolved conflicts are
1254         remembered and can be automatically staged (see ``rerere.autoUpdate``).
1256         However, even with auto staging, ``git rebase`` still stops and
1257         requires an explicit ``git rebase --continue`` to keep going.
1259         In the case where ``git rebase -m`` is being used to flatten history
1260         (such as after a ``tg export --collapse`` prior to a
1261         ``git format-patch``), there's a good chance all conflicts have already
1262         been resolved during normal merge maintenance operations so there's no
1263         reason ``git rebase`` could not automatically continue, but there's no
1264         option to make it do so.
1266         The ``tg rebase`` command provides a ``git rebase --auto-continue``
1267         function.
1269         All the same rebase options can be used (they are simply passed through
1270         to Git unchanged).  However, the ``rerere.autoUpdate`` option is
1271         automatically temporarily enabled while running ``git rebase`` and
1272         should ``git rebase`` stop asking one to resolve and continue, but all
1273         conflicts have already been resolved and staged using rerere
1274         information, then ``git rebase --continue`` will be automatically run.
1276 tg revert
1277 ~~~~~~~~~
1278         Provides the ability to revert one or more TopGit branches and their
1279         dependencies to a previous state contained within a tag created using
1280         the ``tg tag`` command.  In addition to the actual revert mode
1281         operation a list mode operation is also provided to examine a tag's ref
1282         contents.
1284         The default mode (``-l`` or ``--list``) shows the state of one or more
1285         of the refs/branches stored in the tag data.  When no refs are given on
1286         the command line, all refs in the tag data are shown.  With the special
1287         ref name ``--heads`` then the indepedent heads contained in the tag
1288         data are shown.  The ``--deps`` option shows the specified refs and all
1289         of their dependencies in a single list with no duplicates.  The
1290         ``--rdeps`` option shows a display similar to ``tg summary --rdeps``
1291         for each ref or all independent heads if no ref is given on the command
1292         line.  The standard ``--no-short``, ``--short=n`` etc. options may be
1293         used to override the default ``--short`` output.  With ``--hash`` (or
1294         ``--hash-only``) show only the hash in ``--list`` mode in which case
1295         the default is ``--no-short``.   The ``--hash`` option can be used much
1296         like the ``git rev-parse --verify`` command to extract a specific hash
1297         value out of a TopGit tag.
1299         The revert mode has three submodes, dry-run mode (``-n`` or
1300         ``--dry-run``), force mode (``-f`` or ``--force``) and interactive mode
1301         (``-i`` or ``--interactive``).  If ``--dry-run`` (or ``-n``) is given
1302         no ref updates will actually be performed but what would have been
1303         updated is shown instead.  If ``--interactive`` (or ``-i``) is given
1304         then the editor is invoked on an instruction sheet allowing manual
1305         selection of the refs to be updated before proceeding.  Since revert is
1306         potentially a destructive operation, at least one of the submodes must
1307         be specified explicitly.  If no refs are listed on the command line
1308         then all refs in the tag data are reverted.  Otherwise the listed refs
1309         and all of their dependencies (unless ``--no-deps`` is given) are
1310         reverted.  Unless ``--no-stash`` is given a new stash will be created
1311         using ``tg tag --stash`` (except, of course, in dry-run mode) just
1312         before actually performing the updates to facilitate recovery from
1313         accidents.
1315         Both modes accept fully-qualified (i.e. starts with ``refs/``) ref
1316         names as well as unqualified names (which will be assumed to be located
1317         under ``refs/heads/``).  In revert mode a tgish ref will always have
1318         both its ``refs/heads/`` and ``refs/top-bases/`` values included no
1319         matter how it's listed unless ``--no-deps`` is given and the ref is
1320         fully qualified (i.e. starts with ``refs/``) or one or the other of its
1321         values was removed from the instruction sheet in interactive mode.  In
1322         list mode a tgish ref will always have both its ``refs/heads/`` and
1323         ``refs/top-bases/`` values included only when using the ``--deps`` or
1324         ``--rdeps`` options.
1326         The ``--tgish-only`` option excludes non-tgish refs (i.e. refs that do
1327         not have a ``refs/heads/<name>``, ``refs/top-bases/<name>`` pair).
1329         The ``--exclude`` option (which can be repeated) excludes specific
1330         refs.  If the name given to ``--exclude`` is not fully-qualified (i.e.
1331         starts with ``refs/``) then it will exclude both members of a tgish ref
1332         pair.
1334         The ``--quiet`` (or ``-q``) option may be used in revert mode to
1335         suppress non-dry-run ref change status messages.
1337         The special tag name ``--stash`` (as well as with ``@{n}`` suffixes)
1338         can be used to refer to ``refs/tgstash``.
1340         The ``tg revert`` command supports tags of tags that contains TopGit
1341         refs.  So, for example, if you do this::
1343                 tg tag newtag --all
1344                 git tag -f -a -m "tag the tag" newtag newtag
1346         Then ``newtag`` will be a tag of a tag containing a ``TOPGIT REFS``
1347         section.  ``tg revert`` knows how to dereference the outermost
1348         tag to get to the next (and the next etc.) tag to find the
1349         ``TOPGIT REFS`` section so after the above sequence, the tag ``newtag``
1350         can still be used successfully with ``tg revert``.
1352         NOTE:  If HEAD points to a ref that is updated by a revert operation
1353         then NO WARNING whatsoever will be issued, but the index and working
1354         tree will always be left completely untouched (and the reflog for
1355         the pointed-to ref can always be used to find the previous value).
1357 tg prev
1358 ~~~~~~~
1359         Outputs the direct dependencies for the current or named branch.
1361         Options:
1362           -i            show dependencies based on index instead of branch
1363           -w            show dependencies based on working tree instead of branch
1365 tg next
1366 ~~~~~~~
1367         Outputs all branches which directly depend on the current or
1368         named branch.
1370         Options:
1371           -i            show dependencies based on index instead of branch
1372           -w            show dependencies based on working tree instead of branch
1374 tg migrate-bases
1375 ~~~~~~~~~~~~~~~~
1376         Transition top-bases from old location to new location.
1378         Beginning with TopGit release 0.19.4, TopGit has the ability to store
1379         the top-bases refs in either the old ``ref/top-bases/...`` location or
1380         the new ``refs/heads/{top-bases}/...`` location.  Starting with TopGit
1381         release 0.20.0, the default is the new location.
1383         By storing the top-bases under heads, Git is less likely to complain
1384         when manipulating them, hosting providers are more likely to provide
1385         access to them and Git prevents them from pointing at anything other
1386         than a commit object.  All in all a win for everyone.
1388         TopGit attempts to automatically detect whether the new or old location
1389         is being used for the top-bases and just do the right thing.  However,
1390         by explicitly setting the config value ``topgit.top-bases`` to either
1391         ``refs`` for the old location or ``heads`` for the new location the
1392         auto-detection can be bypassed.  If no top-bases refs are present in
1393         the repository the default prior to TopGit release 0.20.0 is to use the
1394         old location but starting with TopGit release 0.20.0 the default is to
1395         use the new location.
1397         The ``tg migrate-bases`` command may be used to migrate top-bases refs
1398         from the old location to the new location (or, by using the
1399         undocumented ``--reverse`` option, vice versa).
1401         With few exceptions (``tg create -r`` and ``tg revert``), all top-bases
1402         refs (both local *and* remote refs) are expected to be stored in the
1403         same location (either new or old).  A repository's current location for
1404         storing top-bases refs may be shown with the ``tg --top-bases`` command.
1406 TODO: tg rename
1407 ~~~~~~~~~~~~~~~
1409 IMPLEMENTATION
1410 --------------
1412 TopGit stores all the topic branches in the regular ``refs/heads/``
1413 namespace (so we recommend distinguishing them with the ``t/`` prefix).
1414 Apart from that, TopGit also maintains a set of auxiliary refs in
1415 ``refs/top-*``.  Currently, only ``refs/top-bases/`` is used, containing the
1416 current *base* of the given topic branch -- this is basically a merge of
1417 all the branches the topic branch depends on; it is updated during ``tg
1418 update`` and then merged to the topic branch, and it is the base of a
1419 patch generated from the topic branch by ``tg patch``.
1421 All the metadata is tracked within the source tree and history of the
1422 topic branch itself, in ``.top*`` files; these files are kept isolated
1423 within the topic branches during TopGit-controlled merges and are of
1424 course omitted during ``tg patch``.  The state of these files in base
1425 commits is undefined; look at them only in the topic branches
1426 themselves.  Currently, two files are defined:
1428         ``.topmsg``:
1429             Contains the description of the topic branch in a
1430             mail-like format, plus the author information, whatever
1431             Cc headers you choose or the post-three-dashes message.
1432             When mailing out your patch, basically only a few extra
1433             mail headers are inserted and then the patch itself is
1434             appended.  Thus, as your patches evolve, you can record
1435             nuances like whether the particular patch should have
1436             To-list / Cc-maintainer or vice-versa and similar
1437             nuances, if your project is into that.  ``From`` is
1438             prefilled from your current ``GIT_AUTHOR_IDENT``; other
1439             headers can be prefilled from various optional
1440             ``topgit.*`` git config options.
1442         ``.topdeps``:
1443             Contains the one-per-line list of branches this branch
1444             depends on, pre-seeded by ``tg create``. A (continuously
1445             updated) merge of these branches will be the *base* of
1446             your topic branch.
1448 IMPORTANT: DO NOT EDIT ``.topdeps`` MANUALLY!!! If you do so, you need to
1449 know exactly what you are doing, since this file must stay in sync with
1450 the Git history information, otherwise very bad things will happen.
1452 TopGit also automagically installs a bunch of custom commit-related
1453 hooks that will verify whether you are committing the ``.top*`` files in a
1454 sane state. It will add the hooks to separate files within the ``hooks/``
1455 subdirectory, and merely insert calls to them to the appropriate hooks
1456 and make them executable (but will make sure the original hook's code is
1457 not called if the hook was not executable beforehand).
1459 Another automagically installed piece is a ``.git/info/attributes``
1460 specifier for an ``ours`` merge strategy for the files ``.topmsg`` and
1461 ``.topdeps``, and the (intuitive) ``ours`` merge strategy definition in
1462 ``.git/config``.
1465 REMOTE HANDLING
1466 ---------------
1468 There are two remaining issues with accessing topic branches in remote
1469 repositories:
1471         (i) Referring to remote topic branches from your local repository
1472         (ii) Developing some of the remote topic branches locally
1474 There are two somewhat contradictory design considerations here:
1476         (a) Hacking on multiple independent TopGit remotes in a single
1477             repository
1478         (b) Having a self-contained topic system in local refs space
1480 To us, (a) does not appear to be very convincing, while (b) is quite
1481 desirable for ``git-log topic`` etc. working, and increased conceptual
1482 simplicity.
1484 Thus, we choose to instantiate all the topic branches of given remote
1485 locally; this is performed by ``tg remote --populate``. ``tg update``
1486 will also check if a branch can be updated from its corresponding remote
1487 branch.  The logic needs to be somewhat involved if we are to "do the
1488 right thing".  First, we update the base, handling the remote branch as
1489 if it was the first dependency; thus, conflict resolutions made in the
1490 remote branch will be carried over to our local base automagically.
1491 Then, the base is merged into the remote branch and the result is merged
1492 to the local branch -- again, to carry over remote conflict resolutions.
1493 In the future, this order might be adjustable on a per-update basis, in
1494 case local changes happen to be diverging more than the remote ones.
1495 (See the details in `The Update Process`_ for more in depth coverage.)
1497 All commands by default refer to the remote that ``tg remote --populate``
1498 was called on the last time (stored in the ``topgit.remote`` git
1499 configuration variable). You can manually run any command with a
1500 different base remote by passing ``-r REMOTE`` *before* the subcommand
1501 name.
1504 TECHNICAL
1505 ---------
1507 A familiarity with the terms in the GLOSSARY_ is helpful for understanding the
1508 content of this sections.  See also the IMPLEMENTATION_ section.
1510 The Update Process
1511 ~~~~~~~~~~~~~~~~~~
1513 When a branch is "updated" using the ``tg update`` command the following steps
1514 are taken:
1516         1) The branch and all of its dependencies (and theirs recursively)
1517            are checked to see which ones are *out-of-date*.  See glossary_.
1519         2) Each of the branch's direct dependencies (i.e. they are listed in
1520            the branch's ``.topdeps`` file) which is out of date is updated
1521            before proceeding (yup, this is a recursive process).
1523         3) Each of the branch's direct dependencies (i.e. they are listed in
1524            the branch's ``.topdes`` file) that was updated in the previous
1525            step is now merged into the branch's corresponding base.  If a
1526            remote is involved, and the branch's corresponding base does NOT
1527            contain the remote branch's corresponding base that remote base is
1528            also merged into the branch's base at this time as well (it will be
1529            the first item merged into the branch's base).
1531         4) If the branch has a corresponding remote branch and the branch
1532            does not already contain it, it's merged into the branch's base
1533            (which was possibly already updated in step (3) to contain the
1534            remote branch's base but not the remote branch itself) on a detached
1535            HEAD.  Yup, this step can be a bit confusing and no, the updated
1536            base from step (3) has not yet been merged into the branch itself
1537            yet either.  If there is no remote branch this step does not apply.
1538            Using a detached HEAD allows the remote branch to be merged into the
1539            contents of the base without actually perturbing the base's ref.
1541         5) If there is a remote branch present then use the result of step (4)
1542            otherwise use the branch's base and merge that into the branch
1543            itself.
1545 That's it!  Simple, right? ;)
1547 Unless the auto stash option has been disabled (see `no undo`_, `tg update`_
1548 and `tg tag`_), a copy of all the old refs values will be stashed away
1549 immediately after step (1) before starting step (2), but only if anything is
1550 actually found to be out-of-date.
1553 GLOSSARY
1554 --------
1556         .topmsg
1557                 Version-controlled file stored at the root level of each
1558                 TopGit branch that contains the patch header for a TopGit
1559                 branch.  See also IMPLEMENTATION_;
1561         .topdeps
1562                 Version-controlled file stored at the root level of each
1563                 TopGit branch that lists the branch's dependencies one per
1564                 line omitting the leading ``refs/heads/`` part.  See also
1565                 IMPLEMENTATION_;
1567         branch containment
1568                 Given two Git commit identifiers (e.g. hashes) C1 and C2,
1569                 commit C1 "contains" commit C2 if either they are the same
1570                 commit or C2 can be reached from C1 by following one or more
1571                 parent links from C1 (perhaps via one or more intermediate
1572                 commits along the way).  In other words, if C1 contains C2
1573                 then C2 is an ancestor of C1 or conversely C1 is a descendant
1574                 of C2.  Since a TopGit branch name is also the name of a Git
1575                 branch (something located under the ``refs/heads`` Git
1576                 namespace) and similarly for a TopGit base, they can both be
1577                 resolved to a Git commit identifier and then participate in
1578                 a branch containment test.  An easy mnemonic for this is
1579                 "children contain the genes of their parents."
1581         contains
1582                 See branch containment.
1584         TopGit
1585                 Excellent system for managing a history of changes to one
1586                 or more possibly interrelated patches.
1588         TopGit branch
1589                 A Git branch that has an associated TopGit base.  Conceptually
1590                 it represents a single patch that is the difference between
1591                 the associated TopGit base and the TopGit branch.  In other
1592                 words ``git diff-tree <TopGit base> <TopGit branch>`` except
1593                 that any ``.topdeps`` and/or ``.topmsg`` files are excluded
1594                 from the result and the contents of the ``.topmsg`` file from
1595                 the TopGit branch is prefixed to the result.
1597         TopGit base
1598                 A Git branch that records the base upon which a TopGit branch's
1599                 single conceptual "patch" is built.  The name of the Git branch
1600                 is derived from the TopGit branch name by stripping off the
1601                 leading ``refs/heads/`` and appending the correct prefix where
1602                 all TopGit bases are stored (typically either
1603                 ``refs/top-bases/`` or ``refs/heads/{top-bases}/`` -- the
1604                 prefix for any given repository can be shown by using the
1605                 ``tg --top-bases`` command and updated using the
1606                 ``tg migrate-bases`` command).
1608                 All of a TopGit branch's dependencies are merged into the
1609                 corresponding TopGit base during a ``tg update`` of a branch.
1611         base
1612                 See TopGit base.
1614         TopGit ``[PATCH]`` branch
1615                 A TopGit branch whose subject starts with ``[PATCH]``.  By
1616                 convention these TopGit branches contain a single patch
1617                 (equivalent to a single patch file) and have at least one
1618                 dependency (i.e. their ``.topdeps`` files are never empty).
1620         TopGit ``[BASE]`` branch
1621                 A TopGit branch whose subject starts with ``[BASE]``.  By
1622                 convention these TopGit branches do not actually contain
1623                 any changes and their ``.topdeps`` files are empty.  They
1624                 are used to control a base dependency that another set of
1625                 branches depends on.
1627         TopGit ``[STAGE]`` branch
1628                 A TopGit branch whose subject starts with ``[STAGE]``.  By
1629                 convention these TopGit branches do not actually contain any
1630                 changes of their own but do have one or (typically) more
1631                 dependencies in their ``.topdeps`` file.  These branches are
1632                 used to bring together one or (typically) more independent
1633                 TopGit ``[PATCH]`` branches into a single branch so that
1634                 testing and/or evaluation can be performed on the result.
1636         out-of-date branch
1637                 A TopGit branch is considered to be "out-of-date" when ANY of
1638                 the following are true:
1640                         a) The TopGit branch does NOT contain its
1641                            corresponding base.
1643                         b) The TopGit branch does NOT contain its
1644                            corresponding remote branch (there may not be
1645                            a remote branch in which case this does not apply)
1647                         c) The TopGit branch's base does NOT contain its
1648                            corresponding remote branch's base (there may not be
1649                            a remote branch in which case this does not apply)
1651                         d) Any of the TopGit branches listed in the branch's
1652                            ``.topdeps`` file are NOT contained by the branch.
1653                            (See "branch containment" above.)
1655                         e) Any of the TopGit branches listed in the branch's
1656                            ``.topdeps`` file are out-of-date.
1658                 Note that if a remote branch is present and is NOT out-of-date
1659                 then it will contain its own base and (c) is mostly redundant.
1661         remote TopGit branch
1662                 A Git branch with the same branch name as a TopGit branch
1663                 but living under ``refs/remotes/```<some remote>```/`` instead
1664                 of just ``refs/heads/``.
1666         remote TopGit base
1667                 The TopGit base branch corresponding to a remote TopGit branch,
1668                 which lives under ``refs/remotes/`` somewhere (depending on
1669                 what the output of ``tg --top-bases`` is for that remote).
1672 REFERENCES
1673 ----------
1675 The following references are useful to understand the development of
1676 topgit and its subcommands.
1678 * tg depend:
1679   http://public-inbox.org/git/36ca99e90904091034m4d4d31dct78acb333612e678@mail.gmail.com/T/#u
1682 THIRD-PARTY SOFTWARE
1683 --------------------
1685 The following software understands TopGit branches:
1687 * `magit <http://magit.github.io/>`_ -- a git mode for emacs
1689 IMPORTANT: Magit requires its topgit mode to be enabled first, as
1690 described in its documentation, in the "Activating extensions"
1691 subsection.  If this is not done, it will not push TopGit branches
1692 correctly, so it's important to enable it even if you plan to mostly use
1693 TopGit from the command line.