tg-revert.sh: convert any top-bases in TOPGIT REFS
[topgit/pro.git] / README
blob86417c3c0a5ac5a85be1613da6320b666d3cf572
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.  See the USAGE_
15 section for command line details.
18 INSTALLATION
19 ------------
21 See the file ``INSTALL``.
24 GIT REPOSITORY
25 --------------
27 The TopGit git repository can be found at <http://repo.or.cz/topgit/pro>.
30 RATIONALE
31 ---------
33 Why not use something like StGIT or Guilt or ``rebase -i`` for maintaining
34 your patch queue?  The advantage of these tools is their simplicity;
35 they work with patch *series* and defer to the reflog facility for
36 version control of patches (reordering of patches is not
37 version-controlled at all).  But there are several disadvantages -- for
38 one, these tools (especially StGIT) do not actually fit well with plain
39 Git at all: it is basically impossible to take advantage of the index
40 effectively when using StGIT.  But more importantly, these tools
41 horribly fail in the face of a distributed environment.
43 TopGit has been designed around three main tenets:
45         (i) TopGit is as thin a layer on top of Git as possible.  You
46         still maintain your index and commit using Git; TopGit will only
47         automate a few indispensable tasks.
49         (ii) TopGit is anxious about *keeping* your history.  It will
50         never rewrite your history, and all metadata is also tracked
51         by Git, smoothly and non-obnoxiously.  It is good to have a
52         *single* point when the history is cleaned up, and that is at
53         the point of inclusion in the upstream project; locally, you
54         can see how your patch has evolved and easily return to older
55         versions.
57         (iii) TopGit is specifically designed to work in a
58         distributed environment.  You can have several instances of
59         TopGit-aware repositories and smoothly keep them all
60         up-to-date and transfer your changes between them.
62 As mentioned above, the main intended use-case for TopGit is tracking
63 third-party patches, where each patch is effectively a single topic
64 branch.  In order to flexibly accommodate even complex scenarios when
65 you track many patches where many are independent but some depend on
66 others, TopGit ignores the ancient Quilt heritage of patch series and
67 instead allows the patches to freely form graphs (DAGs just like Git
68 history itself, only "one level higher").  For now, you have to manually
69 specify which patches the current one depends on, but TopGit might help
70 you with that in the future in a darcs-like fashion.
72 A glossary plug: The union (i.e. merge) of patch dependencies is called
73 a *base* of the patch (topic branch).
75 Of course, TopGit is perhaps not the right tool for you:
77         (i) TopGit is not complicated, but StGIT et al. are somewhat
78         simpler, conceptually.  If you just want to make a linear
79         purely-local patch queue, deferring to StGIT instead might
80         make more sense.
82         (ii) When using TopGit, your history can get a little hairy
83         over time, especially with all the merges rippling through.
84         ;-)
87 SYNOPSIS
88 --------
92         ## Create and evolve a topic branch
93         $ tg create t/gitweb/pathinfo-action
94         tg: Automatically marking dependency on master
95         tg: Creating t/gitweb/pathinfo-action base from master...
96         $ ..hack..
97         $ git commit
98         $ ..fix a mistake..
99         $ git commit
101         ## Create another topic branch on top of the former one
102         $ tg create t/gitweb/nifty-links
103         tg: Automatically marking dependency on t/gitweb/pathinfo-action
104         tg: Creating t/gitweb/nifty-links base from t/gitweb/pathinfo-action...
105         $ ..hack..
106         $ git commit
108         ## Create another topic branch on top of master and submit
109         ## the resulting patch upstream
110         $ tg create t/revlist/author-fixed master
111         tg: Creating t/revlist/author-fixed base from master...
112         $ ..hack..
113         $ git commit
114         $ tg patch -m
115         tg: Sent t/revlist/author-fixed
116         From: pasky@suse.cz
117         To: git@vger.kernel.org
118         Cc: gitster@pobox.com
119         Subject: [PATCH] Fix broken revlist --author when --fixed-string
121         ## Create another topic branch depending on two others non-trivially
122         $ tg create t/whatever t/revlist/author-fixed t/gitweb/nifty-links
123         tg: Creating t/whatever base from t/revlist/author-fixed...
124         tg: Merging t/whatever base with t/gitweb/nifty-links...
125         Merge failed!
126         tg: Please commit merge resolution and call: tg create
127         tg: It is also safe to abort this operation using `git reset --hard`
128         tg: but please remember you are on the base branch now;
129         tg: you will want to switch to a different branch.
130         $ ..resolve..
131         $ git commit
132         $ tg create
133         tg: Resuming t/whatever setup...
134         $ ..hack..
135         $ git commit
137         ## Update a single topic branch and propagate the changes to
138         ## a different one
139         $ git checkout t/gitweb/nifty-links
140         $ ..hack..
141         $ git commit
142         $ git checkout t/whatever
143         $ tg info
144         Topic Branch: t/whatever (1 commit)
145         Subject: [PATCH] Whatever patch
146         Base: 3f47ebc1
147         Depends: t/revlist/author-fixed t/gitweb/nifty-links
148         Needs update from:
149                 t/gitweb/nifty-links (1 commit)
150         $ tg update
151         tg: Updating base with t/gitweb/nifty-links changes...
152         Merge failed!
153         tg: Please commit merge resolution and call `tg update` again.
154         tg: It is also safe to abort this operation using `git reset --hard`,
155         tg: but please remember you are on the base branch now;
156         tg: you will want to switch to a different branch.
157         $ ..resolve..
158         $ git commit
159         $ tg update
160         tg: Updating t/whatever against new base...
161         Merge failed!
162         tg: Please resolve the merge and commit. No need to do anything else.
163         tg: You can abort this operation using `git reset --hard` now
164         tg: and retry this merge later using `tg update`.
165         $ ..resolve..
166         $ git commit
168         ## Update a single topic branch and propagate the changes
169         ## further through the dependency chain
170         $ git checkout t/gitweb/pathinfo-action
171         $ ..hack..
172         $ git commit
173         $ git checkout t/whatever
174         $ tg info
175         Topic Branch: t/whatever (1/2 commits)
176         Subject: [PATCH] Whatever patch
177         Base: 0ab2c9b3
178         Depends: t/revlist/author-fixed t/gitweb/nifty-links
179         Needs update from:
180                 t/gitweb/pathinfo-action (<= t/gitweb/nifty-links) (1 commit)
181         $ tg update
182         tg: Recursing to t/gitweb/nifty-links...
183         [t/gitweb/nifty-links] tg: Updating base with t/gitweb/pathinfo-action changes...
184         Merge failed!
185         [t/gitweb/nifty-links] tg: Please commit merge resolution and call `tg update` again.
186         [t/gitweb/nifty-links] tg: It is also safe to abort this operation using `git reset --hard`,
187         [t/gitweb/nifty-links] tg: but please remember you are on the base branch now;
188         [t/gitweb/nifty-links] tg: you will want to switch to a different branch.
189         [t/gitweb/nifty-links] tg: You are in a subshell. If you abort the merge,
190         [t/gitweb/nifty-links] tg: use `exit` to abort the recursive update altogether.
191         [t/gitweb/nifty-links] $ ..resolve..
192         [t/gitweb/nifty-links] $ git commit
193         [t/gitweb/nifty-links] $ tg update
194         [t/gitweb/nifty-links] tg: Updating t/gitweb/nifty-links against new base...
195         Merge failed!
196         [t/gitweb/nifty-links] tg: Please resolve the merge and commit.
197         [t/gitweb/nifty-links] tg: You can abort this operation using `git reset --hard`.
198         [t/gitweb/nifty-links] tg: You are in a subshell. After you either commit or abort
199         [t/gitweb/nifty-links] tg: your merge, use `exit` to proceed with the recursive update.
200         [t/gitweb/nifty-links] $ ..resolve..
201         [t/gitweb/nifty-links] $ git commit
202         [t/gitweb/nifty-links] $ exit
203         tg: Updating base with t/gitweb/nifty-links changes...
204         tg: Updating t/whatever against new base...
206         ## Clone a TopGit-controlled repository
207         $ git clone URL repo
208         $ cd repo
209         $ tg remote --populate origin
210         ...
211         $ git fetch
212         $ tg update
214         ## Add a TopGit remote to a repository and push to it
215         $ git remote add foo URL
216         $ tg remote foo
217         $ tg push -r foo
219         ## Update from a non-default TopGit remote
220         $ git fetch foo
221         $ tg -r foo summary
222         $ tg -r foo update
225 CONVENTIONS
226 -----------
228 When using TopGit there are several common conventions used when working with
229 TopGit branches.  None of them are enforced, they are only suggestions.
231 There are three typical uses for a TopGit branch:
233     1. Normal TopGit branches that represent a single patch.  These are known
234        as "patch" TopGit branches.
235     2. Empty TopGit branches with no dependencies (an empty ``.topdeps`` file)
236        that represent a base upon which other "normal" TopGit branches depend.
237        These are known as "base" TopGit branches (not to be confused with
238        the refs/top-bases/... refs).
239     3. Empty TopGit branches that serve as a staging area to bring together
240        several other TopGit branches into one place so they can be used/tested
241        all together.  These are known as "stage" TopGit branches.
243 An "empty" TopGit branch is one that does not have any changes of its own --
244 it may still have dependencies though ("stage" branches do, "base" branches do
245 not).  The ``tg summary`` output shows empty branches with a ``0`` in the
246 listing.  Normal "patch" branches that have not been annihilated, "base" and
247 "stage" branches fall into this category.  (Annihilated branches are normally
248 omitted from the ``tg summary`` output but can be shown if given explicitly as
249 an argument to the ``tg summary`` command.  However, the message line will be
250 incorrect since an annihilated branch has no ``.topmsg`` file of its own.)
252 A "patch" branch name typically starts with ``t/`` whereas "base" and "stage"
253 branch names often do not.
255 A "base" branch is created by using the ``--no-deps`` option of ``tg create``
256 which will automatically suggest a "[BASE]" message prefix rather than
257 "[PATCH]".  A "stage" branch is created like a normal patch branch except that
258 the only changes that will ever be made to it are typically to add/remove
259 dependencies.  Its subject prefix must be manually changed to "[STAGE]" to
260 reflect its purpose.
262 Since both "base" and "stage" branches typically only have a use for the
263 "Subject:" ilne from their ``.topmsg`` file, they are quite easily created
264 using the ``--topmsg`` option of ``tg create``.
266 Use of "stage" and "base" branches is completely optional.  However, without
267 use of a "stage" branch it will be difficult to test multiple independent
268 patches together all at once.  A "base" branch is merely a convenience that
269 provides more explicit control over when common base for a set of patches gets
270 updated as well as providing a branch that shows in ``tg summary`` output and
271 participates in ``tg remote --populate`` setup.
273 When using the ``tg tag`` command to create tags that record the current state
274 of one or more TopGit branches, the tags are often created with a name that
275 starts with ``t/``.
277 One last thing, you have enabled ``git rerere`` haven't you?
280 NO UNDO
281 -------
283 Beware, there is no "undo" after running a ``tg update``!
285 Well, that's not entirely correct.  Since ``tg update`` never discards commits
286 an "undo" operation is technically feasible provided the old values of all the
287 refs that were affected by the ``tg update`` operation can be determined and
288 then they are simply changed back to their previous values.
290 In practice though, it can be extremely tedious and error prone looking through
291 log information to try and determine what the correct previous values were.
292 Although, since TopGit tries to make sure reflogs are enabled for top-bases
293 refs, using Git's ``@{date}`` notation on all the refs dumped out by a
294 ``tg tag --refs foo``, where "foo" is the branch that was updated whose update
295 needs to be undone, may work.
297 Alternatively, ``tg tag --stash`` can be used prior to the update and then
298 ``tg revert`` used after the update to restore the previous state.  This
299 assumes, of course, that you remember to run ``tg tag --stash`` first.
301 The ``tg update`` command understands a ``--stash`` option that tells it to
302 automatically run ``tg tag --stash`` before it starts making changes (if
303 everything is up-to-date it won't run the stash command at all).  The
304 ``--stash`` option is the default, add the ``--no-stash`` option to turn it
305 off.
307 There is a preference for this.  Setting the config value ``topgit.autostash``
308 to ``false`` will implicitly add the ``--no-stash`` option to any ``tg update``
309 command unless an explicit ``--stash`` option is given.
311 If you are likely to ever want to undo a ``tg update``, setting
312 ``topgit.autostash`` to ``false`` is highly discouraged!
314 Note that the tags saved by ``tg tag --stash`` are stored in the
315 ``refs/tgstash`` ref and its reflog.  Unfortunately, while Git is happy to
316 maintain the reflog (once it's been enabled which ``tg tag`` guarantees for
317 ``refs/tgstash``), Git is unable to view an annotated/signed tag's reflog!
318 Instead Git dereferences the tag and shows the wrong thing.  Use the
319 ``tg tag -g`` command to view the ``refs/tgstash`` reflog instead.
322 SEQUESTRATION
323 -------------
325 No, this is not a section about budget nonsense.  ;)
327 TopGit keeps its metadata in ``.topdeps`` and ``.topmsg`` files.  In an effort
328 to facilitate cherry-picking and other Git activities on the patch changes
329 themselves while ignoring the TopGit metadata, TopGit attempts to keep all
330 changes to ``.topdeps`` and ``.topmsg`` files limited to commits that do NOT
331 contain changes to any other files.
333 This is a departure from previous TopGit versions that made no such effort.
335 Primarily this affects ``tg create`` and ``tg import`` (which makes use of
336 ``tg create``) as ``tg create`` will commit the initial versions of
337 ``.topdeps`` and ``.topmsg`` for a new TopGit-controlled branch in their own
338 commit instead of mixing them in with changes to other files.
340 The ``pre-commit`` hook will also attempt to separate out any ``.topdeps`` and
341 ``.topmsg`` changes from commits that include changes to other files.
343 It is possible to defeat these checks without much effort (``pre-commit`` hooks
344 can easily be bypassed, ``tg create`` has a ``--no-commit`` option, many Git
345 commands simply do not run the ``pre-commit`` hook, etc.).
347 If you really, really, really, really want to change the default back to the
348 old behavior of previous TopGit versions where no such sequestration took
349 place, then set the ``topgit.sequester`` config variable explicitly to the
350 value ``false``.  But this is not recommended.
353 AMENDING AND REBASING AND UPDATE-REF'ING
354 ----------------------------------------
356 In a word, "don't".
358 It is okay to manually update a top-bases/... ref when a) it has no depedencies
359 (i.e. it was created with the ``tg create`` ``--no-deps`` option) and b) the
360 old top-bases/... ref value can be fast-forwarded to the new top-bases/...
361 value OR the new value contains ALL of the changes in the old value through
362 some other mechanism (perhaps they were cherry-picked or otherwise applied to
363 the new top-bases/... ref).  The same rules apply to non-TopGit-controlled
364 dependencies.
366 Ignoring this rule and proceeding anyway with a non-fast-forward update to a
367 top-bases/... ref will result in changes present in the new value being merged
368 into the branch (at ``tg update`` time) as expected (possibly with conflicts),
369 but any changes that were contained in the old version of the top-bases/... ref
370 which have been dropped (i.e. are NOT contained in the new version of the
371 top-bases/... ref) will continue to be present in the branch!  To get rid of
372 the dropped commits, one or more "revert" commits will have to be manually
373 applied to the tip of the new top-bases/... value (which will then be merged
374 into the branch at next ``tg update`` time).
376 The only time it's safe to amend, rebase, filter or otherwise rewrite commits
377 contained in a TopGit controlled branch or non-TopGit branch is when those
378 commits are NOT reachable via any other ref!
380 Furthermore, while it is safe to rewrite merge commits (provided they meet the
381 same conditions) the merge commits themselves and the branches they are merging
382 in must be preserved during the rewrite and that can be rather tricky to get
383 right so it's not recommended.
385 For example, if, while working on a TopGit-controlled branch ``foo``, a bad
386 typo is noticed, it's okay to ammend/rebase to fix that provided neither
387 ``tg update`` nor ``tg create`` has already been used to cause some other ref
388 to be able to reach the commit with the typo.
390 If an amend or rerwite is done anyway even though the commit with the typo is
391 reachable from some other ref, the typo won't really be removed.  What will
392 happen instead is that the new version without the typo will ultimately be
393 merged into the other ref(s) (at ``tg update`` time) likely causing a conflict
394 that will have to be manually resolved and the commit with the typo will
395 continue to be reachable from those other refs!
397 Instead just make a new commit to fix the typo.  The end result will end up
398 being the same but without the merge conflicts.
400 See also the discussion in the "NO UNDO" section.
403 SPEED AND CACHING
404 -----------------
406 TopGit needs to check many thing to determine whether a TopGit branch is
407 up-to-date or not.  This can involve a LOT of git commands for a complex
408 dependency tree.  In order to speed things up, TopGit keeps a cache of results
409 in a ``tg-cache`` subdirectory in the ``.git`` directory.
411 Results are tagged with the original hash values used to get that result so
412 that items which have not been changed return their results quickly and items
413 which have been changed compute their new result and cache it for future use.
415 The ``.git/tg-cache`` directory may be removed at any time and the cache will
416 simply be recreated in an on-demand fashion as needed, at some speed penalty,
417 until it's fully rebuilt.
419 To force the cache to be fully pre-loaded, run the ``tg summary`` command
420 without any arguments.  Otherwise, normal day-to-day TopGit operations should
421 keep it more-or-less up-to-date.
423 While each TopGit command is running, it uses a temporary subdirectory also
424 located in the ``.git`` directory.  These directories are named
425 ``tg-tmp.XXXXXX`` where the ``XXXXXX`` part will be random letters and digits.
427 These temporary directories should always be removed automatically after each
428 TopGit command finishes running.  As long as you are not in a subshell as a
429 result of a TopGit command stopping and waiting for a manual merge resolution,
430 it's safe to remove any of these directories that may have somehow accidentally
431 been left behind as a result of some failure that occurred while running a
432 TopGit command (provided, of course, it's not actually being used by a TopGit
433 command currently running in another terminal window or by another user on the
434 same repository).
437 USAGE
438 -----
439 ``tg [-C <dir>] [-r <remote> | -u] [-c <name>=<val>] <subcommand> [<subcommand option/argument>...]``
441         -C <dir>        Change directory to <dir> before doing anything
442         -r <remote>     Pretend ``topgit.remote`` is set to <remote>
443         -u              Pretend ``topgit.remote`` is not set
444         -c <name=val>   Pass config option to git, may be repeated
446 The ``tg`` tool has several subcommands:
448         :`tg annihilate`_:  Mark a TopGit-controlled branch as defunct
449         :`tg base`_:        Show base commit for one or more TopGit branches
450         :`tg checkout`_:    Shortcut for git checkout with name matching
451         :`tg create`_:      Create a new TopGit-controlled branch
452         :`tg delete`_:      Delete a TopGit-controlled branch cleanly
453         :`tg depend`_:      Add a new dependency to a TopGit-controlled branch
454         :`tg export`_:      Export TopGit branch patches to files or a branch
455         :`tg files`_:       Show files changed by a TopGit branch
456         :`tg help`_:        Show TopGit help optionally using a browser
457         :`tg import`_:      Import commit(s) to separate TopGit branches
458         :`tg info`_:        Show status information about a TopGit branch
459         :`tg log`_:         Run git log limiting revisions to a TopGit branch
460         :`tg mail`_:        Shortcut for git send-email with ``tg patch`` output
461         :`tg next`_:        Show branches directly depending on a TopGit branch
462         :`tg patch`_:       Generate a patch file for a TopGit branch
463         :`tg prev`_:        Show non-annihilated TopGit dependencies for a branch
464         :`tg push`_:        Run git push on TopGit branch(es) and depedencies
465         :`tg rebase`_:      Auto continue git rebase if rerere resolves conflicts
466         :`tg remote`_:      Set up remote for fetching/pushing TopGit branches
467         :`tg revert`_:      Revert ref(s) to a state stored in a ``tg tag``
468         :`tg summary`_:     Show various information about TopGit branches
469         :`tg tag`_:         Create tag that records current TopGit branch state
470         :`tg update`_:      Update TopGit branch(es) with respect to dependencies
472 tg help
473 ~~~~~~~
474         Our sophisticated integrated help facility.  Mostly duplicates
475         what is below::
477          # to list commands:
478          $ tg help
479          # to get help for a particular command:
480          $ tg help <command>
481          # to get help for a particular command in a browser window:
482          $ tg help -w <command>
483          # to get help on TopGit itself
484          $ tg help tg
485          # to get help on TopGit itself in a browser
486          $ tg help -w tg
488 tg create
489 ~~~~~~~~~
490         Create a new TopGit-controlled topic branch of the given name
491         (required argument) and switch to it.  If no dependencies are
492         specified (by extra arguments passed after the first one), the
493         current branch is assumed to be the only dependency.
495         By default ``tg create`` opens an editor on the new ``.topmsg`` file
496         and then commits the new ``.topmsg`` and ``.topdeps`` files
497         automatically with a suitable default commit message.
499         The commit message can be changed with the ``-m`` (or ``--message``) or
500         ``-F`` (or ``--file``) option.  The automatic commit can be suppressed
501         by using the ``--no-ccmmit`` option.  Running the editor on the new
502         ``.topmsg`` file can be suppressed by using ``-n`` (or ``--no-edit``)
503         (which also suppresses the automatic commit) or by providing an
504         explicit value for the new ``.topmsg`` file using the ``--topmsg`` or
505         ``--topmsg-file`` option.  In any case the ``.topmsg`` content will be
506         automatically reformated to have a ``Subject:`` header line if needed.
508         If more than one dependency is listed, the automatic commit will not
509         take place until AFTER all the listed dependencies have been merged
510         into a base commit which will require some manual merge resolutions if
511         conflicts occur during the merge operations.
513         Previous versions of TopGit behaved as though the ``--no-edit`` option
514         was always given on the command line.
516         The default behavior has been changed to promote a separation between
517         commits that modify ``.topmsg`` and/or ``.topdeps`` and commits that
518         modify other files.  This facilitates cleaner cherry picking and other
519         patch maintenance activities.
521         You should edit the patch description (contained in the ``.topmsg``
522         file) as appropriate.  It will already contain some prefilled bits.
523         You can set the ``topgit.to``, ``topgit.cc`` and ``topgit.bcc``
524         git configuration variables (see ``man git-config``) in order to
525         have ``tg create`` add these headers with the given default values
526         to ``.topmsg`` before invoking the editor.
528         The main task of ``tg create`` is to set up the topic branch base
529         from the dependencies.  This may fail due to merge conflicts if more
530         than one dependencie is given.  In that case, after you commit the
531         conflict resolution, you should call ``tg create`` again (without any
532         arguments or with the single argument ``--continue``); it will then
533         detect that you are on a topic branch base ref and resume the topic
534         branch creation operation.
536         With the ``--no-deps`` option at most one dependency may be listed
537         which may be any valid committish (instead of just refs/heads/...) and
538         the newly created TopGit-controlled branch will have an empty
539         ``.topdeps`` file.  This may be desirable in order to create a TopGit-
540         controlled branch that has no changes of its own and serves merely to
541         mark the common dependency that all other TopGit-controlled branches
542         in some set of TopGit-controlled branches depend on.  A plain,
543         non-TopGit-controlled branch can be used for the same purpose, but the
544         advantage of a TopGit-controlled branch with no dependencies is that it
545         will be pushed with ``tg push``, it will show up in the ``tg summary``
546         and ``tg info`` output with the subject from its ``.topmsg`` file
547         thereby documenting what it's for and finally it can be set up with
548         ``tg create -r`` and/or ``tg remote --populate`` to facilitate sharing.
550         For example, ``tg create --no-deps release v2.1`` will create a TopGit-
551         controlled ``release`` branch based off the ``v2.1`` tag that can then
552         be used as a base for creation of other TopGit-controlled branches.
553         Then when the time comes to move the base for an entire set of changes
554         up to ``v2.2`` the command ``git update-ref top-bases/release v2.2^0``
555         can be used followed by ``tg update --all``.  Note that it's only safe
556         to update ``top-bases/release`` directly in this manner because a) it
557         has no depedencies since it was created with the ``--no-deps`` option
558         and b) the old ``top-bases/release`` value can be fast-forwarded to the
559         new ``top-bases/release`` value.
561         Using ``--no-deps`` it's also possible to use ``tg create`` on an
562         unborn branch (omit the dependency name or specify ``HEAD``).  The
563         unborn branch itself can be made into the new TopGit branch (rather
564         than being born empty and then having the new TopGit branch based off
565         that) by specifying ``HEAD`` as the new branch's name (which is
566         probably what you normally want to do in this case anyway so you can
567         just run ``tg create --no-deps HEAD`` to accomplish that).
569         In an alternative use case, if ``-r <branch>`` is given instead of a
570         dependency list, the topic branch is created based on the given
571         remote branch.  With just ``-r`` the remote branch name is assumed
572         to be the same as the local topic branch being created.  Since no
573         new commits are created in this mode (only two refs will be updated)
574         the editor will never be run for this use case.  Note that no other
575         options may be combined with ``-r``.
577         The ``--quiet`` (or ``-q``) option suppresses most informational
578         messages.
580 tg delete
581 ~~~~~~~~~
582         Remove a TopGit-controlled topic branch of the given name
583         (required argument). Normally, this command will remove only an
584         empty branch (base == head) without dependendents; use ``-f`` to
585         remove a non-empty branch or a branch that is depended upon by
586         another branch.
588         The ``-f`` option is also useful to force removal of a branch's
589         base, if you used ``git branch -D B`` to remove branch B, and then
590         certain TopGit commands complain, because the base of branch B
591         is still there.
593         Normally ``tg delete`` will refuse to delete the current branch.
594         However, giving ``-f`` twice (or more) will force it to do so but it
595         will first detach your HEAD.
597         IMPORTANT: Currently, this command will *NOT* remove the branch
598         from the dependency list in other branches. You need to take
599         care of this *manually*.  This is even more complicated in
600         combination with ``-f`` -- in that case, you need to manually
601         unmerge the removed branch's changes from the branches depending
602         on it.
604         See also ``tg annihilate``.
606         | TODO: ``-a`` to delete all empty branches, depfix, revert
608 tg annihilate
609 ~~~~~~~~~~~~~
610         Make a commit on the current TopGit-controlled topic branch
611         that makes it equal to its base, including the presence or
612         absence of .topmsg and .topdeps.  Annihilated branches are not
613         displayed by ``tg summary``, so they effectively get out of your
614         way.  However, the branch still exists, and ``tg push`` will
615         push it (except if given the ``-a`` option).  This way, you can
616         communicate that the branch is no longer wanted.
618         When annihilating a branch that has dependents (i.e. branches
619         that depend on it), those dependents have the dependencies of
620         the branch being annihilated added to them if they do not already
621         have them as dependencies.  Essentially the DAG is repaired to
622         skip over the annihilated branch.
624         Normally, this command will remove only an empty branch
625         (base == head, except for changes to the .top* files); use
626         ``-f`` to annihilate a non-empty branch.
628 tg depend
629 ~~~~~~~~~
630         Change the dependencies of a TopGit-controlled topic branch.
631         This should have several subcommands, but only ``add`` is
632         supported right now.
634         The ``add`` subcommand takes an argument naming a topic branch to
635         be added, adds it to ``.topdeps``, performs a commit and then
636         updates your topic branch accordingly.  If you want to do other
637         things related to the dependency addition, like adjusting
638         ``.topmsg``, use the option ``--no-commit``.  Adding the
639         ``--no-update`` (or ``--no-commit``) option will suppress the
640         ``tg update`` normally performed after committing the change.
642         It is safe to run ``tg depend add`` in a dirty worktree, but the
643         normally performed ``tg update`` will be suppressed in that case
644         (even if neither ``--no-update`` nor ``--no-commit`` is given).
646         You have enabled ``git rerere`` haven't you?
648         | TODO: Subcommand for removing dependencies, obviously
650 tg files
651 ~~~~~~~~
652         List files changed by the current or specified topic branch.
654         Options:
655           -i            list files based on index instead of branch
656           -w            list files based on working tree instead of branch
658 tg info
659 ~~~~~~~
660         Show summary information about the current or specified topic
661         branch.
663         Numbers in parenthesis after a branch name such as "(11/3 commits)"
664         indicate how many commits on the branch (11) and how many of those
665         are non-merge commits (3).
667         Alternatively, if ``--heads`` is used then which of the independent
668         TopGit branch heads (as output by ``tg summary --tgish-only --heads)``
669         contains the specified commit (which may be any committish -- defaults
670         to ``HEAD`` if not given).  Zero or more results will be output.
672 tg patch
673 ~~~~~~~~
674         Generate a patch from the current or specified topic branch.
675         This means that the diff between the topic branch base and head
676         (latest commit) is shown, appended to the description found in
677         the ``.topmsg`` file.
679         The patch is simply dumped to stdout.  In the future, ``tg patch``
680         will be able to automatically send the patches by mail or save
681         them to files. (TODO)
683         Options:
684           -i            base patch generation on index instead of branch
685           -w            base patch generation on working tree instead of branch
686           --binary      pass --binary to ``git diff-tree`` to enable generation
687                         of binary patches
688           --diff-opt    options after the branch name (and an optional ``--``)
689                         are passed directly to ``git diff-tree``
691         In order to pass a sole explicit ``-w`` through to ``git diff-tree`` it
692         must be separated from the ``tg`` options by an explicit ``--``.
693         Or it can be spelled as ``--ignore-all-space`` to distinguuish it from
694         ``tg``'s ``-w`` option.
696         If additional non-``tg`` options are passed through to
697         ``git diff-tree`` (other than ``--binary`` which is fully supported)
698         the resulting ``tg patch`` output may not be appliable.
700 tg mail
701 ~~~~~~~
702         Send a patch from the current or specified topic branch as
703         email(s).
705         Takes the patch given on the command line and emails it out.
706         Destination addresses such as To, Cc and Bcc are taken from the
707         patch header.
709         Since it actually boils down to ``git send-email``, please refer
710         to the documentation for that for details on how to setup email
711         for git.  You can pass arbitrary options to this command through
712         the ``-s`` parameter, but you must double-quote everything.  The
713         ``-r`` parameter with a msgid can be used to generate in-reply-to
714         and reference headers to an earlier mail.
716         WARNING: be careful when using this command.  It easily sends
717         out several mails.  You might want to run::
719                 git config sendemail.confirm always
721         to let ``git send-email`` ask for confirmation before sending any
722         mail.
724         Options:
725           -i            base patch generation on index instead of branch
726           -w            base patch generation on working tree instead of branch
728         | TODO: ``tg mail patchfile`` to mail an already exported patch
729         | TODO: mailing patch series
730         | TODO: specifying additional options and addresses on command line
732 tg remote
733 ~~~~~~~~~
734         Register the given remote as TopGit-controlled. This will create
735         the namespace for the remote branch bases and teach ``git fetch``
736         to operate on them. However, from TopGit 0.8 onwards you need to
737         use ``tg push``, or ``git push --mirror``, for pushing
738         TopGit-controlled branches.
740         ``tg remote`` takes an optional remote name argument, and an
741         optional ``--populate`` switch.  Use ``--populate`` for your
742         origin-style remotes: it will seed the local topic branch system
743         based on the remote topic branches.  ``--populate`` will also make
744         ``tg remote`` automatically fetch the remote, and ``tg update`` look
745         at branches of this remote for updates by default.
747         Using ``--populate`` with a remote name causes the ``topgit.remote``
748         git configuration variable to be set to the given remote name.
750 tg summary
751 ~~~~~~~~~~
752         Show overview of all TopGit-tracked topic branches and their
753         up-to-date status.  With a branch name limit output to that branch.
754         Using ``--deps-only`` or ``--rdeps`` changes the default from all
755         branches to just the current ``HEAD`` branch but using ``--all`` as
756         the branch name will show results for all branches instead of ``HEAD``.
758                 ``>``
759                         marks the current topic branch
761                 ``0``
762                         indicates that it introduces no changes of its own
764                 ``l``/``r``
765                         indicates respectively whether it is local-only
766                         or has a remote mate
768                 ``L``/``R``
769                         indicates respectively if it is ahead or out-of-date
770                         with respect to its remote mate
772                 ``D``
773                         indicates that it is out-of-date with respect to its
774                         dependencies
776                 ``!``
777                         indicates that it has missing dependencies [even if
778                         they are recursive ones]
780                 ``B``
781                         indicates that it is out-of-date with respect to
782                         its base
784         This can take a longish time to accurately determine all the
785         relevant information about each branch; you can pass ``-t`` (or ``-l``
786         or ``--list``) to get just a terse list of topic branch names quickly.
788         Passing ``--heads`` shows independent topic branch names and when
789         combined with ``--rdeps`` behaves as though ``--rdeps`` were run with
790         the output of ``--heads``.
792         Alternatively, you can pass ``--graphviz`` to get a dot-suitable output
793         for drawing a dependency graph between the topic branches.
795         You can also use the ``--sort`` option to sort the branches using
796         a topological sort.  This is especially useful if each
797         TopGit-tracked topic branch depends on a single parent branch,
798         since it will then print the branches in the dependency order.
799         In more complex scenarios, a text graph view would be much more
800         useful, but that has not yet been implemented.
802         The ``--deps`` option outputs dependency information between
803         branches in a machine-readable format.  Feed this to ``tsort`` to
804         get the output from --sort.
806         The ``--deps-only`` option outputs a sorted list of the unique branch
807         names given on the command line plus all of their recursive
808         dependencies (subject to ``--exclude`` of course).  When
809         ``--deps-only`` is given the default is to just display information for
810         ``HEAD``, but that can be changed by using ``--all`` as the branch
811         name.  Each branch name will appear only once in the output no matter
812         how many times it's visited while tracing the dependency graph or how
813         many branch names are given on the command line to process.
815         The ``--rdeps`` option outputs dependency information in an indented
816         text format that clearly shows all the dependencies and their
817         relationships to one another.  When ``--rdeps`` is given the default is
818         to just display information for ``HEAD``, but that can be changed by
819         using ``--all`` as the branch name or by adding the ``--heads`` option.
820         Note that ``tg summary --rdeps --heads`` can be particularly helpful in
821         seeing all the TopGit-controlled branches in the repository and their
822         relationships to one another.
824         Adding ``--with-deps`` replaces the given list of branches (which will
825         default to ``HEAD`` if none are given) with the result of running
826         ``tg summary --deps-only --tgish`` on the list of branches.  This can
827         be helpful in limiting ``tg summary`` output to only the list of given
828         branches and their dependencies when many TopGit-controlled branches
829         are present in the repository.
831         With ``--exclude branch``, branch can be excluded from the output
832         meaning it will be skipped and its name will be omitted from any
833         dependency output.  The ``--exclude`` option may be repeated to omit
834         more than one branch from the output.  Limiting the output to a single
835         branch that has been excluded will result in no output at all.
837         The ``--tgish-only`` option behaves as though any non-TopGit-controlled
838         dependencies encountered during processing had been listed after an
839         ``--exclude`` option.
841         Note that the branch name can be specified as ``HEAD`` as a shortcut for
842         the TopGit-controlled branch that ``HEAD`` is a symbolic ref to.
844         Options:
845           -i            Use TopGit metadata from the index instead of the branch
846           -w            Use TopGit metadata from the working tree instead of the branch
849 tg checkout
850 ~~~~~~~~~~~
851         Switch to a topic branch.  You can use ``git checkout <branch>``
852         to get the same effect, but this command helps you navigate
853         the dependency graph, or allows you to match the topic branch
854         name using a regular expression, so it can be more convenient.
856         There following subcommands are available:
858             ``tg checkout push``
859                                 Check out a branch that directly
860                                 depends on your current branch.
862             ``tg checkout pop``
863                                 Check out a branch that this branch
864                                 directly depends on.
866             ``tg checkout [goto] [--] <pattern>``
867                                 Check out a topic branch that
868                                 matches ``<pattern>``.  ``<pattern>``
869                                 is used as a sed pattern to filter
870                                 all the topic branches.  Both ``goto`` and
871                                 ``--`` may be omitted provided ``<pattern>``
872                                 is not ``push``, ``pop``, ``-a``, ``--all``,
873                                 ``goto``, ``..``, ``--``, ``next``, ``child``,
874                                 ``prev``, ``parent``, ``-h`` or ``--help``.
876             ``tg checkout next``
877                                 An alias for ``push``.
879             ``tg checkout child``
880                                 An alias for ``push``.
882             ``tg checkout``
883                                 An alias for ``push``.
885             ``tg checkout prev``
886                                 An alias for ``pop``.
888             ``tg checkout parent``
889                                 An alias for ``pop``.
891             ``tg checkout ..``
892                                 An alias for ``pop``.
894         If any of the above commands can find more than one possible
895         branch to switch to, you will be presented with the matches
896         and asked to select one of them.
898         The ``<pattern>`` of ``tg checkout goto`` is optional.  If you don't
899         supply it, all the available topic branches are listed and you
900         can select one of them.
902         Normally, the ``push`` and ``pop`` commands moves one step in
903         the dependency graph of the topic branches.  The ``-a`` option
904         causes them (and their aliases) to move as far as possible.
905         That is, ``tg checkout push -a`` moves to a topic branch that
906         depends (directly or indirectly) on the current branch and
907         that no other branch depends on.  ``tg checkout pop -a``
908         moves to a regular branch that the current topic branch
909         depends on (directly or indirectly).  If there is more than
910         one possibility, you will be prompted for your selection.
912 tg export
913 ~~~~~~~~~
914         Export a tidied-up history of the current topic branch and its
915         dependencies, suitable for feeding upstream.  Each topic branch
916         corresponds to a single commit or patch in the cleaned up
917         history (corresponding basically exactly to ``tg patch`` output
918         for the topic branch).
920         The command has three possible outputs now -- either a Git branch
921         with the collapsed history, a Git branch with a linearized
922         history, or a quilt series in new directory.
924         In the case where you are producing collapsed history in a new
925         branch, you can use this collapsed structure either for
926         providing a pull source for upstream, or for further
927         linearization e.g. for creation of a quilt series using git log::
929                 git log --pretty=email -p --topo-order origin..exported
931         To better understand the function of ``tg export``, consider this
932         dependency structure::
934          origin/master - t/foo/blue - t/foo/red - master
935                       `- t/bar/good <,----------'
936                       `- t/baz      ------------'
938         (where each of the branches may have a hefty history). Then::
940          master$ tg export for-linus
942         will create this commit structure on the branch ``for-linus``::
944          origin/master - t/foo/blue -. merge - t/foo/red -.. merge - master
945                       `- t/bar/good <,-------------------'/
946                       `- t/baz      ---------------------'
948         In this mode, ``tg export`` works on the current topic branch, and
949         can be called either without an option (in that case,
950         ``--collapse`` is assumed), or with the ``--collapse`` option, and
951         with one mandatory argument: the name of the branch where the
952         exported result will be stored.
954         When using the linearize mode::
956          master$ tg export --linearize for-linus
958         you get a linear history respecting the dependencies of your
959         patches in a new branch ``for-linus``.  The result should be more
960         or less the same as using quilt mode and then reimporting it
961         into a Git branch.  (More or less because the topological order
962         can usually be extended in more than one way into a total order,
963         and the two methods may choose different ones.)  The result
964         might be more appropriate for merging upstream, as it contains
965         fewer merges.
967         Note that you might get conflicts during linearization because
968         the patches are reordered to get a linear history.  If linearization
969         would produce conflicts then using ``--quilt`` will also likely result
970         in conflicts when the exported quilt series is applied.  Since the
971         ``--quilt`` mode simply runs a series of ``tg patch`` commands to
972         generate the patches in the exported quilt series and those patches
973         will end up being applied linearly, the same conflicts that would be
974         produced by the ``--linearize`` option will then occur at that time.
976         To avoid conflicts produced by ``--linearize`` (or by applying the
977         ``--quilt`` output), use the default ``--collapse`` mode and then use
978         ``tg rebase`` (or ``git rebase -m`` directly) on the collapsed branch
979         (with a suitable <upstream>) followed by ``git format-patch`` on the
980         rebased result to produce a conflict-free patch set.
982         You have enabled ``git rerere`` haven't you?
984         When using the quilt mode::
986          master$ tg export --quilt for-linus
988         would create the following directory ``for-linus``::
990          for-linus/t/foo/blue.diff
991          for-linus/t/foo/red.diff
992          for-linus/t/bar/good.diff
993          for-linus/t/baz.diff
994          for-linus/series:
995                 t/foo/blue.diff -p1
996                 t/bar/good.diff -p1
997                 t/foo/red.diff -p1
998                 t/baz.diff -p1
1000         With ``--quilt``, you can also pass the ``-b`` parameter followed
1001         by a comma-separated explicit list of branches to export, or
1002         the ``--all`` parameter (which can be shortened to ``-a``) to
1003         export them all.  The ``--binary`` option enables producing Git
1004         binary patches.  These options are currently only supported
1005         with ``--quilt``.
1007         In ``--quilt`` mode the patches are named like the originating
1008         topgit branch.  So usually they end up in subdirectories of the
1009         output directory.  With the ``--flatten`` option the names are
1010         mangled so that they end up directly in the output dir (slashes
1011         are replaced with underscores).  With the ``--strip[=N]`` option
1012         the first ``N`` subdirectories (all if no ``N`` is given) get
1013         stripped off.  Names are always ``--strip``'d before being
1014         ``--flatten``'d.  With the option ``--numbered`` (which implies
1015         ``--flatten``) the patch names get a number as prefix to allow
1016         getting the order without consulting the series file, which
1017         eases sending out the patches.
1019         | TODO: Make stripping of non-essential headers configurable
1020         | TODO: Make stripping of [PATCH] and other prefixes configurable
1021         | TODO: ``--mbox`` option to export instead as an mbox file
1022         | TODO: support ``--all`` option in other modes of operation
1023         | TODO: For quilt exporting, export the linearized history created in
1024                 a temporary branch--this would allow producing conflict-less
1025                 series
1027 tg import
1028 ~~~~~~~~~
1029         Import commits within the given revision range into TopGit,
1030         creating one topic branch per commit. The dependencies are set
1031         up to form a linear sequence starting on your current branch --
1032         or a branch specified by the ``-d`` parameter, if present.
1034         The branch names are auto-guessed from the commit messages and
1035         prefixed by ``t/`` by default; use ``-p <prefix>`` to specify an
1036         alternative prefix (even an empty one).
1038         Alternatively, you can use the ``-s NAME`` parameter to specify
1039         the name of the target branch; the command will then take one
1040         more argument describing a *single* commit to import.
1042 tg update
1043 ~~~~~~~~~
1044         Update the current, specified or all topic branches with respect
1045         to changes in the branches they depend on and remote branches.
1046         This is performed in two phases -- first, changes within the
1047         dependencies are merged to the base, then the base is merged
1048         into the topic branch.  The output will guide you on what to do
1049         next in case of conflicts.
1051         You have enabled ``git rerere`` haven't you?
1053         When ``-a`` (or ``--all``) is specifed, updates all topic branches
1054         matched by ``<pattern>``'s (see ``git-for-each-ref(1)`` for details),
1055         or all if no ``<pattern>`` is given.  Any topic branches with missing
1056         dependencies will be skipped entirely unless ``--skip`` is specified.
1058         When ``--skip`` is specifed, an attempt is made to update topic
1059         branches with missing dependencies by skipping only the dependencies
1060         that are missing.  Caveat utilitor.
1062         When ``--stash`` is specified (or the ``topgit.autostash`` config
1063         value is set to ``true``), a ref stash will be automatically created
1064         just before beginning updates if any are needed.  The ``--no-stash``
1065         option may be used to disable a ``topgit.autostash=true`` setting.
1066         See the ``tg tag`` ``--stash`` option for details.
1068         After the update, if a single topic branch was specified, it is
1069         left as the current one; if ``-a`` was specified, it returns to
1070         the branch which was current at the beginning.
1072         If your dependencies are not up-to-date, ``tg update`` will first
1073         recurse into them and update them.
1075         If a remote branch update brings in dependencies on branches
1076         that are not yet instantiated locally, you can either bring in
1077         all the new branches from the remote using ``tg remote
1078         --populate``, or only pick out the missing ones using ``tg create
1079         -r`` (``tg summary`` will point out branches with incomplete
1080         dependencies by showing an ``!`` next to them).
1082         | TODO: ``tg update -a -c`` to autoremove (clean) up-to-date branches
1084 tg push
1085 ~~~~~~~
1086         If ``-a`` or ``--all`` was specified, pushes all non-annihilated
1087         TopGit-controlled topic branches, to a remote repository.
1088         Otherwise, pushes the specified topic branches -- or the
1089         current branch, if you don't specify which.  By default, the
1090         remote gets all the dependencies (both TopGit-controlled and
1091         non-TopGit-controlled) and bases pushed to it too.  If
1092         ``--tgish-only`` was specified, only TopGit-controlled
1093         dependencies will be pushed, and if ``--no-deps`` was specified,
1094         no dependencies at all will be pushed.
1096         The ``--dry-run`` and ``--force`` options are passed directly to
1097         ``git push`` if given.
1099         The remote may be specified with the ``-r`` option. If no remote
1100         was specified, the configured default TopGit remote will be
1101         used.
1103 tg base
1104 ~~~~~~~
1105         Prints the base commit of each of the named topic branches, or
1106         the current branch if no branches are named.  Prints an error
1107         message and exits with exit code 1 if the named branch is not
1108         a TopGit branch.
1110 tg log
1111 ~~~~~~
1112         Prints the git log of the named topgit branch -- or the current
1113         branch, if you don't specify a name.
1115         NOTE: if you have merged changes from a different repository, this
1116         command might not list all interesting commits.
1118 tg tag
1119 ~~~~~~
1120         Creates a TopGit annotated/signed tag or lists the reflog of one.
1122         A TopGit annotated tag records the current state of one or more TopGit
1123         branches and their dependencies and may be used to revert to the tagged
1124         state at any point in the future.
1126         When reflogs are enabled (the default in a non-bare repository) and
1127         combined with the ``--force`` option a single tag name may be used as a
1128         sort of TopGit branch state stash.  The special branch name ``--all``
1129         may be used to tag the state of all current TopGit branches to
1130         facilitate this function and has the side-effect of suppressing the
1131         out-of-date check allowing out-of-date branches to be included.
1133         As a special feature, ``--stash`` may be used as the tag name in which
1134         case ``--all`` is implied if no branch name is listed (instead of the
1135         normal default of ``HEAD``), ``--force`` and ``--no-edit`` (use
1136         ``--edit`` to change that) are automatically activated and the tag will
1137         be saved to ``refs/tgstash`` instead of ``refs/tags/<tagname>``.
1138         The ``--stash`` tag name may also be used with the ``-g``/``--reflog``
1139         option.
1141         The mostly undocumented option ``--allow-outdated`` will bypass the
1142         out-of-date check and is implied when ``--stash`` or ``--all`` is used.
1144         A TopGit annotated/signed tag is simply a Git annotated/signed tag with
1145         a "TOPGIT REFS" section appended to the end of the tag message (and
1146         preceding the signature for signed tags).  PEM-style begin and end
1147         lines surround one line per ref where the format of each line is
1148         full-hash SP ref-name.  A line will be included for each branch given
1149         on the command line and each ref they depend on either directly or
1150         indirectly.
1152         If more than one TopGit branch is given on the command line, a new
1153         commit will be created that has an empty tree and all of the given
1154         TopGit branches as parents and that commit will be tagged.  If a single
1155         TopGit branch is given, then it will be tagged.
1157         All the options for creating a tag serve the same purpose as their Git
1158         equivalents except for two.  The ``--refs`` option suppresses tag
1159         creation entirely and emits the "TOPGIT REFS" section that would have
1160         been included with the tag.  If the ``--no-edit`` option is given and
1161         no message is supplied (via the ``-m`` or ``-F`` option) then the
1162         default message created by TopGit will be used without running the
1163         editor.
1165         With ``-g`` or ``--reflog`` show the reflog for a tag.  With the
1166         ``--reflog-message`` option the message from the reflog is shown.
1167         With the ``--commit-message`` option the first line of the tag's
1168         message (if the object is a tag) or the commit message (if the object
1169         is a commit) falling back to the reflog message for tree and blob
1170         objects is shown.  The default is ``--reflog-message`` unless the
1171         ``--stash`` (``refs/tgstash``) is being shown in which case the default
1172         is then ``--commit-message``.  Just add either option explicitly to
1173         override the default.
1175         When showing reflogs, non-tag entries are annotated with their type
1176         unless ``--no-type`` is given.
1178         TopGit tags are created with a reflog if core.logallrefupdates is
1179         enabled (the default for non-bare repositories).  Unfortunately Git
1180         is incapable of showing an annotated/signed tag's reflog
1181         (using git log -g) as it will first resolve the tag before checking to
1182         see if it has a reflog.  Git can, however, show reflogs for lightweight
1183         tags (using git log -g) just fine but that's not helpful here.  Use
1184         ``tg tag`` with the ``-g`` or ``--reflog`` option to see the reflog for
1185         an actual tag object.  This also works on non-TopGit annotated/signed
1186         tags as well provided they have a reflog.
1188         The number of entries shown may be limited with the ``-n`` option.  If
1189         the tagname is omitted then ``--stash`` is assumed.
1191         The ``--delete`` option is a convenience option that runs the
1192         ``git update-ref -d`` command on the specified tag removing it and its
1193         reflog (if it has one).
1195         The ``--clear`` option clears all but the most recent (the ``@{0}``)
1196         reflog entries from the reflog for the specified tag.  It's equivalent
1197         to dropping all the higher numbered reflog entries.
1199         The ``--drop`` option drops the specified reflog entry and requires the
1200         given tagname to have an ``@{n}`` suffix where ``n`` is the reflog
1201         entry number to be dropped.   This is really just a convenience option
1202         that runs the appropriate ``git reflog delete`` command.
1204         Note that when combined with ``tg revert``, a tag created by ``tg tag``
1205         can be used to transfer TopGit branches.  Simply create the tag, push
1206         it somewhere and then have the recipient run ``tg revert`` to recreate
1207         the TopGit branches.  This may be helpful in situations where it's not
1208         feasible to push all the refs corresponding to the TopGit-controlled
1209         branches and their top-bases.
1211 tg rebase
1212 ~~~~~~~~~
1213         Provides a ``git rebase`` rerere auto continue function.  It may be
1214         used as a drop-in replacement front-end for ``git rebase -m`` that
1215         automatically continues the rebase when ``git rerere`` information is
1216         sufficient to resolve all conflicts.
1218         You have enabled ``git rerere`` haven't you?
1220         If the ``-m`` or ``--merge`` option is not present then ``tg rebase``
1221         will complain and not do anything.
1223         When ``git rerere`` is enabled, previously resolved conflicts are
1224         remembered and can be automatically staged (see ``rerere.autoUpdate``).
1226         However, even with auto staging, ``git rebase`` still stops and
1227         requires an explicit ``git rebase --continue`` to keep going.
1229         In the case where ``git rebase -m`` is being used to flatten history
1230         (such as after a ``tg export --collapse`` prior to a
1231         ``git format-patch``), there's a good chance all conflicts have already
1232         been resolved during normal merge maintenance operations so there's no
1233         reason ``git rebase`` could not automatically continue, but there's no
1234         option to make it do so.
1236         The ``tg rebase`` command provides a ``git rebase --auto-continue``
1237         function.
1239         All the same rebase options can be used (they are simply passed through
1240         to Git unchanged).  However, the ``rerere.autoUpdate`` option is
1241         automatically temporarily enabled while running ``git rebase`` and
1242         should ``git rebase`` stop asking one to resolve and continue, but all
1243         conflicts have already been resolved and staged using rerere
1244         information, then ``git rebase --continue`` will be automatically run.
1246 tg revert
1247 ~~~~~~~~~
1248         Provides the ability to revert one or more TopGit branches and their
1249         dependencies to a previous state contained within a tag created using
1250         the ``tg tag`` command.  In addition to the actual revert mode
1251         operation a list mode operation is also provided to examine a tag's ref
1252         contents.
1254         The default mode (``-l`` or ``--list``) shows the state of one or more
1255         of the refs/branches stored in the tag data.  When no refs are given on
1256         the command line, all refs in the tag data are shown.  With the special
1257         ref name ``--heads`` then the indepedent heads contained in the tag
1258         data are shown.  The ``--deps`` option shows the specified refs and all
1259         of their dependencies in a single list with no duplicates.  The
1260         ``--rdeps`` option shows a display similar to ``tg summary --rdeps``
1261         for each ref or all independent heads if no ref is given on the command
1262         line.
1264         The revert mode has three submodes, dry-run mode (``-n`` or
1265         ``--dry-run``), force mode (``-f`` or ``--force``) and interactive mode
1266         (``-i`` or ``--interactive``).  If ``--dry-run`` (or ``-n``) is given
1267         no ref updates will actually be performed but what would have been
1268         updated is shown instead.  If ``--interactive`` (or ``-i``) is given
1269         then the editor is invoked on an instruction sheet allowing manual
1270         selection of the refs to be updated before proceeding.  Since revert is
1271         potentially a destructive operation, at least one of the submodes must
1272         be specified explicitly.  If no refs are listed on the command line
1273         then all refs in the tag data are reverted.  Otherwise the listed refs
1274         and all of their dependencies (unless ``--no-deps`` is given) are
1275         reverted.  Unless ``--no-stash`` is given a new stash will be created
1276         using ``tg tag --stash`` (except, of course, in dry-run mode) just
1277         before actually performing the updates to facilitate recovery from
1278         accidents.
1280         Both modes accept fully-qualified (i.e. starts with ``refs/``) ref
1281         names as well as unqualified names (which will be assumed to be located
1282         under ``refs/heads/``).  In revert mode a tgish ref will always have
1283         both its ``refs/heads/`` and ``refs/top-bases/`` values included no
1284         matter how it's listed unless ``--no-deps`` is given and the ref is
1285         fully qualified (i.e. starts with ``refs/``) or one or the other of its
1286         values was removed from the instruction sheet in interactive mode.  In
1287         list mode a tgish ref will always have both its ``refs/heads/`` and
1288         ``refs/top-bases/`` values included only when using the ``--deps`` or
1289         ``--rdeps`` options.
1291         The ``--tgish-only`` option excludes non-tgish refs (i.e. refs that do
1292         not have a ``refs/heads/<name>``, ``refs/top-bases/<name>`` pair).
1294         The ``--exclude`` option (which can be repeated) excludes specific
1295         refs.  If the name given to ``--exclude`` is not fully-qualified (i.e.
1296         starts with ``refs/``) then it will exclude both members of a tgish ref
1297         pair.
1299         The ``--quiet`` (or ``-q``) option may be used in revert mode to
1300         suppress non-dry-run ref change status messages.
1302         The special tag name ``--stash`` (as well as with ``@{n}`` suffixes)
1303         can be used to refer to ``refs/tgstash``.
1305         The ``tg revert`` command supports tags of tags that contains TopGit
1306         refs.  So, for example, if you do this::
1308                 tg tag newtag --all
1309                 git tag -f -a -m "tag the tag" newtag newtag
1311         Then ``newtag`` will be a tag of a tag containing a ``TOPGIT REFS``
1312         section.  ``tg revert`` knows how to dereference the outermost
1313         tag to get to the next (and the next etc.) tag to find the
1314         ``TOPGIT REFS`` section so after the above sequence, the tag ``newtag``
1315         can still be used successfully with ``tg revert``.
1317         NOTE:  If HEAD points to a ref that is updated by a revert operation
1318         then NO WARNING whatsoever will be issued, but the index and working
1319         tree will always be left completely untouched (and the reflog for
1320         the pointed-to ref can always be used to find the previous value).
1322 tg prev
1323 ~~~~~~~
1324         Outputs the direct dependencies for the current or named branch.
1326         Options:
1327           -i            show dependencies based on index instead of branch
1328           -w            show dependencies based on working tree instead of branch
1330 tg next
1331 ~~~~~~~
1332         Outputs all branches which directly depend on the current or
1333         named branch.
1335         Options:
1336           -i            show dependencies based on index instead of branch
1337           -w            show dependencies based on working tree instead of branch
1339 TODO: tg rename
1340 ~~~~~~~~~~~~~~~
1342 IMPLEMENTATION
1343 --------------
1345 TopGit stores all the topic branches in the regular ``refs/heads/``
1346 namespace (so we recommend distinguishing them with the ``t/`` prefix).
1347 Apart from that, TopGit also maintains a set of auxiliary refs in
1348 ``refs/top-*``.  Currently, only ``refs/top-bases/`` is used, containing the
1349 current *base* of the given topic branch -- this is basically a merge of
1350 all the branches the topic branch depends on; it is updated during ``tg
1351 update`` and then merged to the topic branch, and it is the base of a
1352 patch generated from the topic branch by ``tg patch``.
1354 All the metadata is tracked within the source tree and history of the
1355 topic branch itself, in ``.top*`` files; these files are kept isolated
1356 within the topic branches during TopGit-controlled merges and are of
1357 course omitted during ``tg patch``.  The state of these files in base
1358 commits is undefined; look at them only in the topic branches
1359 themselves.  Currently, two files are defined:
1361         ``.topmsg``:
1362             Contains the description of the topic branch in a
1363             mail-like format, plus the author information, whatever
1364             Cc headers you choose or the post-three-dashes message.
1365             When mailing out your patch, basically only a few extra
1366             mail headers are inserted and then the patch itself is
1367             appended.  Thus, as your patches evolve, you can record
1368             nuances like whether the particular patch should have
1369             To-list / Cc-maintainer or vice-versa and similar
1370             nuances, if your project is into that.  ``From`` is
1371             prefilled from your current ``GIT_AUTHOR_IDENT``; other
1372             headers can be prefilled from various optional
1373             ``topgit.*`` git config options.
1375         ``.topdeps``:
1376             Contains the one-per-line list of branches this branch
1377             depends on, pre-seeded by ``tg create``. A (continuously
1378             updated) merge of these branches will be the *base* of
1379             your topic branch.
1381 IMPORTANT: DO NOT EDIT ``.topdeps`` MANUALLY!!! If you do so, you need to
1382 know exactly what you are doing, since this file must stay in sync with
1383 the Git history information, otherwise very bad things will happen.
1385 TopGit also automagically installs a bunch of custom commit-related
1386 hooks that will verify whether you are committing the ``.top*`` files in a
1387 sane state. It will add the hooks to separate files within the ``hooks/``
1388 subdirectory, and merely insert calls to them to the appropriate hooks
1389 and make them executable (but will make sure the original hook's code is
1390 not called if the hook was not executable beforehand).
1392 Another automagically installed piece is a ``.git/info/attributes``
1393 specifier for an ``ours`` merge strategy for the files ``.topmsg`` and
1394 ``.topdeps``, and the (intuitive) ``ours`` merge strategy definition in
1395 ``.git/config``.
1398 REMOTE HANDLING
1399 ---------------
1401 There are two remaining issues with accessing topic branches in remote
1402 repositories:
1404         (i) Referring to remote topic branches from your local repository
1405         (ii) Developing some of the remote topic branches locally
1407 There are two somewhat contradictory design considerations here:
1409         (a) Hacking on multiple independent TopGit remotes in a single
1410             repository
1411         (b) Having a self-contained topic system in local refs space
1413 To us, (a) does not appear to be very convincing, while (b) is quite
1414 desirable for ``git-log topic`` etc. working, and increased conceptual
1415 simplicity.
1417 Thus, we choose to instantiate all the topic branches of given remote
1418 locally; this is performed by ``tg remote --populate``. ``tg update``
1419 will also check if a branch can be updated from its corresponding remote
1420 branch.  The logic needs to be somewhat involved if we are to "do the
1421 right thing".  First, we update the base, handling the remote branch as
1422 if it was the first dependency; thus, conflict resolutions made in the
1423 remote branch will be carried over to our local base automagically.
1424 Then, the base is merged into the remote branch and the result is merged
1425 to the local branch -- again, to carry over remote conflict resolutions.
1426 In the future, this order might be adjustable on a per-update basis, in
1427 case local changes happen to be diverging more than the remote ones.
1429 All commands by default refer to the remote that ``tg remote --populate``
1430 was called on the last time (stored in the ``topgit.remote`` git
1431 configuration variable). You can manually run any command with a
1432 different base remote by passing ``-r REMOTE`` *before* the subcommand
1433 name.
1436 REFERENCES
1437 ----------
1439 The following references are useful to understand the development of
1440 topgit and its subcommands.
1442 * tg depend:
1443   http://lists-archives.org/git/688698-add-list-and-rm-sub-commands-to-tg-depend.html
1446 THIRD-PARTY SOFTWARE
1447 --------------------
1449 The following software understands TopGit branches:
1451 * `magit <http://magit.github.io/>`_ -- a git mode for emacs
1453 IMPORTANT: Magit requires its topgit mode to be enabled first, as
1454 described in its documentation, in the "Activating extensions"
1455 subsection.  If this is not done, it will not push TopGit branches
1456 correctly, so it's important to enable it even if you plan to mostly use
1457 TopGit from the command line.