test-lib-functions-tg.sh: introduce TopGit-specific test functions library
[topgit/pro.git] / README
blob10b4d3e081cbc399f792201365e8176cbc691131
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         :REQUIREMENTS_:     Installation requirements
19         :USAGE_:            Command Line details
20         :`NO UNDO`_:        Where's the undo!!!
21         :CONVENTIONS_:      Suggestions for organizing your TopGit branches
22         :`EXTRA SETTINGS`_: Various possible "topgit.*" config settings
23         :ALIASES_:          Git-like TopGit command aliases
24         :GLOSSARY_:         All the TopGit vocabulary in one place
25         :TECHNICAL_:        How it works behind the scenes
28 REQUIREMENTS
29 ------------
31 TopGit is a collection of POSIX shell scripts so a POSIX-compliant shell is
32 required along with some standard POSIX-compliant utilities (e.g. sed, awk,
33 cat, etc.).  Git version 1.8.5 or later is also required.
35 To use TopGit with linked working trees (the ``git worktree add`` command),
36 at least Git version 2.5.0 (obviously, since that's when the ``git worktree``
37 command first appeared) is needed in which case linked working trees are then
38 fully supported for use with TopGit.
40 The scripts need to be preprocessed and installed and currently the Makefile
41 that does this requires GNU make, but that's an install-time-only requirement.
43 It is possible, however, to use the DESTDIR functionality to install TopGit to
44 a staging area on one machine, archive that and then unarchive it on another
45 machine to perform an install (provided the build prefix and other options are
46 compatible with the final installed location).
49 INSTALLATION
50 ------------
52 See the file ``INSTALL``.
55 GIT REPOSITORY
56 --------------
58 The TopGit git repository can be found at <http://repo.or.cz/topgit/pro>.
61 RATIONALE
62 ---------
64 Why not use something like StGIT or Guilt or ``rebase -i`` for maintaining
65 your patch queue?  The advantage of these tools is their simplicity;
66 they work with patch *series* and defer to the reflog facility for
67 version control of patches (reordering of patches is not
68 version-controlled at all).  But there are several disadvantages -- for
69 one, these tools (especially StGIT) do not actually fit well with plain
70 Git at all: it is basically impossible to take advantage of the index
71 effectively when using StGIT.  But more importantly, these tools
72 horribly fail in the face of a distributed environment.
74 TopGit has been designed around three main tenets:
76         (i) TopGit is as thin a layer on top of Git as possible.  You
77         still maintain your index and commit using Git; TopGit will only
78         automate a few indispensable tasks.
80         (ii) TopGit is anxious about *keeping* your history.  It will
81         never rewrite your history, and all metadata is also tracked
82         by Git, smoothly and non-obnoxiously.  It is good to have a
83         *single* point when the history is cleaned up, and that is at
84         the point of inclusion in the upstream project; locally, you
85         can see how your patch has evolved and easily return to older
86         versions.
88         (iii) TopGit is specifically designed to work in a
89         distributed environment.  You can have several instances of
90         TopGit-aware repositories and smoothly keep them all
91         up-to-date and transfer your changes between them.
93 As mentioned above, the main intended use-case for TopGit is tracking
94 third-party patches, where each patch is effectively a single topic
95 branch.  In order to flexibly accommodate even complex scenarios when
96 you track many patches where many are independent but some depend on
97 others, TopGit ignores the ancient Quilt heritage of patch series and
98 instead allows the patches to freely form graphs (DAGs just like Git
99 history itself, only "one level higher").  For now, you have to manually
100 specify which patches the current one depends on, but TopGit might help
101 you with that in the future in a darcs-like fashion.
103 A glossary_ plug: The union (i.e. merge) of patch dependencies is called
104 a *base* of the patch (topic branch).
106 Of course, TopGit is perhaps not the right tool for you:
108         (i) TopGit is not complicated, but StGIT et al. are somewhat
109         simpler, conceptually.  If you just want to make a linear
110         purely-local patch queue, deferring to StGIT instead might
111         make more sense.
113         (ii) When using TopGit, your history can get a little hairy
114         over time, especially with all the merges rippling through.
115         ;-)
118 SYNOPSIS
119 --------
123         ## Create and evolve a topic branch
124         $ tg create t/gitweb/pathinfo-action
125         tg: Automatically marking dependency on master
126         tg: Creating t/gitweb/pathinfo-action base from master...
127         $ ..hack..
128         $ git commit
129         $ ..fix a mistake..
130         $ git commit
132         ## Create another topic branch on top of the former one
133         $ tg create t/gitweb/nifty-links
134         tg: Automatically marking dependency on t/gitweb/pathinfo-action
135         tg: Creating t/gitweb/nifty-links base from t/gitweb/pathinfo-action...
136         $ ..hack..
137         $ git commit
139         ## Create another topic branch on top of master and submit
140         ## the resulting patch upstream
141         $ tg create t/revlist/author-fixed master
142         tg: Creating t/revlist/author-fixed base from master...
143         $ ..hack..
144         $ git commit
145         $ tg patch -m
146         tg: Sent t/revlist/author-fixed
147         From: pasky@suse.cz
148         To: git@vger.kernel.org
149         Cc: gitster@pobox.com
150         Subject: [PATCH] Fix broken revlist --author when --fixed-string
152         ## Create another topic branch depending on two others non-trivially
153         $ tg create t/whatever t/revlist/author-fixed t/gitweb/nifty-links
154         tg: Creating t/whatever base from t/revlist/author-fixed...
155         tg: Merging t/whatever base with t/gitweb/nifty-links...
156         Merge failed!
157         tg: Please commit merge resolution and call: tg update --continue
158         tg: It is also safe to abort this operation using `git reset --hard`
159         tg: but please remember you are on the base branch now;
160         tg: you will want to switch to a different branch.
161         $ ..resolve..
162         $ git commit
163         $ tg update --continue
164         $ ..hack..
165         $ git commit
167         ## Update a single topic branch and propagate the changes to
168         ## a different one
169         $ git checkout t/gitweb/nifty-links
170         $ ..hack..
171         $ git commit
172         $ git checkout t/whatever
173         $ tg info
174         Topic Branch: t/whatever (1 commit)
175         Subject: [PATCH] Whatever patch
176         Base: 3f47ebc1
177         Depends: t/revlist/author-fixed t/gitweb/nifty-links
178         Needs update from:
179                 t/gitweb/nifty-links (1 commit)
180         $ tg update
181         tg: Updating base with t/gitweb/nifty-links changes...
182         Merge failed!
183         tg: Please commit merge resolution and call `tg update --continue`
184         tg: (use `tg status` to see more options)
185         $ ..resolve..
186         $ git commit
187         $ tg update --continue
188         tg: Updating t/whatever against new base...
189         Merge failed!
190         tg: Please commit merge resolution and call `tg update --continue`
191         tg: (use `tg status` to see more options)
192         $ ..resolve..
193         $ git commit
194         $ tg update --continue
196         ## Update a single topic branch and propagate the changes
197         ## further through the dependency chain
198         $ git checkout t/gitweb/pathinfo-action
199         $ ..hack..
200         $ git commit
201         $ git checkout t/whatever
202         $ tg info
203         Topic Branch: t/whatever (1/2 commits)
204         Subject: [PATCH] Whatever patch
205         Base: 0ab2c9b3
206         Depends: t/revlist/author-fixed t/gitweb/nifty-links
207         Needs update from:
208                 t/gitweb/pathinfo-action (<= t/gitweb/nifty-links) (1 commit)
209         $ tg update
210         tg: Recursing to t/gitweb/nifty-links...
211         [t/gitweb/nifty-links] tg: Updating base with t/gitweb/pathinfo-action changes...
212         Merge failed!
213         [t/gitweb/nifty-links] tg: Please commit merge resolution and call `tg update --continue`
214         [t/gitweb/nifty-links] tg: (use `tg status` to see more options)
215         $ ..resolve..
216         $ git commit
217         $ tg update --continue
218         [t/gitweb/nifty-links] tg: Updating t/gitweb/nifty-links against new base...
219         Merge failed!
220         [t/gitweb/nifty-links] tg: Please commit merge resolution and call `tg update --continue`
221         [t/gitweb/nifty-links] tg: (use `tg status` to see more options)
222         $ ..resolve..
223         $ git commit
224         $ tg update --continue
225         tg: Updating base with t/gitweb/nifty-links changes...
226         tg: Updating t/whatever against new base...
228         ## Clone a TopGit-controlled repository
229         $ git clone URL repo
230         $ cd repo
231         $ tg remote --populate origin
232         ...
233         $ git fetch
234         $ tg update
236         ## Add a TopGit remote to a repository and push to it
237         $ git remote add foo URL
238         $ tg remote foo
239         $ tg push -r foo
241         ## Update from a non-default TopGit remote
242         $ git fetch foo
243         $ tg -r foo summary
244         $ tg -r foo update
247 CONVENTIONS
248 -----------
250 When using TopGit there are several common conventions used when working with
251 TopGit branches.  None of them are enforced, they are only suggestions.
253 There are three typical uses for a TopGit branch:
255     1. [PATCH]
256        Normal TopGit branches that represent a single patch.  These are known
257        as "patch" TopGit branches.
258     2. [BASE]
259        Empty TopGit branches with no dependencies (an empty ``.topdeps`` file)
260        that represent a base upon which other "normal" TopGit branches depend.
261        These are known as "base" TopGit branches (not to be confused with
262        the refs/top-bases/... refs).
263     3. [STAGE]
264        Empty TopGit branches that serve as a staging area to bring together
265        several other TopGit branches into one place so they can be used/tested
266        all together.  These are known as "stage" TopGit branches.
268 An "empty" TopGit branch is one that does not have any changes of its own --
269 it may still have dependencies though ("stage" branches do, "base" branches do
270 not).  The ``tg summary`` output shows empty branches with a ``0`` in the
271 listing.  Normal "patch" branches that have not been annihilated, "base" and
272 "stage" branches fall into this category.  (Annihilated branches are normally
273 omitted from the ``tg summary`` output but can be shown if given explicitly as
274 an argument to the ``tg summary`` command.  However, the message line will be
275 incorrect since an annihilated branch has no ``.topmsg`` file of its own.)
277 A "patch" branch name typically starts with ``t/`` whereas "base" and "stage"
278 branch names often do not.
280 A "base" branch is created by using the ``--no-deps`` option of ``tg create``
281 which will automatically suggest a "[BASE]" message prefix rather than
282 "[PATCH]".  A "stage" branch is created like a normal patch branch except that
283 the only changes that will ever be made to it are typically to add/remove
284 dependencies.  Its subject prefix must be manually changed to "[STAGE]" to
285 reflect its purpose.
287 Since both "base" and "stage" branches typically only have a use for the
288 "Subject:" ilne from their ``.topmsg`` file, they are quite easily created
289 using the ``--topmsg`` option of ``tg create``.
291 Use of "stage" and "base" branches is completely optional.  However, without
292 use of a "stage" branch it will be difficult to test multiple independent
293 patches together all at once.  A "base" branch is merely a convenience that
294 provides more explicit control over when a common base for a set of patches
295 gets updated as well as providing a branch that shows in ``tg summary`` output
296 and participates in ``tg remote --populate`` setup.
298 When using the ``tg tag`` command to create tags that record the current state
299 of one or more TopGit branches, the tags are often created with a name that
300 starts with ``t/``.
302 One last thing, you have enabled ``git rerere`` haven't you?
305 NO UNDO
306 -------
308 Beware, there is no "undo" after running a ``tg update``!
310 Well, that's not entirely correct.  Since ``tg update`` never discards commits
311 an "undo" operation is technically feasible provided the old values of all the
312 refs that were affected by the ``tg update`` operation can be determined and
313 then they are simply changed back to their previous values.
315 In practice though, it can be extremely tedious and error prone looking through
316 log information to try and determine what the correct previous values were.
317 Although, since TopGit tries to make sure reflogs are enabled for top-bases
318 refs, using Git's ``@{date}`` notation on all the refs dumped out by a
319 ``tg tag --refs foo``, where "foo" is the branch that was updated whose update
320 needs to be undone, may work.
322 Alternatively, ``tg tag --stash`` can be used prior to the update and then
323 ``tg revert`` used after the update to restore the previous state.  This
324 assumes, of course, that you remember to run ``tg tag --stash`` first.
326 The ``tg update`` command understands a ``--stash`` option that tells it to
327 automatically run ``tg tag --stash`` before it starts making changes (if
328 everything is up-to-date it won't run the stash command at all).
330 The ``--stash`` option is the default nowadays when running ``tg update``,
331 add the ``--no-stash`` option to turn it off.
333 There is a preference for this.  Setting the config value ``topgit.autostash``
334 to ``false`` will implicitly add the ``--no-stash`` option to any ``tg update``
335 command unless an explicit ``--stash`` option is given.
337 If you are likely to ever want to undo a ``tg update``, setting
338 ``topgit.autostash`` to ``false`` is highly discouraged!
340 Note that the tags saved by ``tg tag --stash`` are stored in the
341 ``refs/tgstash`` ref and its reflog.  Unfortunately, while Git is happy to
342 maintain the reflog (once it's been enabled which ``tg tag`` guarantees for
343 ``refs/tgstash``), Git is unable to view an annotated/signed tag's reflog!
344 Instead Git dereferences the tag and shows the wrong thing.  Use the
345 ``tg tag -g`` command to view the ``refs/tgstash`` reflog instead.
348 EXTRA SETTINGS
349 --------------
351 TopGit supports various config settings:
353         :ALIASES_:              ``topgit.alias.*`` for Git-like command aliases
354         :SEQUESTRATION_:        ``topgit.sequester`` for sequestration control
355         :`tg migrate-bases`_:   ``topgit.top-bases`` for refs bases location
356         :`tg update`_:          ``topgit.autostash`` automatic stash control
357         :`REMOTE HANDLING`_:    ``topgit.remote`` TopGit's default remote
360 ALIASES
361 -------
363 These work exactly like Git's aliases except they are stored under
364 ``topgit.alias.*`` instead.  See the ``git help config`` output under
365 the ``alias.*`` section for details.  Do note that while alias nesting is
366 explicitly permitted, a maximum nesting depth of 10 is enforced to help
367 detect accidental aliasing loops from wedging the machine.
370 SEQUESTRATION
371 -------------
373 No, this is not a section about budget nonsense.  ;)
375 TopGit keeps its metadata in ``.topdeps`` and ``.topmsg`` files.  In an effort
376 to facilitate cherry-picking and other Git activities on the patch changes
377 themselves while ignoring the TopGit metadata, TopGit attempts to keep all
378 changes to ``.topdeps`` and ``.topmsg`` files limited to commits that do NOT
379 contain changes to any other files.
381 This is a departure from previous TopGit versions that made no such effort.
383 Primarily this affects ``tg create`` and ``tg import`` (which makes use of
384 ``tg create``) as ``tg create`` will commit the initial versions of
385 ``.topdeps`` and ``.topmsg`` for a new TopGit-controlled branch in their own
386 commit instead of mixing them in with changes to other files.
388 The ``pre-commit`` hook will also attempt to separate out any ``.topdeps`` and
389 ``.topmsg`` changes from commits that include changes to other files.
391 It is possible to defeat these checks without much effort (``pre-commit`` hooks
392 can easily be bypassed, ``tg create`` has a ``--no-commit`` option, many Git
393 commands simply do not run the ``pre-commit`` hook, etc.).
395 If you really, really, really, really want to change the default back to the
396 old behavior of previous TopGit versions where no such sequestration took
397 place, then set the ``topgit.sequester`` config variable explicitly to the
398 value ``false``.  But this is not recommended.
401 AMENDING AND REBASING AND UPDATE-REF'ING
402 ----------------------------------------
404 In a word, "don't".
406 It is okay to manually update a top-bases/... ref when a) it has no depedencies
407 (i.e. it was created with the ``tg create`` ``--no-deps`` option) and b) the
408 old top-bases/... ref value can be fast-forwarded to the new top-bases/...
409 value OR the new value contains ALL of the changes in the old value through
410 some other mechanism (perhaps they were cherry-picked or otherwise applied to
411 the new top-bases/... ref).  The same rules apply to non-TopGit-controlled
412 dependencies.
414 Ignoring this rule and proceeding anyway with a non-fast-forward update to a
415 top-bases/... ref will result in changes present in the new value being merged
416 into the branch (at ``tg update`` time) as expected (possibly with conflicts),
417 but any changes that were contained in the old version of the top-bases/... ref
418 which have been dropped (i.e. are NOT contained in the new version of the
419 top-bases/... ref) will continue to be present in the branch!  To get rid of
420 the dropped commits, one or more "revert" commits will have to be manually
421 applied to the tip of the new top-bases/... value (which will then be merged
422 into the branch at next ``tg update`` time).
424 The only time it's safe to amend, rebase, filter or otherwise rewrite commits
425 contained in a TopGit controlled branch or non-TopGit branch is when those
426 commits are NOT reachable via any other ref!
428 Furthermore, while it is safe to rewrite merge commits (provided they meet the
429 same conditions) the merge commits themselves and the branches they are merging
430 in must be preserved during the rewrite and that can be rather tricky to get
431 right so it's not recommended.
433 For example, if, while working on a TopGit-controlled branch ``foo``, a bad
434 typo is noticed, it's okay to ammend/rebase to fix that provided neither
435 ``tg update`` nor ``tg create`` has already been used to cause some other ref
436 to be able to reach the commit with the typo.
438 If an amend or rerwite is done anyway even though the commit with the typo is
439 reachable from some other ref, the typo won't really be removed.  What will
440 happen instead is that the new version without the typo will ultimately be
441 merged into the other ref(s) (at ``tg update`` time) likely causing a conflict
442 that will have to be manually resolved and the commit with the typo will
443 continue to be reachable from those other refs!
445 Instead just make a new commit to fix the typo.  The end result will end up
446 being the same but without the merge conflicts.
448 See also the discussion in the `NO UNDO`_ section.
451 SPEED AND CACHING
452 -----------------
454 TopGit needs to check many things to determine whether a TopGit branch is
455 up-to-date or not.  This can involve a LOT of git commands for a complex
456 dependency tree.  In order to speed things up, TopGit keeps a cache of results
457 in a ``tg-cache`` subdirectory in the ``.git`` directory.
459 Results are tagged with the original hash values used to get that result so
460 that items which have not been changed return their results quickly and items
461 which have been changed compute their new result and cache it for future use.
463 The ``.git/tg-cache`` directory may be removed at any time and the cache will
464 simply be recreated in an on-demand fashion as needed, at some speed penalty,
465 until it's fully rebuilt.
467 To force the cache to be fully pre-loaded, run the ``tg summary`` command
468 without any arguments.  Otherwise, normal day-to-day TopGit operations should
469 keep it more-or-less up-to-date.
471 While each TopGit command is running, it uses a temporary subdirectory also
472 located in the ``.git`` directory.  These directories are named
473 ``tg-tmp.XXXXXX`` where the ``XXXXXX`` part will be random letters and digits.
475 These temporary directories should always be removed automatically after each
476 TopGit command finishes running.  As long as you are not in a subshell as a
477 result of a TopGit command stopping and waiting for a manual merge resolution,
478 it's safe to remove any of these directories that may have somehow accidentally
479 been left behind as a result of some failure that occurred while running a
480 TopGit command (provided, of course, it's not actually being used by a TopGit
481 command currently running in another terminal window or by another user on the
482 same repository).
485 USAGE
486 -----
487 ``tg [-C <dir>] [-r <remote> | -u] [-c <name>=<val>] <subcommand> [<subcommand option/argument>...]``
489         -C <dir>        Change directory to <dir> before doing anything
490         -r <remote>     Pretend ``topgit.remote`` is set to <remote>
491         -u              Pretend ``topgit.remote`` is not set
492         -c <name=val>   Pass config option to git, may be repeated
494 The ``tg`` tool has several subcommands:
496         :`tg annihilate`_:  Mark a TopGit-controlled branch as defunct
497         :`tg base`_:        Show base commit for one or more TopGit branches
498         :`tg checkout`_:    Shortcut for git checkout with name matching
499         :`tg contains`_:    Which TopGit-controlled branch contains the commit
500         :`tg create`_:      Create a new TopGit-controlled branch
501         :`tg delete`_:      Delete a TopGit-controlled branch cleanly
502         :`tg depend`_:      Add a new dependency to a TopGit-controlled branch
503         :`tg export`_:      Export TopGit branch patches to files or a branch
504         :`tg files`_:       Show files changed by a TopGit branch
505         :`tg help`_:        Show TopGit help optionally using a browser
506         :`tg import`_:      Import commit(s) to separate TopGit branches
507         :`tg info`_:        Show status information about a TopGit branch
508         :`tg log`_:         Run git log limiting revisions to a TopGit branch
509         :`tg mail`_:        Shortcut for git send-email with ``tg patch`` output
510         :`tg migrate-bases`_: Transition top-bases to new location
511         :`tg next`_:        Show branches directly depending on a TopGit branch
512         :`tg patch`_:       Generate a patch file for a TopGit branch
513         :`tg prev`_:        Show non-annihilated TopGit dependencies for a branch
514         :`tg push`_:        Run git push on TopGit branch(es) and depedencies
515         :`tg rebase`_:      Auto continue git rebase if rerere resolves conflicts
516         :`tg remote`_:      Set up remote for fetching/pushing TopGit branches
517         :`tg revert`_:      Revert ref(s) to a state stored in a ``tg tag``
518         :`tg status`_:      Show current TopGit status (e.g. in-progress update)
519         :`tg summary`_:     Show various information about TopGit branches
520         :`tg tag`_:         Create tag that records current TopGit branch state
521         :`tg update`_:      Update TopGit branch(es) with respect to dependencies
523 tg help
524 ~~~~~~~
525         Our sophisticated integrated help facility.  Mostly duplicates
526         what is below::
528          # to list commands:
529          $ tg help
530          # to get help for a particular command:
531          $ tg help <command>
532          # to get help for a particular command in a browser window:
533          $ tg help -w <command>
534          # to get help on TopGit itself
535          $ tg help tg
536          # to get help on TopGit itself in a browser
537          $ tg help -w tg
539 tg status
540 ~~~~~~~~~
541         Our sophisticated status facility.  Similar to Git's status command
542         but shows any in-progress update that's awaiting a merge resolution
543         or any other on-going TopGit activity (such as a branch creation).
545         With a single ``--verbose`` (or ``-v``) option include a short status
546         display for any dirty (but not untracked) files.  This also causes all
547         non file status lines to be prefixed with "## ".
549         With two (or more) ``--verbose`` (or ``-v``) options, additionally
550         show full symbolic ref names and unabbreviated hash values.
552         With the ``--exit-code`` option the exit code will be non-zero if any
553         TopGit or Git operation is currently in progress or the working
554         tree is unclean.
556 tg create
557 ~~~~~~~~~
558         Create a new TopGit-controlled topic branch of the given name
559         (required argument) and switch to it.  If no dependencies are
560         specified (by extra arguments passed after the first one), the
561         current branch is assumed to be the only dependency.
563         By default ``tg create`` opens an editor on the new ``.topmsg`` file
564         and then commits the new ``.topmsg`` and ``.topdeps`` files
565         automatically with a suitable default commit message.
567         The commit message can be changed with the ``-m`` (or ``--message``) or
568         ``-F`` (or ``--file``) option.  The automatic commit can be suppressed
569         by using the ``--no-ccmmit`` option.  Running the editor on the new
570         ``.topmsg`` file can be suppressed by using ``-n`` (or ``--no-edit``)
571         (which also suppresses the automatic commit) or by providing an
572         explicit value for the new ``.topmsg`` file using the ``--topmsg`` or
573         ``--topmsg-file`` option.  In any case the ``.topmsg`` content will be
574         automatically reformated to have a ``Subject:`` header line if needed.
576         If more than one dependency is listed, the automatic commit will not
577         take place until AFTER all the listed dependencies have been merged
578         into a base commit which will require some manual merge resolutions if
579         conflicts occur during the merge operations.
581         Previous versions of TopGit behaved as though the ``--no-edit`` option
582         was always given on the command line.
584         The default behavior has been changed to promote a separation between
585         commits that modify ``.topmsg`` and/or ``.topdeps`` and commits that
586         modify other files.  This facilitates cleaner cherry picking and other
587         patch maintenance activities.
589         You should edit the patch description (contained in the ``.topmsg``
590         file) as appropriate.  It will already contain some prefilled bits.
591         You can set the ``topgit.to``, ``topgit.cc`` and ``topgit.bcc``
592         git configuration variables (see ``man git-config``) in order to
593         have ``tg create`` add these headers with the given default values
594         to ``.topmsg`` before invoking the editor.
596         The main task of ``tg create`` is to set up the topic branch base
597         from the dependencies.  This may fail due to merge conflicts if more
598         than one dependency is given.   In that case, after you commit the
599         conflict resolution, you should call ``tg update --continue`` to
600         finish merging the dependencies into the new topic branch base.
602         With the ``--no-deps`` option at most one dependency may be listed
603         which may be any valid committish (instead of just refs/heads/...) and
604         the newly created TopGit-controlled branch will have an empty
605         ``.topdeps`` file.  This may be desirable in order to create a TopGit-
606         controlled branch that has no changes of its own and serves merely to
607         mark the common dependency that all other TopGit-controlled branches
608         in some set of TopGit-controlled branches depend on.  A plain,
609         non-TopGit-controlled branch can be used for the same purpose, but the
610         advantage of a TopGit-controlled branch with no dependencies is that it
611         will be pushed with ``tg push``, it will show up in the ``tg summary``
612         and ``tg info`` output with the subject from its ``.topmsg`` file
613         thereby documenting what it's for and finally it can be set up with
614         ``tg create -r`` and/or ``tg remote --populate`` to facilitate sharing.
616         For example, ``tg create --no-deps release v2.1`` will create a TopGit-
617         controlled ``release`` branch based off the ``v2.1`` tag that can then
618         be used as a base for creation of other TopGit-controlled branches.
619         Then when the time comes to move the base for an entire set of changes
620         up to ``v2.2`` the command ``git update-ref top-bases/release v2.2^0``
621         can be used followed by ``tg update --all``.  Note that it's only safe
622         to update ``top-bases/release`` directly in this manner because a) it
623         has no depedencies since it was created with the ``--no-deps`` option
624         and b) the old ``top-bases/release`` value can be fast-forwarded to the
625         new ``top-bases/release`` value.
627         Using ``--no-deps`` it's also possible to use ``tg create`` on an
628         unborn branch (omit the dependency name or specify ``HEAD``).  The
629         unborn branch itself can be made into the new TopGit branch (rather
630         than being born empty and then having the new TopGit branch based off
631         that) by specifying ``HEAD`` as the new branch's name (which is
632         probably what you normally want to do in this case anyway so you can
633         just run ``tg create --no-deps HEAD`` to accomplish that).
635         In an alternative use case, if ``-r <branch>`` is given instead of a
636         dependency list, the topic branch is created based on the given
637         remote branch.  With just ``-r`` the remote branch name is assumed
638         to be the same as the local topic branch being created.  Since no
639         new commits are created in this mode (only two refs will be updated)
640         the editor will never be run for this use case.  Note that no other
641         options may be combined with ``-r``.
643         The ``--quiet`` (or ``-q``) option suppresses most informational
644         messages.
646 tg delete
647 ~~~~~~~~~
648         Remove a TopGit-controlled topic branch of the given name
649         (required argument). Normally, this command will remove only an
650         empty branch (base == head) without dependendents; use ``-f`` to
651         remove a non-empty branch or a branch that is depended upon by
652         another branch.
654         The ``-f`` option is also useful to force removal of a branch's
655         base, if you used ``git branch -D B`` to remove branch B, and then
656         certain TopGit commands complain, because the base of branch B
657         is still there.
659         Normally ``tg delete`` will refuse to delete the current branch.
660         However, giving ``-f`` twice (or more) will force it to do so but it
661         will first detach your HEAD.
663         IMPORTANT: Currently, this command will *NOT* remove the branch
664         from the dependency list in other branches. You need to take
665         care of this *manually*.  This is even more complicated in
666         combination with ``-f`` -- in that case, you need to manually
667         unmerge the removed branch's changes from the branches depending
668         on it.
670         See also ``tg annihilate``.
672         | TODO: ``-a`` to delete all empty branches, depfix, revert
674 tg annihilate
675 ~~~~~~~~~~~~~
676         Make a commit on the current TopGit-controlled topic branch
677         that makes it equal to its base, including the presence or
678         absence of .topmsg and .topdeps.  Annihilated branches are not
679         displayed by ``tg summary``, so they effectively get out of your
680         way.  However, the branch still exists, and ``tg push`` will
681         push it (except if given the ``-a`` option).  This way, you can
682         communicate that the branch is no longer wanted.
684         When annihilating a branch that has dependents (i.e. branches
685         that depend on it), those dependents have the dependencies of
686         the branch being annihilated added to them if they do not already
687         have them as dependencies.  Essentially the DAG is repaired to
688         skip over the annihilated branch.
690         Normally, this command will remove only an empty branch
691         (base == head, except for changes to the .top* files); use
692         ``-f`` to annihilate a non-empty branch.
694         After completing the annihilation itself, normally ``tg update``
695         is run on any modified dependents.  Use the ``--no-update`` option
696         to suppress running ``tg update``.
698 tg depend
699 ~~~~~~~~~
700         Change the dependencies of a TopGit-controlled topic branch.
701         This should have several subcommands, but only ``add`` is
702         supported right now.
704         The ``add`` subcommand takes an argument naming a topic branch to
705         be added, adds it to ``.topdeps``, performs a commit and then
706         updates your topic branch accordingly.  If you want to do other
707         things related to the dependency addition, like adjusting
708         ``.topmsg``, use the option ``--no-commit``.  Adding the
709         ``--no-update`` (or ``--no-commit``) option will suppress the
710         ``tg update`` normally performed after committing the change.
712         It is safe to run ``tg depend add`` in a dirty worktree, but the
713         normally performed ``tg update`` will be suppressed in that case
714         (even if neither ``--no-update`` nor ``--no-commit`` is given).
716         You have enabled ``git rerere`` haven't you?
718         | TODO: Subcommand for removing dependencies, obviously
720 tg files
721 ~~~~~~~~
722         List files changed by the current or specified topic branch.
724         Options:
725           -i            list files based on index instead of branch
726           -w            list files based on working tree instead of branch
728 tg info
729 ~~~~~~~
730         Show summary information about the current or specified topic
731         branch.
733         Numbers in parenthesis after a branch name such as "(11/3 commits)"
734         indicate how many commits on the branch (11) and how many of those
735         are non-merge commits (3).
737         With ``--verbose`` (or ``-v``) include a list of dependents (i.e. other
738         branches that depend on this one).  Another ``--verbose`` annotates
739         them with "[needs merge]" if the current tip of branch for which info
740         is being shown has not yet been merged into the base of the dependent.
742         Alternatively, if ``--heads`` is used then which of the independent
743         TopGit branch heads (as output by ``tg summary --topgit-heads``)
744         logically contains the specified commit (which may be any committish --
745         defaults to ``HEAD`` if not given).  Zero or more results will be
746         output.  Note that "logically" means with regard to the TopGit
747         dependency relationships as established by the ``.topdeps`` file(s).
748         It's the answer that would be given when all the TopGit branches are
749         up-to-date (even though they need not be to use this option) and the
750         ``git branch --contains`` command is run and the output then filtered
751         to only those branches that appear in ``tg summary --topgit-heads``.
752         This computation may require several seconds on complex repositories.
754         If ``--leaves`` is used then the unique list of leaves of the current
755         or specified topic branch is shown as one fully-qualified ref per line.
756         Duplicates are suppressed and a tag name will be used when appropriate.
757         A "leaf" is any dependency that is either not a TopGit branch or is
758         the base of a non-annihilated TopGit branch with no non-annihilated
759         dependencies.
761         A linearized patch series can only be automatically created for a
762         TopGit topic branch (including its recursive dependencies) when exactly
763         one line is output by ``tg info --leaves <topic-branch>``.
765 tg patch
766 ~~~~~~~~
767         Generate a patch from the current or specified topic branch.
768         This means that the diff between the topic branch base and head
769         (latest commit) is shown, appended to the description found in
770         the ``.topmsg`` file.
772         The patch is simply dumped to stdout.  In the future, ``tg patch``
773         will be able to automatically send the patches by mail or save
774         them to files. (TODO)
776         Options:
777           -i            base patch generation on index instead of branch
778           -w            base patch generation on working tree instead of branch
779           --binary      pass --binary to ``git diff-tree`` to enable generation
780                         of binary patches
781           --diff-opt    options after the branch name (and an optional ``--``)
782                         are passed directly to ``git diff-tree``
784         In order to pass a sole explicit ``-w`` through to ``git diff-tree`` it
785         must be separated from the ``tg`` options by an explicit ``--``.
786         Or it can be spelled as ``--ignore-all-space`` to distinguuish it from
787         ``tg``'s ``-w`` option.
789         If additional non-``tg`` options are passed through to
790         ``git diff-tree`` (other than ``--binary`` which is fully supported)
791         the resulting ``tg patch`` output may not be appliable.
793 tg mail
794 ~~~~~~~
795         Send a patch from the current or specified topic branch as
796         email(s).
798         Takes the patch given on the command line and emails it out.
799         Destination addresses such as To, Cc and Bcc are taken from the
800         patch header.
802         Since it actually boils down to ``git send-email``, please refer
803         to the documentation for that for details on how to setup email
804         for git.  You can pass arbitrary options to this command through
805         the ``-s`` parameter, but you must double-quote everything.  The
806         ``-r`` parameter with a msgid can be used to generate in-reply-to
807         and reference headers to an earlier mail.
809         WARNING: be careful when using this command.  It easily sends
810         out several mails.  You might want to run::
812                 git config sendemail.confirm always
814         to let ``git send-email`` ask for confirmation before sending any
815         mail.
817         Options:
818           -i            base patch generation on index instead of branch
819           -w            base patch generation on working tree instead of branch
821         | TODO: ``tg mail patchfile`` to mail an already exported patch
822         | TODO: mailing patch series
823         | TODO: specifying additional options and addresses on command line
825 tg remote
826 ~~~~~~~~~
827         Register the given remote as TopGit-controlled. This will create
828         the namespace for the remote branch bases and teach ``git fetch``
829         to operate on them. However, from TopGit 0.8 onwards you need to
830         use ``tg push``, or ``git push --mirror``, for pushing
831         TopGit-controlled branches.
833         ``tg remote`` takes an optional remote name argument, and an
834         optional ``--populate`` switch.  Use ``--populate`` for your
835         origin-style remotes: it will seed the local topic branch system
836         based on the remote topic branches.  ``--populate`` will also make
837         ``tg remote`` automatically fetch the remote, and ``tg update`` look
838         at branches of this remote for updates by default.
840         Using ``--populate`` with a remote name causes the ``topgit.remote``
841         git configuration variable to be set to the given remote name.
843 tg summary
844 ~~~~~~~~~~
845         Show overview of all TopGit-tracked topic branches and their
846         up-to-date status.  With a branch name limit output to that branch.
847         Using ``--deps-only`` or ``--rdeps`` changes the default from all
848         branches to just the current ``HEAD`` branch but using ``--all`` as
849         the branch name will show results for all branches instead of ``HEAD``.
851                 ``>``
852                         marks the current topic branch
854                 ``0``
855                         indicates that it introduces no changes of its own
857                 ``l``/``r``
858                         indicates respectively whether it is local-only
859                         or has a remote mate
861                 ``L``/``R``
862                         indicates respectively if it is ahead or out-of-date
863                         with respect to its remote mate
865                 ``D``
866                         indicates that it is out-of-date with respect to its
867                         dependencies
869                 ``!``
870                         indicates that it has missing dependencies [even if
871                         they are recursive ones]
873                 ``B``
874                         indicates that it is out-of-date with respect to
875                         its base
877                 ``*``
878                         indicates it is ahead of (and needs to be merged into)
879                         at least one of its dependents -- only computed when
880                         showing all branches or using the (possibly implied)
881                         ``--with-deps`` option.
883         This can take a longish time to accurately determine all the
884         relevant information about each branch; you can pass ``-t`` (or ``-l``
885         or ``--list``) to get just a terse list of topic branch names quickly.
887         Passing ``--heads`` shows independent topic branch names and when
888         combined with ``--rdeps`` behaves as though ``--rdeps`` were run with
889         the output of ``--heads``.
891         The ``--heads-independent`` option works just like ``--heads`` except
892         that it computes the heads using ``git merge-base --independent``
893         rather than examining the TopGit ``.topdeps`` relationships.  If the
894         TopGit branches are all up-to-date (as shown in ``tg summary``) then
895         both ``--heads`` and ``--heads-independent`` should compute the same
896         list of heads (unless some overlapping TopGit branches have been
897         manually created).  If not all the TopGit branches are up-to-date then
898         the ``--heads-independent`` results may have extra items in it, but
899         occasionally that's what's needed; usually it's the wrong answer.
900         (Note that ``--topgit-heads`` is accepted as an alias for ``--heads``
901         as well.)
903         Using ``--heads-only`` behaves as though the output of ``--heads`` was
904         passed as the list of branches along with ``--without-deps``.
906         Alternatively, you can pass ``--graphviz`` to get a dot-suitable output
907         for drawing a dependency graph between the topic branches.
909         You can also use the ``--sort`` option to sort the branches using
910         a topological sort.  This is especially useful if each
911         TopGit-tracked topic branch depends on a single parent branch,
912         since it will then print the branches in the dependency order.
913         In more complex scenarios, a text graph view would be much more
914         useful, but that has not yet been implemented.
916         The ``--deps`` option outputs dependency information between
917         branches in a machine-readable format.  Feed this to ``tsort`` to
918         get the output from --sort.
920         The ``--deps-only`` option outputs a sorted list of the unique branch
921         names given on the command line plus all of their recursive
922         dependencies (subject to ``--exclude`` of course).  When
923         ``--deps-only`` is given the default is to just display information for
924         ``HEAD``, but that can be changed by using ``--all`` as the branch
925         name.  Each branch name will appear only once in the output no matter
926         how many times it's visited while tracing the dependency graph or how
927         many branch names are given on the command line to process.
929         The ``--rdeps`` option outputs dependency information in an indented
930         text format that clearly shows all the dependencies and their
931         relationships to one another.  When ``--rdeps`` is given the default is
932         to just display information for ``HEAD``, but that can be changed by
933         using ``--all`` as the branch name or by adding the ``--heads`` option.
934         Note that ``tg summary --rdeps --heads`` can be particularly helpful in
935         seeing all the TopGit-controlled branches in the repository and their
936         relationships to one another.
938         Adding ``--with-deps`` replaces the given list of branches (which will
939         default to ``HEAD`` if none are given) with the result of running
940         ``tg summary --deps-only --tgish`` on the list of branches.  This can
941         be helpful in limiting ``tg summary`` output to only the list of given
942         branches and their dependencies when many TopGit-controlled branches
943         are present in the repository.  When it would be allowed,
944         ``--with-deps`` is now the default.  Use ``--without-deps`` to switch
945         back to the old behavior.
947         With ``--exclude branch``, branch can be excluded from the output
948         meaning it will be skipped and its name will be omitted from any
949         dependency output.  The ``--exclude`` option may be repeated to omit
950         more than one branch from the output.  Limiting the output to a single
951         branch that has been excluded will result in no output at all.
953         The ``--tgish-only`` option behaves as though any non-TopGit-controlled
954         dependencies encountered during processing had been listed after an
955         ``--exclude`` option.
957         Note that the branch name can be specified as ``HEAD`` or ``@`` as a
958         shortcut for the TopGit-controlled branch that ``HEAD`` is a
959         symbolic ref to.  The ``tg summary @`` command can be quite useful.
961         Options:
962           -i            Use TopGit metadata from the index instead of the branch
963           -w            Use TopGit metadata from the working tree instead of the branch
965 tg contains
966 ~~~~~~~~~~~
967         Search all TopGit-controlled branches (and optionally their remotes)
968         to find which TopGit-controlled branch contains the specified commit.
970         This is more than just basic branch containment as provided for by the
971         ``git branch --contains`` command.  While the shown branch name(s)
972         will, indeed, be one (or more) of those output by the
973         ``git branch --contains`` command, the result(s) will exclude any
974         TopGit-controlled branches from the result(s) that have one (or more)
975         of their TopGit dependencies (either direct or indirect) appearing in
976         the ``git branch --contains`` output.
978         Normally the result will be only the one, single TopGit-controlled
979         branch for which the specified committish appears in the ``tg log``
980         output for that branch (unless the committish lies outside the
981         TopGit-controlled portion of the DAG and ``--no-strict`` was used).
983         Unless ``--annihilated-okay`` (or ``--ann`` or ``--annihilated``) is
984         used then annihilated branches will be immediately removed from the
985         ``git branch --contains`` output before doing anything else.  This
986         means a committish that was originally located in a now-annihilated
987         branch will show up in whatever branch picked up the annihilated
988         branch's changes (if there is one).  This is usually the correct
989         answer, but occasionally it's not; hence this option.  If this option
990         is used together with ``--verbose`` then annihilated branches will
991         be shown as "[:annihilated:]".
993         In other words, if a ``tg patch`` is generated for the found branch
994         (assuming one was found and a subsequent commit in the same branch
995         didn't then revert or otherwise back out the change), then that patch
996         will include the changes introduced by the specified committish
997         (unless, of course, that committish is outside the TopGit-controlled
998         portion of the DAG and ``--no-strict`` was given).
1000         This can be very helpful when, for example, a bug is discovered and
1001         then after using ``git bisect`` (or some other tool) to find the
1002         offending commit it's time to commit the fix.  But because the
1003         TopGit merging history can be quite complicated and maybe the one
1004         doing the fix wasn't the bug's author (or the author's memory is just
1005         going), it can sometimes be rather tedious to figure out which
1006         TopGit branch the fix belongs in.  The ``tg contains`` command can
1007         quickly tell you the answer to that question.
1009         With the ``--remotes`` (or ``-r``) option a TopGit-controlled remote
1010         branch name may be reported as the result but only if there is no
1011         non-remote branch containing the committish (this can only happen
1012         if at least one of the TopGit-controlled local branches are not yet
1013         up-to-date with their remotes).
1015         With the ``--verbose`` option show which TopGit DAG head(s) (one or
1016         more of the TopGit-controlled branch names output by
1017         ``tg summary --heads``) have the result as a dependency (either direct
1018         or indirect).  Using this option will noticeably increase running time.
1020         With the default ``--strict`` option, results for which the base of the
1021         TopGit-controlled branch contains the committish will be suppressed.
1022         For example, if the committish was deep-down in the master branch
1023         history somewhere far outside of the TopGit-controlled portion of
1024         the DAG, with ``--no-strict``, whatever TopGit-controlled branch(es)
1025         first picked up history containing that committish will be shown.
1026         While this is a useful result it's usually not the desired result
1027         which is why it's not the default.
1029         To summarize, even with ``--remotes``, remote results are only shown
1030         if there are no non-remote results.  Without ``--no-strict`` (because
1031         ``--strict`` is the default) results outside the TopGit-controlled
1032         portion of the DAG are never shown and even with ``--no-strict`` they
1033         will only be shown if there are no ``--strict`` results.  Finally,
1034         the TopGit head info shown with ``--verbose`` only ever appears for
1035         local (i.e. not a remote branch) results.  Annihilated branches are
1036         never considered possible matches without ``--annihilated-okay``.
1038 tg checkout
1039 ~~~~~~~~~~~
1040         Switch to a topic branch.  You can use ``git checkout <branch>``
1041         to get the same effect, but this command helps you navigate
1042         the dependency graph, or allows you to match the topic branch
1043         name using a regular expression, so it can be more convenient.
1045         There following subcommands are available:
1047             ``tg checkout push``
1048                                 Check out a branch that directly
1049                                 depends on your current branch.
1051             ``tg checkout pop``
1052                                 Check out a branch that this branch
1053                                 directly depends on.
1055             ``tg checkout [goto] [--] <pattern>``
1056                                 Check out a topic branch that
1057                                 matches ``<pattern>``.  ``<pattern>``
1058                                 is used as a sed pattern to filter
1059                                 all the topic branches.  Both ``goto`` and
1060                                 ``--`` may be omitted provided ``<pattern>``
1061                                 is not ``push``, ``pop``, ``-a``, ``--all``,
1062                                 ``goto``, ``..``, ``--``, ``next``, ``child``,
1063                                 ``prev``, ``parent``, ``-h`` or ``--help``.
1065             ``tg checkout next``
1066                                 An alias for ``push``.
1068             ``tg checkout child``
1069                                 An alias for ``push``.
1071             ``tg checkout``
1072                                 An alias for ``push``.
1074             ``tg checkout prev``
1075                                 An alias for ``pop``.
1077             ``tg checkout parent``
1078                                 An alias for ``pop``.
1080             ``tg checkout ..``
1081                                 An alias for ``pop``.
1083         If any of the above commands can find more than one possible
1084         branch to switch to, you will be presented with the matches
1085         and asked to select one of them.
1087         If the ``--ignore-other-worktrees`` (or ``--iow``) option is given and
1088         the current Git version is at least 2.5.0 then the full
1089         ``--ignore-other-worktrees`` option will be passed along to the
1090         ``git checkout`` command when it's run (otherwise the option will be
1091         silently ignored and not passed to Git as it would cause an error).
1093         The ``--force`` (or ``-f``) option, when given, gets passed through to
1094         the ``git checkout`` command.
1096         The ``<pattern>`` of ``tg checkout goto`` is optional.  If you don't
1097         supply it, all the available topic branches are listed and you
1098         can select one of them.
1100         Normally, the ``push`` and ``pop`` commands moves one step in
1101         the dependency graph of the topic branches.  The ``-a`` option
1102         causes them (and their aliases) to move as far as possible.
1103         That is, ``tg checkout push -a`` moves to a topic branch that
1104         depends (directly or indirectly) on the current branch and
1105         that no other branch depends on.  ``tg checkout pop -a``
1106         moves to a regular branch that the current topic branch
1107         depends on (directly or indirectly).  If there is more than
1108         one possibility, you will be prompted for your selection.
1110 tg export
1111 ~~~~~~~~~
1112         Export a tidied-up history of the current topic branch and its
1113         dependencies, suitable for feeding upstream.  Each topic branch
1114         corresponds to a single commit or patch in the cleaned up
1115         history (corresponding basically exactly to ``tg patch`` output
1116         for the topic branch).
1118         The command has three possible outputs now -- either a Git branch
1119         with the collapsed history, a Git branch with a linearized
1120         history, or a quilt series in new directory.
1122         In the case where you are producing collapsed history in a new
1123         branch, you can use this collapsed structure either for
1124         providing a pull source for upstream, or for further
1125         linearization e.g. for creation of a quilt series using git log::
1127                 git log --pretty=email -p --topo-order origin..exported
1129         To better understand the function of ``tg export``, consider this
1130         dependency structure::
1132          origin/master - t/foo/blue - t/foo/red - master
1133                       `- t/bar/good <,----------'
1134                       `- t/baz      ------------'
1136         (where each of the branches may have a hefty history). Then::
1138          master$ tg export for-linus
1140         will create this commit structure on the branch ``for-linus``::
1142          origin/master - t/foo/blue -. merge - t/foo/red -.. merge - master
1143                       `- t/bar/good <,-------------------'/
1144                       `- t/baz      ---------------------'
1146         In this mode, ``tg export`` works on the current topic branch, and
1147         can be called either without an option (in that case,
1148         ``--collapse`` is assumed), or with the ``--collapse`` option, and
1149         with one mandatory argument: the name of the branch where the
1150         exported result will be stored.
1152         When using the linearize mode::
1154          master$ tg export --linearize for-linus
1156         you get a linear history respecting the dependencies of your
1157         patches in a new branch ``for-linus``.  The result should be more
1158         or less the same as using quilt mode and then reimporting it
1159         into a Git branch.  (More or less because the topological order
1160         can usually be extended in more than one way into a total order,
1161         and the two methods may choose different ones.)  The result
1162         might be more appropriate for merging upstream, as it contains
1163         fewer merges.
1165         Note that you might get conflicts during linearization because
1166         the patches are reordered to get a linear history.  If linearization
1167         would produce conflicts then using ``--quilt`` will also likely result
1168         in conflicts when the exported quilt series is applied.  Since the
1169         ``--quilt`` mode simply runs a series of ``tg patch`` commands to
1170         generate the patches in the exported quilt series and those patches
1171         will end up being applied linearly, the same conflicts that would be
1172         produced by the ``--linearize`` option will then occur at that time.
1174         To avoid conflicts produced by ``--linearize`` (or by applying the
1175         ``--quilt`` output), use the default ``--collapse`` mode and then use
1176         ``tg rebase`` (or ``git rebase -m`` directly) on the collapsed branch
1177         (with a suitable <upstream>) followed by ``git format-patch`` on the
1178         rebased result to produce a conflict-free patch set.  A suitable
1179         upstream may be determined with the ``tg info --leaves`` command (if
1180         it outputs more than one line, linearization will be problematic).
1182         You have enabled ``git rerere`` haven't you?
1184         When using the quilt mode::
1186          master$ tg export --quilt for-linus
1188         would create the following directory ``for-linus``::
1190          for-linus/t/foo/blue.diff
1191          for-linus/t/foo/red.diff
1192          for-linus/t/bar/good.diff
1193          for-linus/t/baz.diff
1194          for-linus/series:
1195                 t/foo/blue.diff -p1
1196                 t/bar/good.diff -p1
1197                 t/foo/red.diff -p1
1198                 t/baz.diff -p1
1200         With ``--quilt``, you can also pass the ``-b`` parameter followed
1201         by a comma-separated explicit list of branches to export, or
1202         the ``--all`` parameter (which can be shortened to ``-a``) to
1203         export them all.  The ``--binary`` option enables producing Git
1204         binary patches.  These options are currently only supported
1205         with ``--quilt``.
1207         In ``--quilt`` mode the patches are named like the originating
1208         topgit branch.  So usually they end up in subdirectories of the
1209         output directory.  With the ``--flatten`` option the names are
1210         mangled so that they end up directly in the output dir (slashes
1211         are replaced with underscores).  With the ``--strip[=N]`` option
1212         the first ``N`` subdirectories (all if no ``N`` is given) get
1213         stripped off.  Names are always ``--strip``'d before being
1214         ``--flatten``'d.  With the option ``--numbered`` (which implies
1215         ``--flatten``) the patch names get a number as prefix to allow
1216         getting the order without consulting the series file, which
1217         eases sending out the patches.
1219         | TODO: Make stripping of non-essential headers configurable
1220         | TODO: Make stripping of [PATCH] and other prefixes configurable
1221         | TODO: ``--mbox`` option to export instead as an mbox file
1222         | TODO: support ``--all`` option in other modes of operation
1223         | TODO: For quilt exporting, export the linearized history created in
1224                 a temporary branch--this would allow producing conflict-less
1225                 series
1227 tg import
1228 ~~~~~~~~~
1229         Import commits within the given revision range into TopGit,
1230         creating one topic branch per commit. The dependencies are set
1231         up to form a linear sequence starting on your current branch --
1232         or a branch specified by the ``-d`` parameter, if present.
1234         The branch names are auto-guessed from the commit messages and
1235         prefixed by ``t/`` by default; use ``-p <prefix>`` to specify an
1236         alternative prefix (even an empty one).
1238         Alternatively, you can use the ``-s NAME`` parameter to specify
1239         the name of the target branch; the command will then take one
1240         more argument describing a *single* commit to import.
1242 tg update
1243 ~~~~~~~~~
1244         Update the current, specified or all topic branches with respect
1245         to changes in the branches they depend on and remote branches.
1246         This is performed in two phases -- first, changes within the
1247         dependencies are merged to the base, then the base is merged
1248         into the topic branch.  The output will guide you on what to do
1249         next in case of conflicts.
1251         You have enabled ``git rerere`` haven't you?
1253         When ``-a`` (or ``--all``) is specifed, updates all topic branches
1254         matched by ``<pattern>``'s (see ``git-for-each-ref(1)`` for details),
1255         or all if no ``<pattern>`` is given.  Any topic branches with missing
1256         dependencies will be skipped entirely unless ``--skip-missing`` is
1257         specified.
1259         When ``--skip-missing`` is specifed, an attempt is made to update topic
1260         branches with missing dependencies by skipping only the dependencies
1261         that are missing.  Caveat utilitor.
1263         When ``--stash`` is specified (or the ``topgit.autostash`` config
1264         value is set to ``true``), a ref stash will be automatically created
1265         just before beginning updates if any are needed.  The ``--no-stash``
1266         option may be used to disable a ``topgit.autostash=true`` setting.
1267         See the ``tg tag`` ``--stash`` option for details.
1269         After the update, if a single topic branch was specified, it is
1270         left as the current one; if ``-a`` was specified, it returns to
1271         the branch which was current at the beginning.
1273         If your dependencies are not up-to-date, ``tg update`` will first
1274         recurse into them and update them.
1276         If a remote branch update brings in dependencies on branches
1277         that are not yet instantiated locally, you can either bring in
1278         all the new branches from the remote using ``tg remote
1279         --populate``, or only pick out the missing ones using ``tg create
1280         -r`` (``tg summary`` will point out branches with incomplete
1281         dependencies by showing an ``!`` next to them).
1283         | TODO: ``tg update -a -c`` to autoremove (clean) up-to-date branches
1285 tg push
1286 ~~~~~~~
1287         If ``-a`` or ``--all`` was specified, pushes all non-annihilated
1288         TopGit-controlled topic branches, to a remote repository.
1289         Otherwise, pushes the specified topic branches -- or the
1290         current branch, if you don't specify which.  By default, the
1291         remote gets all the dependencies (both TopGit-controlled and
1292         non-TopGit-controlled) and bases pushed to it too.  If
1293         ``--tgish-only`` was specified, only TopGit-controlled
1294         dependencies will be pushed, and if ``--no-deps`` was specified,
1295         no dependencies at all will be pushed.
1297         The ``--dry-run`` and ``--force`` options are passed directly to
1298         ``git push`` if given.
1300         The remote may be specified with the ``-r`` option. If no remote
1301         was specified, the configured default TopGit remote will be
1302         used.
1304 tg base
1305 ~~~~~~~
1306         Prints the base commit of each of the named topic branches, or
1307         the current branch if no branches are named.  Prints an error
1308         message and exits with exit code 1 if the named branch is not
1309         a TopGit branch.
1311 tg log
1312 ~~~~~~
1313         Prints the git log of the named topgit branch -- or the current
1314         branch, if you don't specify a name.
1316         This is really just a convenient shortcut for:
1318             ``git log --first-parent --no-merges $(tg base <name>)..<name>``
1320         where ``<name>`` is the name of the TopGit topic branch (or omitted
1321         for the current branch).
1323         NOTE: if you have merged changes from a different repository, this
1324         command might not list all interesting commits.
1326 tg tag
1327 ~~~~~~
1328         Creates a TopGit annotated/signed tag or lists the reflog of one.
1330         A TopGit annotated tag records the current state of one or more TopGit
1331         branches and their dependencies and may be used to revert to the tagged
1332         state at any point in the future.
1334         When reflogs are enabled (the default in a non-bare repository) and
1335         combined with the ``--force`` option a single tag name may be used as a
1336         sort of TopGit branch state stash.  The special branch name ``--all``
1337         may be used to tag the state of all current TopGit branches to
1338         facilitate this function and has the side-effect of suppressing the
1339         out-of-date check allowing out-of-date branches to be included.
1341         As a special feature, ``--stash`` may be used as the tag name in which
1342         case ``--all`` is implied if no branch name is listed (instead of the
1343         normal default of ``HEAD``), ``--force`` and ``--no-edit`` (use
1344         ``--edit`` to change that) are automatically activated and the tag will
1345         be saved to ``refs/tgstash`` instead of ``refs/tags/<tagname>``.
1346         The ``--stash`` tag name may also be used with the ``-g``/``--reflog``
1347         option.
1349         The mostly undocumented option ``--allow-outdated`` will bypass the
1350         out-of-date check and is implied when ``--stash`` or ``--all`` is used.
1352         A TopGit annotated/signed tag is simply a Git annotated/signed tag with
1353         a "TOPGIT REFS" section appended to the end of the tag message (and
1354         preceding the signature for signed tags).  PEM-style begin and end
1355         lines surround one line per ref where the format of each line is
1356         full-hash SP ref-name.  A line will be included for each branch given
1357         on the command line and each ref they depend on either directly or
1358         indirectly.
1360         If more than one TopGit branch is given on the command line, a new
1361         commit will be created that has an empty tree and all of the given
1362         TopGit branches as parents and that commit will be tagged.  If a single
1363         TopGit branch is given, then it will be tagged.  If the ``--tree``
1364         option is used then it will be used instead of an empty tree (a new
1365         commit will be created if necessary to guarantee the specified tree is
1366         what's in the commit the newly created tag refers to).  The argument to
1367         the ``--tree`` option may be any valid treeish.
1369         All the options for creating a tag serve the same purpose as their Git
1370         equivalents except for two.  The ``--refs`` option suppresses tag
1371         creation entirely and emits the "TOPGIT REFS" section that would have
1372         been included with the tag.  If the ``--no-edit`` option is given and
1373         no message is supplied (via the ``-m`` or ``-F`` option) then the
1374         default message created by TopGit will be used without running the
1375         editor.
1377         With ``-g`` or ``--reflog`` show the reflog for a tag.  With the
1378         ``--reflog-message`` option the message from the reflog is shown.
1379         With the ``--commit-message`` option the first line of the tag's
1380         message (if the object is a tag) or the commit message (if the object
1381         is a commit) falling back to the reflog message for tree and blob
1382         objects is shown.  The default is ``--reflog-message`` unless the
1383         ``--stash`` (``refs/tgstash``) is being shown in which case the default
1384         is then ``--commit-message``.  Just add either option explicitly to
1385         override the default.
1387         When showing reflogs, non-tag entries are annotated with their type
1388         unless ``--no-type`` is given.
1390         TopGit tags are created with a reflog if core.logallrefupdates is
1391         enabled (the default for non-bare repositories).  Unfortunately Git
1392         is incapable of showing an annotated/signed tag's reflog
1393         (using git log -g) as it will first resolve the tag before checking to
1394         see if it has a reflog.  Git can, however, show reflogs for lightweight
1395         tags (using git log -g) just fine but that's not helpful here.  Use
1396         ``tg tag`` with the ``-g`` or ``--reflog`` option to see the reflog for
1397         an actual tag object.  This also works on non-TopGit annotated/signed
1398         tags as well provided they have a reflog.
1400         The number of entries shown may be limited with the ``-n`` option.  If
1401         the tagname is omitted then ``--stash`` is assumed.
1403         The ``--delete`` option is a convenience option that runs the
1404         ``git update-ref -d`` command on the specified tag removing it and its
1405         reflog (if it has one).
1407         The ``--clear`` option clears all but the most recent (the ``@{0}``)
1408         reflog entries from the reflog for the specified tag.  It's equivalent
1409         to dropping all the higher numbered reflog entries.
1411         The ``--drop`` option drops the specified reflog entry and requires the
1412         given tagname to have an ``@{n}`` suffix where ``n`` is the reflog
1413         entry number to be dropped.   This is really just a convenience option
1414         that runs the appropriate ``git reflog delete`` command.
1416         Note that when combined with ``tg revert``, a tag created by ``tg tag``
1417         can be used to transfer TopGit branches.  Simply create the tag, push
1418         it somewhere and then have the recipient run ``tg revert`` to recreate
1419         the TopGit branches.  This may be helpful in situations where it's not
1420         feasible to push all the refs corresponding to the TopGit-controlled
1421         branches and their top-bases.
1423 tg rebase
1424 ~~~~~~~~~
1425         Provides a ``git rebase`` rerere auto continue function.  It may be
1426         used as a drop-in replacement front-end for ``git rebase -m`` that
1427         automatically continues the rebase when ``git rerere`` information is
1428         sufficient to resolve all conflicts.
1430         You have enabled ``git rerere`` haven't you?
1432         If the ``-m`` or ``--merge`` option is not present then ``tg rebase``
1433         will complain and not do anything.
1435         When ``git rerere`` is enabled, previously resolved conflicts are
1436         remembered and can be automatically staged (see ``rerere.autoUpdate``).
1438         However, even with auto staging, ``git rebase`` still stops and
1439         requires an explicit ``git rebase --continue`` to keep going.
1441         In the case where ``git rebase -m`` is being used to flatten history
1442         (such as after a ``tg export --collapse`` prior to a
1443         ``git format-patch``), there's a good chance all conflicts have already
1444         been resolved during normal merge maintenance operations so there's no
1445         reason ``git rebase`` could not automatically continue, but there's no
1446         option to make it do so.
1448         The ``tg rebase`` command provides a ``git rebase --auto-continue``
1449         function.
1451         All the same rebase options can be used (they are simply passed through
1452         to Git unchanged).  However, the ``rerere.autoUpdate`` option is
1453         automatically temporarily enabled while running ``git rebase`` and
1454         should ``git rebase`` stop asking one to resolve and continue, but all
1455         conflicts have already been resolved and staged using rerere
1456         information, then ``git rebase --continue`` will be automatically run.
1458 tg revert
1459 ~~~~~~~~~
1460         Provides the ability to revert one or more TopGit branches and their
1461         dependencies to a previous state contained within a tag created using
1462         the ``tg tag`` command.  In addition to the actual revert mode
1463         operation a list mode operation is also provided to examine a tag's ref
1464         contents.
1466         The default mode (``-l`` or ``--list``) shows the state of one or more
1467         of the refs/branches stored in the tag data.  When no refs are given on
1468         the command line, all refs in the tag data are shown.  With the special
1469         ref name ``--heads`` then the indepedent heads contained in the tag
1470         data are shown.  The ``--deps`` option shows the specified refs and all
1471         of their dependencies in a single list with no duplicates.  The
1472         ``--rdeps`` option shows a display similar to ``tg summary --rdeps``
1473         for each ref or all TopGit heads if no ref is given on the command
1474         line.  The standard ``--no-short``, ``--short=n`` etc. options may be
1475         used to override the default ``--short`` output.  With ``--hash`` (or
1476         ``--hash-only``) show only the hash in ``--list`` mode in which case
1477         the default is ``--no-short``.   The ``--hash`` option can be used much
1478         like the ``git rev-parse --verify`` command to extract a specific hash
1479         value out of a TopGit tag.
1481         Note that unlike `tg summary`_, here ``--heads`` actually does mean the
1482         ``git merge-base --independent`` heads of the stored refs from the tag
1483         data.  To see only the independent TopGit topic branch heads stored in
1484         the tag data use the ``--topgit-heads`` option instead.  The default
1485         for the ``--rdeps`` option is ``--topgit-heads`` but ``--heads`` can
1486         be given explicitly to change that.  (Note that ``--heads-independent``
1487         is accepted as an alias for ``--heads`` as well.)
1489         The revert mode has three submodes, dry-run mode (``-n`` or
1490         ``--dry-run``), force mode (``-f`` or ``--force``) and interactive mode
1491         (``-i`` or ``--interactive``).  If ``--dry-run`` (or ``-n``) is given
1492         no ref updates will actually be performed but what would have been
1493         updated is shown instead.  If ``--interactive`` (or ``-i``) is given
1494         then the editor is invoked on an instruction sheet allowing manual
1495         selection of the refs to be updated before proceeding.  Since revert is
1496         potentially a destructive operation, at least one of the submodes must
1497         be specified explicitly.  If no refs are listed on the command line
1498         then all refs in the tag data are reverted.  Otherwise the listed refs
1499         and all of their dependencies (unless ``--no-deps`` is given) are
1500         reverted.  Unless ``--no-stash`` is given a new stash will be created
1501         using ``tg tag --stash`` (except, of course, in dry-run mode) just
1502         before actually performing the updates to facilitate recovery from
1503         accidents.
1505         Both modes accept fully-qualified (i.e. starts with ``refs/``) ref
1506         names as well as unqualified names (which will be assumed to be located
1507         under ``refs/heads/``).  In revert mode a tgish ref will always have
1508         both its ``refs/heads/`` and ``refs/top-bases/`` values included no
1509         matter how it's listed unless ``--no-deps`` is given and the ref is
1510         fully qualified (i.e. starts with ``refs/``) or one or the other of its
1511         values was removed from the instruction sheet in interactive mode.  In
1512         list mode a tgish ref will always have both its ``refs/heads/`` and
1513         ``refs/top-bases/`` values included only when using the ``--deps`` or
1514         ``--rdeps`` options.
1516         The ``--tgish-only`` option excludes non-tgish refs (i.e. refs that do
1517         not have a ``refs/heads/<name>``, ``refs/top-bases/<name>`` pair).
1519         The ``--exclude`` option (which can be repeated) excludes specific
1520         refs.  If the name given to ``--exclude`` is not fully-qualified (i.e.
1521         starts with ``refs/``) then it will exclude both members of a tgish ref
1522         pair.
1524         The ``--quiet`` (or ``-q``) option may be used in revert mode to
1525         suppress non-dry-run ref change status messages.
1527         The special tag name ``--stash`` (as well as with ``@{n}`` suffixes)
1528         can be used to refer to ``refs/tgstash``.
1530         The ``tg revert`` command supports tags of tags that contains TopGit
1531         refs.  So, for example, if you do this::
1533                 tg tag newtag --all
1534                 git tag -f -a -m "tag the tag" newtag newtag
1536         Then ``newtag`` will be a tag of a tag containing a ``TOPGIT REFS``
1537         section.  ``tg revert`` knows how to dereference the outermost
1538         tag to get to the next (and the next etc.) tag to find the
1539         ``TOPGIT REFS`` section so after the above sequence, the tag ``newtag``
1540         can still be used successfully with ``tg revert``.
1542         NOTE:  If HEAD points to a ref that is updated by a revert operation
1543         then NO WARNING whatsoever will be issued, but the index and working
1544         tree will always be left completely untouched (and the reflog for
1545         the pointed-to ref can always be used to find the previous value).
1547 tg prev
1548 ~~~~~~~
1549         Outputs the direct dependencies for the current or named branch.
1551         Options:
1552           -i            show dependencies based on index instead of branch
1553           -w            show dependencies based on working tree instead of branch
1555 tg next
1556 ~~~~~~~
1557         Outputs all branches which directly depend on the current or
1558         named branch.
1560         Options:
1561           -i            show dependencies based on index instead of branch
1562           -w            show dependencies based on working tree instead of branch
1564 tg migrate-bases
1565 ~~~~~~~~~~~~~~~~
1566         Transition top-bases from old location to new location.
1568         Beginning with TopGit release 0.19.4, TopGit has the ability to store
1569         the top-bases refs in either the old ``ref/top-bases/...`` location or
1570         the new ``refs/heads/{top-bases}/...`` location.  Starting with TopGit
1571         release 0.20.0, the default is the new location.
1573         By storing the top-bases under heads, Git is less likely to complain
1574         when manipulating them, hosting providers are more likely to provide
1575         access to them and Git prevents them from pointing at anything other
1576         than a commit object.  All in all a win for everyone.
1578         TopGit attempts to automatically detect whether the new or old location
1579         is being used for the top-bases and just do the right thing.  However,
1580         by explicitly setting the config value ``topgit.top-bases`` to either
1581         ``refs`` for the old location or ``heads`` for the new location the
1582         auto-detection can be bypassed.  If no top-bases refs are present in
1583         the repository the default prior to TopGit release 0.20.0 is to use the
1584         old location but starting with TopGit release 0.20.0 the default is to
1585         use the new location.
1587         The ``tg migrate-bases`` command may be used to migrate top-bases refs
1588         from the old location to the new location (or, by using the
1589         undocumented ``--reverse`` option, vice versa).
1591         With few exceptions (``tg create -r`` and ``tg revert``), all top-bases
1592         refs (both local *and* remote refs) are expected to be stored in the
1593         same location (either new or old).  A repository's current location for
1594         storing top-bases refs may be shown with the ``tg --top-bases`` command.
1596 TODO: tg rename
1597 ~~~~~~~~~~~~~~~
1599 IMPLEMENTATION
1600 --------------
1602 TopGit stores all the topic branches in the regular ``refs/heads/``
1603 namespace (so we recommend distinguishing them with the ``t/`` prefix).
1604 Apart from that, TopGit also maintains a set of auxiliary refs in
1605 ``refs/top-*``.  Currently, only ``refs/top-bases/`` is used, containing the
1606 current *base* of the given topic branch -- this is basically a merge of
1607 all the branches the topic branch depends on; it is updated during ``tg
1608 update`` and then merged to the topic branch, and it is the base of a
1609 patch generated from the topic branch by ``tg patch``.
1611 All the metadata is tracked within the source tree and history of the
1612 topic branch itself, in ``.top*`` files; these files are kept isolated
1613 within the topic branches during TopGit-controlled merges and are of
1614 course omitted during ``tg patch``.  The state of these files in base
1615 commits is undefined; look at them only in the topic branches
1616 themselves.  Currently, two files are defined:
1618         ``.topmsg``:
1619             Contains the description of the topic branch in a
1620             mail-like format, plus the author information, whatever
1621             Cc headers you choose or the post-three-dashes message.
1622             When mailing out your patch, basically only a few extra
1623             mail headers are inserted and then the patch itself is
1624             appended.  Thus, as your patches evolve, you can record
1625             nuances like whether the particular patch should have
1626             To-list / Cc-maintainer or vice-versa and similar
1627             nuances, if your project is into that.  ``From`` is
1628             prefilled from your current ``GIT_AUTHOR_IDENT``; other
1629             headers can be prefilled from various optional
1630             ``topgit.*`` git config options.
1632         ``.topdeps``:
1633             Contains the one-per-line list of branches this branch
1634             depends on, pre-seeded by ``tg create``. A (continuously
1635             updated) merge of these branches will be the *base* of
1636             your topic branch.
1638 IMPORTANT: DO NOT EDIT ``.topdeps`` MANUALLY!!! If you do so, you need to
1639 know exactly what you are doing, since this file must stay in sync with
1640 the Git history information, otherwise very bad things will happen.
1642 TopGit also automagically installs a bunch of custom commit-related
1643 hooks that will verify whether you are committing the ``.top*`` files in a
1644 sane state. It will add the hooks to separate files within the ``hooks/``
1645 subdirectory, and merely insert calls to them to the appropriate hooks
1646 and make them executable (but will make sure the original hook's code is
1647 not called if the hook was not executable beforehand).
1649 Another automagically installed piece is a ``.git/info/attributes``
1650 specifier for an ``ours`` merge strategy for the files ``.topmsg`` and
1651 ``.topdeps``, and the (intuitive) ``ours`` merge strategy definition in
1652 ``.git/config``.
1655 REMOTE HANDLING
1656 ---------------
1658 There are two remaining issues with accessing topic branches in remote
1659 repositories:
1661         (i) Referring to remote topic branches from your local repository
1662         (ii) Developing some of the remote topic branches locally
1664 There are two somewhat contradictory design considerations here:
1666         (a) Hacking on multiple independent TopGit remotes in a single
1667             repository
1668         (b) Having a self-contained topic system in local refs space
1670 To us, (a) does not appear to be very convincing, while (b) is quite
1671 desirable for ``git-log topic`` etc. working, and increased conceptual
1672 simplicity.
1674 Thus, we choose to instantiate all the topic branches of given remote
1675 locally; this is performed by ``tg remote --populate``. ``tg update``
1676 will also check if a branch can be updated from its corresponding remote
1677 branch.  The logic needs to be somewhat involved if we are to "do the
1678 right thing".  First, we update the base, handling the remote branch as
1679 if it was the first dependency; thus, conflict resolutions made in the
1680 remote branch will be carried over to our local base automagically.
1681 Then, the base is merged into the remote branch and the result is merged
1682 to the local branch -- again, to carry over remote conflict resolutions.
1683 In the future, this order might be adjustable on a per-update basis, in
1684 case local changes happen to be diverging more than the remote ones.
1685 (See the details in `The Update Process`_ for more in depth coverage.)
1687 All commands by default refer to the remote that ``tg remote --populate``
1688 was called on the last time (stored in the ``topgit.remote`` git
1689 configuration variable). You can manually run any command with a
1690 different base remote by passing ``-r REMOTE`` *before* the subcommand
1691 name or passing ``-u`` *before* the subcommand to run without one.
1694 TECHNICAL
1695 ---------
1697 A familiarity with the terms in the GLOSSARY_ is helpful for understanding the
1698 content of this sections.  See also the IMPLEMENTATION_ section.
1700 The Update Process
1701 ~~~~~~~~~~~~~~~~~~
1703 When a branch is "updated" using the ``tg update`` command the following steps
1704 are taken:
1706         1) The branch and all of its dependencies (and theirs recursively)
1707            are checked to see which ones are *out-of-date*.  See glossary_.
1709         2) Each of the branch's direct dependencies (i.e. they are listed in
1710            the branch's ``.topdeps`` file) which is out of date is updated
1711            before proceeding (yup, this is a recursive process).
1713         3) Each of the branch's direct dependencies (i.e. they are listed in
1714            the branch's ``.topdes`` file) that was updated in the previous
1715            step is now merged into the branch's corresponding base.  If a
1716            remote is involved, and the branch's corresponding base does NOT
1717            contain the remote branch's corresponding base that remote base is
1718            also merged into the branch's base at this time as well (it will be
1719            the first item merged into the branch's base).
1721         4) If the branch has a corresponding remote branch and the branch
1722            does not already contain it, it's merged into the branch's base
1723            (which was possibly already updated in step (3) to contain the
1724            remote branch's base but not the remote branch itself) on a detached
1725            HEAD.  Yup, this step can be a bit confusing and no, the updated
1726            base from step (3) has not yet been merged into the branch itself
1727            yet either.  If there is no remote branch this step does not apply.
1728            Using a detached HEAD allows the remote branch to be merged into the
1729            contents of the base without actually perturbing the base's ref.
1731         5) If there is a remote branch present then use the result of step (4)
1732            otherwise use the branch's base and merge that into the branch
1733            itself.
1735 That's it!  Simple, right? ;)
1737 Unless the auto stash option has been disabled (see `no undo`_, `tg update`_
1738 and `tg tag`_), a copy of all the old refs values will be stashed away
1739 immediately after step (1) before starting step (2), but only if anything is
1740 actually found to be out-of-date.
1742 Merge Strategies
1743 ~~~~~~~~~~~~~~~~
1745 The ``tg update`` command regularly performs merges while executing an update
1746 operation.  In order to speed things up, it attempts to do in-index merges
1747 where possible.  It accomplishes this by using a separate, temporary index
1748 file and the ``git read-tree -m --aggressive`` command possibly assisted by
1749 the ``git merge-index`` and ``git merge-file`` commands.  This combination may
1750 be repeated more than once to perform an octopus in-index merge.  If this
1751 fails, the files are checked out and a normal ``git merge`` three-way merge is
1752 performed (possily multiple times).  If the normal ``git merge`` fails then
1753 user intervention is required to resolve the merge conflict(s) and continue.
1755 Since the ``tg annihilate``, ``tg create`` and ``tg depend add`` commands may
1756 end up running the ``tg update`` machinery behind the scenes to complete their
1757 operation they may also result in any of these merge strategies being used.
1759 In addition to the normal Git merge strategies (if the in-index merging fails),
1760 there are four possible TopGit merge strategies that may be shown.  Since they
1761 all involve use of the ``git read-tree -m --aggressive`` command they are all
1762 variations of a "trivial aggressive" merge.  The "trivial" part because all of
1763 the merges done by ``git read-tree -m`` are described as "trivial" and the
1764 "aggressive" part because the ``--aggressive`` option is always used.
1766         1) "trivial aggressive"
1767                 Only two heads were involved and all merging was completed by
1768                 the ``git read-tree -m --aggressive`` command.
1770         2) "trivial aggressive automatic"
1771                 Only two heads were involved but after the
1772                 ``git read-tree -m --aggressive`` command completed there were
1773                 still unresolved items and ``git merge-index`` had to be run
1774                 (using the ``tg index-merge-one-file`` driver) which ultimately
1775                 ran ``git merge-file`` at least once to perform a simple
1776                 automatic three-way merge.  Hence the "automatic" description
1777                 and the "Auto-merging ..." output line(s).
1779         3) "trivial aggressive octopus"
1780                 This is the same as a "trivial aggressive" merge except that
1781                 more than two heads were involved and after merging the first
1782                 two heads, the ``git read-tree -m --aggressive`` step was
1783                 repeated again on the result for each additional head.  All
1784                 merging was completed via multiple
1785                 ``git read-tree -m --aggressive`` commands only.
1786                 This beast is relatively rare in the wild.
1788         4) "trivial aggressive automatic octopus"
1789                 This is very similar to the "trivial aggressive octopus"
1790                 except that at least one of the ``git read-tree -m --aggressive``
1791                 commands left unresolved items that were handled the same way
1792                 as the "trivial aggressive automatic" strategy.  This species
1793                 is commonly seen in the wild.
1796 GLOSSARY
1797 --------
1799         .topmsg
1800                 Version-controlled file stored at the root level of each
1801                 TopGit branch that contains the patch header for a TopGit
1802                 branch.  See also IMPLEMENTATION_;
1804         .topdeps
1805                 Version-controlled file stored at the root level of each
1806                 TopGit branch that lists the branch's dependencies one per
1807                 line omitting the leading ``refs/heads/`` part.  See also
1808                 IMPLEMENTATION_;
1810         branch containment
1811                 Given two Git commit identifiers (e.g. hashes) C1 and C2,
1812                 commit C1 "contains" commit C2 if either they are the same
1813                 commit or C2 can be reached from C1 by following one or more
1814                 parent links from C1 (perhaps via one or more intermediate
1815                 commits along the way).  In other words, if C1 contains C2
1816                 then C2 is an ancestor of C1 or conversely C1 is a descendant
1817                 of C2.  Since a TopGit branch name is also the name of a Git
1818                 branch (something located under the ``refs/heads`` Git
1819                 namespace) and similarly for a TopGit base, they can both be
1820                 resolved to a Git commit identifier and then participate in
1821                 a branch containment test.  An easy mnemonic for this is
1822                 "children contain the genes of their parents."
1824         contains
1825                 See branch containment.
1827         TopGit
1828                 Excellent system for managing a history of changes to one
1829                 or more possibly interrelated patches.
1831         TopGit branch
1832                 A Git branch that has an associated TopGit base.  Conceptually
1833                 it represents a single patch that is the difference between
1834                 the associated TopGit base and the TopGit branch.  In other
1835                 words ``git diff-tree <TopGit base> <TopGit branch>`` except
1836                 that any ``.topdeps`` and/or ``.topmsg`` files are excluded
1837                 from the result and the contents of the ``.topmsg`` file from
1838                 the TopGit branch is prefixed to the result.
1840         TopGit base
1841                 A Git branch that records the base upon which a TopGit branch's
1842                 single conceptual "patch" is built.  The name of the Git branch
1843                 is derived from the TopGit branch name by stripping off the
1844                 leading ``refs/heads/`` and appending the correct prefix where
1845                 all TopGit bases are stored (typically either
1846                 ``refs/top-bases/`` or ``refs/heads/{top-bases}/`` -- the
1847                 prefix for any given repository can be shown by using the
1848                 ``tg --top-bases`` command and updated using the
1849                 ``tg migrate-bases`` command).
1851                 All of a TopGit branch's dependencies are merged into the
1852                 corresponding TopGit base during a ``tg update`` of a branch.
1854         base
1855                 See TopGit base.
1857         TopGit ``[PATCH]`` branch
1858                 A TopGit branch whose subject starts with ``[PATCH]``.  By
1859                 convention these TopGit branches contain a single patch
1860                 (equivalent to a single patch file) and have at least one
1861                 dependency (i.e. their ``.topdeps`` files are never empty).
1863         TopGit ``[BASE]`` branch
1864                 A TopGit branch whose subject starts with ``[BASE]``.  By
1865                 convention these TopGit branches do not actually contain
1866                 any changes and their ``.topdeps`` files are empty.  They
1867                 are used to control a base dependency that another set of
1868                 branches depends on.
1870         TopGit ``[STAGE]`` branch
1871                 A TopGit branch whose subject starts with ``[STAGE]``.  By
1872                 convention these TopGit branches do not actually contain any
1873                 changes of their own but do have one or (typically) more
1874                 dependencies in their ``.topdeps`` file.  These branches are
1875                 used to bring together one or (typically) more independent
1876                 TopGit ``[PATCH]`` branches into a single branch so that
1877                 testing and/or evaluation can be performed on the result.
1879         merge conflict
1880                 When merging two (or more) heads that touch the same lines in
1881                 the file but in different ways the result is a merge conflict
1882                 that requires manual intervention.  If a merge conflict occurs
1883                 with more than two heads (an octopus merge) it's generally
1884                 replaced by multiple three-way merges so that by the time a
1885                 user sees a merge conflict needing manual resolution, there
1886                 will be only two heads involved.
1888         merge strategy
1889                 A Git merge strategy (see the "MERGE STRATEGIES" section of
1890                 ``git help merge``) or one of the TopGit `merge strategies`_
1891                 used to merge two or more heads.
1893         TopGit merge strategy
1894                 See the `Merge Strategies`_ section above for details but
1895                 basically these are just in-index merges done using the
1896                 ``git read-tree -m --aggressive`` command one or more times
1897                 possibily assisted by the ``git merge-index`` and the
1898                 ``git merge-file`` commands.
1900         octopus merge
1901                 A merge involving more than two heads.  Note that if there are
1902                 less than three independent heads the resulting merge that
1903                 started out as an octopus will end up not actually being an
1904                 octopus after all.
1906         out-of-date branch
1907                 A TopGit branch is considered to be "out-of-date" when ANY of
1908                 the following are true:
1910                         a) The TopGit branch does NOT contain its
1911                            corresponding base.
1913                         b) The TopGit branch does NOT contain its
1914                            corresponding remote branch (there may not be
1915                            a remote branch in which case this does not apply)
1917                         c) The TopGit branch's base does NOT contain its
1918                            corresponding remote branch's base (there may not be
1919                            a remote branch in which case this does not apply)
1921                         d) Any of the TopGit branches listed in the branch's
1922                            ``.topdeps`` file are NOT contained by the branch.
1923                            (See "branch containment" above.)
1925                         e) Any of the TopGit branches listed in the branch's
1926                            ``.topdeps`` file are out-of-date.
1928                 Note that if a remote branch is present and is NOT out-of-date
1929                 then it will contain its own base and (c) is mostly redundant.
1931         remote TopGit branch
1932                 A Git branch with the same branch name as a TopGit branch
1933                 but living under ``refs/remotes/<some remote>/`` instead
1934                 of just ``refs/heads/``.
1936         remote TopGit base
1937                 The TopGit base branch corresponding to a remote TopGit branch,
1938                 which lives under ``refs/remotes/`` somewhere (depending on
1939                 what the output of ``tg --top-bases`` is for that remote).
1941         three-way merge
1942                 A three-way merge takes a common base and two heads (call them
1943                 A and B) and creates a new file that is the common base plus
1944                 all of the changes made between the common base and head A
1945                 *AND* all of the changes made between the common base and
1946                 head B.  The technique used to accomplish this is called a
1947                 "merge strategy".
1950 REFERENCES
1951 ----------
1953 The following references are useful to understand the development of
1954 topgit and its subcommands.
1956 * tg depend:
1957   http://public-inbox.org/git/36ca99e90904091034m4d4d31dct78acb333612e678@mail.gmail.com/T/#u
1960 THIRD-PARTY SOFTWARE
1961 --------------------
1963 The following software understands TopGit branches:
1965 * `magit <http://magit.github.io/>`_ -- a git mode for emacs
1967 IMPORTANT: Magit requires its topgit mode to be enabled first, as
1968 described in its documentation, in the "Activating extensions"
1969 subsection.  If this is not done, it will not push TopGit branches
1970 correctly, so it's important to enable it even if you plan to mostly use
1971 TopGit from the command line.