tg: make sure we're really working with commits
[topgit/pro.git] / README
blob62bcaab415828d8b5d2fea7cac8c0fd3c2a6064b
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.
17 INSTALLATION
18 ------------
20 See the file ``INSTALL``.
23 GIT REPOSITORY
24 --------------
26 The TopGit git repository can be found at <http://repo.or.cz/topgit/pro>.
29 RATIONALE
30 ---------
32 Why not use something like StGIT or Guilt or ``rebase -i`` for maintaining
33 your patch queue?  The advantage of these tools is their simplicity;
34 they work with patch *series* and defer to the reflog facility for
35 version control of patches (reordering of patches is not
36 version-controlled at all).  But there are several disadvantages -- for
37 one, these tools (especially StGIT) do not actually fit well with plain
38 Git at all: it is basically impossible to take advantage of the index
39 effectively when using StGIT.  But more importantly, these tools
40 horribly fail in the face of a distributed environment.
42 TopGit has been designed around three main tenets:
44         (i) TopGit is as thin a layer on top of Git as possible.  You
45         still maintain your index and commit using Git; TopGit will only
46         automate a few indispensable tasks.
48         (ii) TopGit is anxious about *keeping* your history.  It will
49         never rewrite your history, and all metadata is also tracked
50         by Git, smoothly and non-obnoxiously.  It is good to have a
51         *single* point when the history is cleaned up, and that is at
52         the point of inclusion in the upstream project; locally, you
53         can see how your patch has evolved and easily return to older
54         versions.
56         (iii) TopGit is specifically designed to work in a
57         distributed environment.  You can have several instances of
58         TopGit-aware repositories and smoothly keep them all
59         up-to-date and transfer your changes between them.
61 As mentioned above, the main intended use-case for TopGit is tracking
62 third-party patches, where each patch is effectively a single topic
63 branch.  In order to flexibly accommodate even complex scenarios when
64 you track many patches where many are independent but some depend on
65 others, TopGit ignores the ancient Quilt heritage of patch series and
66 instead allows the patches to freely form graphs (DAGs just like Git
67 history itself, only "one level higher").  For now, you have to manually
68 specify which patches the current one depends on, but TopGit might help
69 you with that in the future in a darcs-like fashion.
71 A glossary plug: The union (i.e. merge) of patch dependencies is called
72 a *base* of the patch (topic branch).
74 Of course, TopGit is perhaps not the right tool for you:
76         (i) TopGit is not complicated, but StGIT et al. are somewhat
77         simpler, conceptually.  If you just want to make a linear
78         purely-local patch queue, deferring to StGIT instead might
79         make more sense.
81         (ii) When using TopGit, your history can get a little hairy
82         over time, especially with all the merges rippling through.
83         ;-)
86 SYNOPSIS
87 --------
91         ## Create and evolve a topic branch
92         $ tg create t/gitweb/pathinfo-action
93         tg: Automatically marking dependency on master
94         tg: Creating t/gitweb/pathinfo-action base from master...
95         $ ..hack..
96         $ git commit
97         $ ..fix a mistake..
98         $ git commit
100         ## Create another topic branch on top of the former one
101         $ tg create t/gitweb/nifty-links
102         tg: Automatically marking dependency on t/gitweb/pathinfo-action
103         tg: Creating t/gitweb/nifty-links base from t/gitweb/pathinfo-action...
104         $ ..hack..
105         $ git commit
107         ## Create another topic branch on top of master and submit
108         ## the resulting patch upstream
109         $ tg create t/revlist/author-fixed master
110         tg: Creating t/revlist/author-fixed base from master...
111         $ ..hack..
112         $ git commit
113         $ tg patch -m
114         tg: Sent t/revlist/author-fixed
115         From: pasky@suse.cz
116         To: git@vger.kernel.org
117         Cc: gitster@pobox.com
118         Subject: [PATCH] Fix broken revlist --author when --fixed-string
120         ## Create another topic branch depending on two others non-trivially
121         $ tg create t/whatever t/revlist/author-fixed t/gitweb/nifty-links
122         tg: Creating t/whatever base from t/revlist/author-fixed...
123         tg: Merging t/whatever base with t/gitweb/nifty-links...
124         Merge failed!
125         tg: Please commit merge resolution and call: tg create
126         tg: It is also safe to abort this operation using `git reset --hard`
127         tg: but please remember you are on the base branch now;
128         tg: you will want to switch to a different branch.
129         $ ..resolve..
130         $ git commit
131         $ tg create
132         tg: Resuming t/whatever setup...
133         $ ..hack..
134         $ git commit
136         ## Update a single topic branch and propagate the changes to
137         ## a different one
138         $ git checkout t/gitweb/nifty-links
139         $ ..hack..
140         $ git commit
141         $ git checkout t/whatever
142         $ tg info
143         Topic Branch: t/whatever (1 commit)
144         Subject: [PATCH] Whatever patch
145         Base: 3f47ebc1
146         Depends: t/revlist/author-fixed t/gitweb/nifty-links
147         Needs update from:
148                 t/gitweb/nifty-links (1 commit)
149         $ tg update
150         tg: Updating base with t/gitweb/nifty-links changes...
151         Merge failed!
152         tg: Please commit merge resolution and call `tg update` again.
153         tg: It is also safe to abort this operation using `git reset --hard`,
154         tg: but please remember you are on the base branch now;
155         tg: you will want to switch to a different branch.
156         $ ..resolve..
157         $ git commit
158         $ tg update
159         tg: Updating t/whatever against new base...
160         Merge failed!
161         tg: Please resolve the merge and commit. No need to do anything else.
162         tg: You can abort this operation using `git reset --hard` now
163         tg: and retry this merge later using `tg update`.
164         $ ..resolve..
165         $ git commit
167         ## Update a single topic branch and propagate the changes
168         ## further through the dependency chain
169         $ git checkout t/gitweb/pathinfo-action
170         $ ..hack..
171         $ git commit
172         $ git checkout t/whatever
173         $ tg info
174         Topic Branch: t/whatever (1/2 commits)
175         Subject: [PATCH] Whatever patch
176         Base: 0ab2c9b3
177         Depends: t/revlist/author-fixed t/gitweb/nifty-links
178         Needs update from:
179                 t/gitweb/pathinfo-action (<= t/gitweb/nifty-links) (1 commit)
180         $ tg update
181         tg: Recursing to t/gitweb/nifty-links...
182         [t/gitweb/nifty-links] tg: Updating base with t/gitweb/pathinfo-action changes...
183         Merge failed!
184         [t/gitweb/nifty-links] tg: Please commit merge resolution and call `tg update` again.
185         [t/gitweb/nifty-links] tg: It is also safe to abort this operation using `git reset --hard`,
186         [t/gitweb/nifty-links] tg: but please remember you are on the base branch now;
187         [t/gitweb/nifty-links] tg: you will want to switch to a different branch.
188         [t/gitweb/nifty-links] tg: You are in a subshell. If you abort the merge,
189         [t/gitweb/nifty-links] tg: use `exit` to abort the recursive update altogether.
190         [t/gitweb/nifty-links] $ ..resolve..
191         [t/gitweb/nifty-links] $ git commit
192         [t/gitweb/nifty-links] $ tg update
193         [t/gitweb/nifty-links] tg: Updating t/gitweb/nifty-links against new base...
194         Merge failed!
195         [t/gitweb/nifty-links] tg: Please resolve the merge and commit.
196         [t/gitweb/nifty-links] tg: You can abort this operation using `git reset --hard`.
197         [t/gitweb/nifty-links] tg: You are in a subshell. After you either commit or abort
198         [t/gitweb/nifty-links] tg: your merge, use `exit` to proceed with the recursive update.
199         [t/gitweb/nifty-links] $ ..resolve..
200         [t/gitweb/nifty-links] $ git commit
201         [t/gitweb/nifty-links] $ exit
202         tg: Updating base with t/gitweb/nifty-links changes...
203         tg: Updating t/whatever against new base...
205         ## Clone a TopGit-controlled repository
206         $ git clone URL repo
207         $ cd repo
208         $ tg remote --populate origin
209         ...
210         $ git fetch
211         $ tg update
213         ## Add a TopGit remote to a repository and push to it
214         $ git remote add foo URL
215         $ tg remote foo
216         $ tg push -r foo
218         ## Update from a non-default TopGit remote
219         $ git fetch foo
220         $ tg -r foo summary
221         $ tg -r foo update
224 USAGE
225 -----
226 ``tg [-C <dir>] [-r <remote> | -u] [-c <name>=<val>] <subcommand> [<subcommand option/argument>...]``
228         -C <dir>        Change directory to <dir> before doing anything
229         -r <remote>     Pretend ``topgit.remote`` is set to <remote>
230         -u              Pretend ``topgit.remote`` is not set
231         -c <name=val>   Pass config option to git, may be repeated
233 The ``tg`` tool has several subcommands:
235 tg help
236 ~~~~~~~
237         Our sophisticated integrated help facility.  Mostly duplicates
238         what is below::
240          # to list commands:
241          $ tg help
242          # to get help for a particular command:
243          $ tg help <command>
244          # to get help for a particular command in a browser window:
245          $ tg help -w <command>
246          # to get help on TopGit itself
247          $ tg help tg
248          # to get help on TopGit itself in a browser
249          $ tg help -w tg
251 tg create
252 ~~~~~~~~~
253         Create a new TopGit-controlled topic branch of the given name
254         (required argument) and switch to it.  If no dependencies are
255         specified (by extra arguments passed after the first one), the
256         current branch is assumed to be the only dependency.
258         By default ``tg create`` opens an editor on the new ``.topmsg`` file
259         and then commits the new ``.topmsg`` and ``.topdeps`` files
260         automatically with a suitable default commit message.  The commit
261         message can be changed with the ``-m`` (or ``--message``) or ``-F``
262         (or ``--file``) option.  The automatic commit can be suppressed by
263         using the ``--no-ccmmit`` option.  Running the editor on the new
264         ``.topmsg`` file can be suppressed by using ``-n`` (or ``--no-edit``)
265         which also suppresses the automatic commit.  If more than one
266         dependency is listed, the automatic commit will not take place until
267         AFTER all the listed dependencies have been merged into a base commit
268         which may require some manual merge resolutions if there are conflicts.
270         Previous versions of TopGit behaved as though the ``--no-edit`` option
271         was always given on the command line.
273         The default behavior has been changed to promote a separation between
274         commits that modify ``.topmsg`` and/or ``.topdeps`` and commits that
275         modify other files.  This facilitates cleaner cherry picking and other
276         patch maintenance activities.
278         You should edit the patch description (contained in the ``.topmsg``
279         file) as appropriate.  It will already contain some prefilled bits.
280         You can set the ``topgit.to``, ``topgit.cc`` and ``topgit.bcc``
281         git configuration variables (see ``man git-config``) in order to
282         have ``tg create`` add these headers with the given default values
283         to ``.topmsg`` before invoking the editor.
285         The main task of ``tg create`` is to set up the topic branch base
286         from the dependencies.  This may fail due to merge conflicts.
287         In that case, after you commit the conflict resolution, you
288         should call ``tg create`` again (without any arguments or with the
289         single argument ``--continue``); it will then detect that you are on a
290         topic branch base ref and resume the topic branch creation operation.
292         In an alternative use case, if ``-r <branch>`` is given instead of a
293         dependency list, the topic branch is created based on the given
294         remote branch.  With just ``-r`` the remote branch name is assumed
295         to be the same as the local topic branch being created.  Since no
296         new commits are created in this mode (only two refs will be updated)
297         the editor will never be run for this use case.
299 tg delete
300 ~~~~~~~~~
301         Remove a TopGit-controlled topic branch of the given name
302         (required argument). Normally, this command will remove only an
303         empty branch (base == head) without dependendents; use ``-f`` to
304         remove a non-empty branch or a branch that is depended upon by
305         another branch.
307         The ``-f`` option is also useful to force removal of a branch's
308         base, if you used ``git branch -D B`` to remove branch B, and then
309         certain TopGit commands complain, because the base of branch B
310         is still there.
312         IMPORTANT: Currently, this command will *NOT* remove the branch
313         from the dependency list in other branches. You need to take
314         care of this *manually*.  This is even more complicated in
315         combination with ``-f`` -- in that case, you need to manually
316         unmerge the removed branch's changes from the branches depending
317         on it.
319         See also ``tg annihilate``.
321         | TODO: ``-a`` to delete all empty branches, depfix, revert
323 tg annihilate
324 ~~~~~~~~~~~~~
325         Make a commit on the current TopGit-controlled topic branch
326         that makes it equal to its base, including the presence or
327         absence of .topmsg and .topdeps.  Annihilated branches are not
328         displayed by ``tg summary``, so they effectively get out of your
329         way.  However, the branch still exists, and ``tg push`` will
330         push it (except if given the ``-a`` option).  This way, you can
331         communicate that the branch is no longer wanted.
333         When annihilating a branch that has dependents (i.e. branches
334         that depend on it), those dependents have the dependencies of
335         the branch being annihilated added to them if they do not already
336         have them as dependencies.  Essentially the DAG is repaired to
337         skip over the annihilated branch.
339         Normally, this command will remove only an empty branch
340         (base == head, except for changes to the .top* files); use
341         ``-f`` to annihilate a non-empty branch.
343 tg depend
344 ~~~~~~~~~
345         Change the dependencies of a TopGit-controlled topic branch.
346         This should have several subcommands, but only ``add`` is
347         supported right now.
349         The ``add`` subcommand takes an argument naming a topic branch to
350         be added, adds it to ``.topdeps``, performs a commit and then
351         updates your topic branch accordingly.  If you want to do other
352         things related to the dependency addition, like adjusting
353         ``.topmsg``, prepare them in the index before calling ``tg depend
354         add``.
356         You have enabled ``git rerere`` haven't you?
358         | TODO: Subcommand for removing dependencies, obviously
360 tg files
361 ~~~~~~~~
362         List files changed by the current or specified topic branch.
364         Options:
365           -i            list files based on index instead of branch
366           -w            list files based on working tree instead of branch
368 tg info
369 ~~~~~~~
370         Show summary information about the current or specified topic
371         branch.
373         Numbers in parenthesis after a branch name such as "(11/3 commits)"
374         indicate how many commits on the branch (11) and how many of those
375         are non-merge commits (3).
377 tg patch
378 ~~~~~~~~
379         Generate a patch from the current or specified topic branch.
380         This means that the diff between the topic branch base and head
381         (latest commit) is shown, appended to the description found in
382         the ``.topmsg`` file.
384         The patch is simply dumped to stdout.  In the future, ``tg patch``
385         will be able to automatically send the patches by mail or save
386         them to files. (TODO)
388         Options:
389           -i            base patch generation on index instead of branch
390           -w            base patch generation on working tree instead of branch
391           --binary      pass --binary to ``git diff-tree`` to enable generation
392                         of binary patches
393           --diff-opt    options after the branch name (and an optional ``--``)
394                         are passed directly to ``git diff-tree``
396         In order to pass a sole explicit ``-w`` through to ``git diff-tree`` it
397         must be separated from the ``tg`` options by an explicit ``--``.
398         Or it can be spelled as ``--ignore-all-space`` to distinguuish it from
399         ``tg``'s ``-w`` option.
401         If additional non-``tg`` options are passed through to
402         ``git diff-tree`` (other than ``--binary`` which is fully supported)
403         the resulting ``tg patch`` output may not be appliable.
405 tg mail
406 ~~~~~~~
407         Send a patch from the current or specified topic branch as
408         email(s).
410         Takes the patch given on the command line and emails it out.
411         Destination addresses such as To, Cc and Bcc are taken from the
412         patch header.
414         Since it actually boils down to ``git send-email``, please refer
415         to the documentation for that for details on how to setup email
416         for git.  You can pass arbitrary options to this command through
417         the ``-s`` parameter, but you must double-quote everything.  The
418         ``-r`` parameter with a msgid can be used to generate in-reply-to
419         and reference headers to an earlier mail.
421         WARNING: be careful when using this command.  It easily sends
422         out several mails.  You might want to run::
424                 git config sendemail.confirm always
426         to let ``git send-email`` ask for confirmation before sending any
427         mail.
429         Options:
430           -i            base patch generation on index instead of branch
431           -w            base patch generation on working tree instead of branch
433         | TODO: ``tg mail patchfile`` to mail an already exported patch
434         | TODO: mailing patch series
435         | TODO: specifying additional options and addresses on command line
437 tg remote
438 ~~~~~~~~~
439         Register the given remote as TopGit-controlled. This will create
440         the namespace for the remote branch bases and teach ``git fetch``
441         to operate on them. However, from TopGit 0.8 onwards you need to
442         use ``tg push``, or ``git push --mirror``, for pushing
443         TopGit-controlled branches.
445         ``tg remote`` takes an optional remote name argument, and an
446         optional ``--populate`` switch.  Use ``--populate`` for your
447         origin-style remotes: it will seed the local topic branch system
448         based on the remote topic branches.  ``--populate`` will also make
449         ``tg remote`` automatically fetch the remote, and ``tg update`` look
450         at branches of this remote for updates by default.
452         Using ``--populate`` with a remote name causes the ``topgit.remote``
453         git configuration variable to be set to the given remote name.
455 tg summary
456 ~~~~~~~~~~
457         Show overview of all TopGit-tracked topic branches and their
458         up-to-date status.  With a branch name limit output to that branch.
459         Using ``--deps-only`` or ``--rdeps`` changes the default from all
460         branches to just the current ``HEAD`` branch but using ``--all`` as
461         the branch name will show results for all branches instead of ``HEAD``.
463                 ``>``
464                         marks the current topic branch
466                 ``0``
467                         indicates that it introduces no changes of its own
469                 ``l``/``r``
470                         indicates respectively whether it is local-only
471                         or has a remote mate
473                 ``L``/``R``
474                         indicates respectively if it is ahead or out-of-date
475                         with respect to its remote mate
477                 ``D``
478                         indicates that it is out-of-date with respect to its
479                         dependencies
481                 ``!``
482                         indicates that it has missing dependencies [even if
483                         they are recursive ones]
485                 ``B``
486                         indicates that it is out-of-date with respect to
487                         its base
489         This can take a long time to accurately determine all the
490         relevant information about each branch; you can pass ``-t`` to get
491         just a terse list of topic branch names quickly.  Alternately,
492         you can pass ``--graphviz`` to get a dot-suitable output to draw a
493         dependency graph between the topic branches.
495         You can also use the ``--sort`` option to sort the branches using
496         a topological sort.  This is especially useful if each
497         TopGit-tracked topic branch depends on a single parent branch,
498         since it will then print the branches in the dependency order.
499         In more complex scenarios, a text graph view would be much more
500         useful, but that has not yet been implemented.
502         The ``--deps`` option outputs dependency information between
503         branches in a machine-readable format.  Feed this to ``tsort`` to
504         get the output from --sort.
506         The ``--deps-only`` option outputs a sorted list of the unique branch
507         names given on the command line plus all of their recursive dependents
508         (subject to ``--exclude`` of course).  When ``--deps-only`` is given
509         the default is to just display information for ``HEAD``, but that can
510         be changed by using ``--all`` as the branch name.  Each branch name
511         will appear only once in the output no matter how many times it's
512         visited while tracing the dependency graph or how many branch names are
513         given on the command line to process.
515         The ``--rdeps`` option outputs dependency information in an indented
516         text format that clearly shows all the dependencies and their
517         relationships to one another.  When ``--rdeps`` is given the default is
518         to just display information for ``HEAD``, but that can be changed by
519         using ``--all`` as the branch name.
521         With ``--exclude branch``, branch can be excluded from the output
522         meaning it will be skipped and its name will be omitted from any
523         dependency output.  The ``--exclude`` option may be repeated to omit
524         more than one branch from the output.  Limiting the output to a single
525         branch that has been excluded will result in no output at all.
527         Note that the branch name can be specified as ``HEAD`` as a shortcut for
528         the TopGit-controlled branch that ``HEAD`` is a symbolic ref to.
530         Options:
531           -i            Use TopGit metadata from the index instead of the branch
532           -w            Use TopGit metadata from the working tree instead of the branch
535 tg checkout
536 ~~~~~~~~~~~
537         Switch to a topic branch.  You can use ``git checkout <branch>``
538         to get the same effect, but this command helps you navigate
539         the dependency graph, or allows you to match the topic branch
540         name using a regular expression, so it can be more convenient.
542         There following subcommands are available:
544             ``tg checkout push``
545                                 Check out a branch that directly
546                                 depends on your current branch.
548             ``tg checkout pop``
549                                 Check out a branch that this branch
550                                 directly depends on.
552             ``tg checkout goto <pattern>``
553                                 Check out a topic branch that
554                                 matches ``<pattern>``.  ``<pattern>``
555                                 is used as a sed pattern to filter
556                                 all the topic branches.
558             ``tg checkout next``
559                                 An alias for ``push``.
561             ``tg checkout child``
562                                 An alias for ``push``.
564             ``tg checkout``
565                                 An alias for ``push``.
567             ``tg checkout prev``
568                                 An alias for ``pop``.
570             ``tg checkout parent``
571                                 An alias for ``pop``.
573             ``tg checkout ..``
574                                 An alias for ``pop``.
576         If any of the above commands can find more than one possible
577         branch to switch to, you will be presented with the matches
578         and asked to select one of them.
580         The ``<pattern>`` of ``tg checkout goto`` is optional.  If you don't
581         supply it, all the available topic branches are listed and you
582         can select one of them.
584         Normally, the ``push`` and ``pop`` commands moves one step in
585         the dependency graph of the topic branches.  The ``-a`` option
586         causes them (and their aliases) to move as far as possible.
587         That is, ``tg checkout push -a`` moves to a topic branch that
588         depends (directly or indirectly) on the current branch and
589         that no other branch depends on.  ``tg checkout pop -a``
590         moves to a regular branch that the current topic branch
591         depends on (directly or indirectly).  If there is more than
592         one possibility, you will be prompted for your selection.
594 tg export
595 ~~~~~~~~~
596         Export a tidied-up history of the current topic branch and its
597         dependencies, suitable for feeding upstream.  Each topic branch
598         corresponds to a single commit or patch in the cleaned up
599         history (corresponding basically exactly to ``tg patch`` output
600         for the topic branch).
602         The command has three possible outputs now -- either a Git branch
603         with the collapsed history, a Git branch with a linearized
604         history, or a quilt series in new directory.
606         In the case where you are producing collapsed history in a new
607         branch, you can use this collapsed structure either for
608         providing a pull source for upstream, or for further
609         linearization e.g. for creation of a quilt series using git log::
611                 git log --pretty=email -p --topo-order origin..exported
613         To better understand the function of ``tg export``, consider this
614         dependency structure::
616          origin/master - t/foo/blue - t/foo/red - master
617                       `- t/bar/good <,----------'
618                       `- t/baz      ------------'
620         (where each of the branches may have a hefty history). Then::
622          master$ tg export for-linus
624         will create this commit structure on the branch ``for-linus``::
626          origin/master - t/foo/blue -. merge - t/foo/red -.. merge - master
627                       `- t/bar/good <,-------------------'/
628                       `- t/baz      ---------------------'
630         In this mode, ``tg export`` works on the current topic branch, and
631         can be called either without an option (in that case,
632         ``--collapse`` is assumed), or with the ``--collapse`` option, and
633         with one mandatory argument: the name of the branch where the
634         exported result will be stored.
636         When using the linearize mode::
638          master$ tg export --linearize for-linus
640         you get a linear history respecting the dependencies of your
641         patches in a new branch ``for-linus``.  The result should be more
642         or less the same as using quilt mode and then reimporting it
643         into a Git branch.  (More or less because the topological order
644         can usually be extended in more than one way into a total order,
645         and the two methods may choose different ones.)  The result
646         might be more appropriate for merging upstream, as it contains
647         fewer merges.
649         Note that you might get conflicts during linearization because
650         the patches are reordered to get a linear history.  If linearization
651         would produce conflicts then using ``--quilt`` will also likely result
652         in conflicts when the exported quilt series is applied.  Since the
653         ``--quilt`` mode simply runs a series of ``tg patch`` commands to
654         generate the patches in the exported quilt series and those patches
655         will end up being applied linearly, the same conflicts that would be
656         produced by the ``--linearize`` option will then occur at that time.
658         To avoid conflicts produced by ``--linearize`` (or by applying the
659         ``--quilt`` output), use the default ``--collapse`` mode and then use
660         ``tg rebase`` (or ``git rebase -m`` directly) on the collapsed branch
661         (with a suitable <upstream>) followed by ``git format-patch`` on the
662         rebased result to produce a conflict-free patch set.
664         You have enabled ``git rerere`` haven't you?
666         When using the quilt mode::
668          master$ tg export --quilt for-linus
670         would create the following directory ``for-linus``::
672          for-linus/t/foo/blue.diff
673          for-linus/t/foo/red.diff
674          for-linus/t/bar/good.diff
675          for-linus/t/baz.diff
676          for-linus/series:
677                 t/foo/blue.diff -p1
678                 t/bar/good.diff -p1
679                 t/foo/red.diff -p1
680                 t/baz.diff -p1
682         With ``--quilt``, you can also pass the ``-b`` parameter followed
683         by a comma-separated explicit list of branches to export, or
684         the ``--all`` parameter (which can be shortened to ``-a``) to
685         export them all.  The ``--binary`` option enables producing Git
686         binary patches.  These options are currently only supported
687         with ``--quilt``.
689         In ``--quilt`` mode the patches are named like the originating
690         topgit branch.  So usually they end up in subdirectories of the
691         output directory.  With the ``--flatten`` option the names are
692         mangled so that they end up directly in the output dir (slashes
693         are replaced with underscores).  With the ``--strip[=N]`` option
694         the first ``N`` subdirectories (all if no ``N`` is given) get
695         stripped off.  Names are always ``--strip``'d before being
696         ``--flatten``'d.  With the option ``--numbered`` (which implies
697         ``--flatten``) the patch names get a number as prefix to allow
698         getting the order without consulting the series file, which
699         eases sending out the patches.
701         | TODO: Make stripping of non-essential headers configurable
702         | TODO: Make stripping of [PATCH] and other prefixes configurable
703         | TODO: ``--mbox`` option to export instead as an mbox file
704         | TODO: support ``--all`` option in other modes of operation
705         | TODO: For quilt exporting, export the linearized history created in
706                 a temporary branch--this would allow producing conflict-less
707                 series
709 tg import
710 ~~~~~~~~~
711         Import commits within the given revision range into TopGit,
712         creating one topic branch per commit. The dependencies are set
713         up to form a linear sequence starting on your current branch --
714         or a branch specified by the ``-d`` parameter, if present.
716         The branch names are auto-guessed from the commit messages and
717         prefixed by ``t/`` by default; use ``-p <prefix>`` to specify an
718         alternative prefix (even an empty one).
720         Alternatively, you can use the ``-s NAME`` parameter to specify
721         the name of the target branch; the command will then take one
722         more argument describing a *single* commit to import.
724 tg update
725 ~~~~~~~~~
726         Update the current, specified or all topic branches with respect
727         to changes in the branches they depend on and remote branches.
728         This is performed in two phases -- first, changes within the
729         dependencies are merged to the base, then the base is merged
730         into the topic branch.  The output will guide you on what to do
731         next in case of conflicts.
733         You have enabled ``git rerere`` haven't you?
735         When ``-a`` (or ``--all``) is specifed, updates all topic branches
736         matched by ``<pattern>``'s (see ``git-for-each-ref(1)`` for details),
737         or all if no ``<pattern>`` is given.  Any topic branches with missing
738         dependencies will be skipped entirely unless ``--skip`` is specified.
740         When ``--skip`` is specifed, an attempt is made to update topic
741         branches with missing dependencies by skipping only the dependencies
742         that are missing.  Caveat utilitor.
744         After the update, if a single topic branch was specified, it is
745         left as the current one; if ``-a`` was specified, it returns to
746         the branch which was current at the beginning.
748         If your dependencies are not up-to-date, ``tg update`` will first
749         recurse into them and update them.
751         If a remote branch update brings in dependencies on branches
752         that are not yet instantiated locally, you can either bring in
753         all the new branches from the remote using ``tg remote
754         --populate``, or only pick out the missing ones using ``tg create
755         -r`` (``tg summary`` will point out branches with incomplete
756         dependencies by showing an ``!`` next to them).
758         | TODO: ``tg update -a -c`` to autoremove (clean) up-to-date branches
760 tg push
761 ~~~~~~~
762         If ``-a`` or ``--all`` was specified, pushes all non-annihilated
763         TopGit-controlled topic branches, to a remote repository.
764         Otherwise, pushes the specified topic branches -- or the
765         current branch, if you don't specify which.  By default, the
766         remote gets all the dependencies (both TopGit-controlled and
767         non-TopGit-controlled) and bases pushed to it too.  If
768         ``--tgish-only`` was specified, only TopGit-controlled
769         dependencies will be pushed, and if ``--no-deps`` was specified,
770         no dependencies at all will be pushed.
772         The ``--dry-run`` and ``--force`` options are passed directly to
773         ``git push`` if given.
775         The remote may be specified with the ``-r`` option. If no remote
776         was specified, the configured default TopGit remote will be
777         used.
779 tg base
780 ~~~~~~~
781         Prints the base commit of each of the named topic branches, or
782         the current branch if no branches are named.  Prints an error
783         message and exits with exit code 1 if the named branch is not
784         a TopGit branch.
786 tg log
787 ~~~~~~
788         Prints the git log of the named topgit branch -- or the current
789         branch, if you don't specify a name.
791         NOTE: if you have merged changes from a different repository, this
792         command might not list all interesting commits.
794 tg tag
795 ~~~~~~
796         Creates a TopGit annotated/signed tag or lists the reflog of one.
798         A TopGit annotated tag records the current state of one or more TopGit
799         branches and their dependencies and may be used to revert to the tagged
800         state at any point in the future.
802         When reflogs are enabled (the default in a non-bare repository) and
803         combined with the ``--force`` option a single tag name may be used as a
804         sort of TopGit branch state stash.  The special branch name ``--all``
805         may be used to tag the state of all current TopGit branches to
806         facilitate this function and has the side-effect of surpressing the
807         out-of-date check allowing out-of-date branches to be included.
809         As a special feature, ``--stash`` may be used as the tag name in which
810         case ``--all`` is implied if no branch name is listed (instead of the
811         normal default of ``HEAD``), ``--force`` and ``--no-edit`` (use
812         ``--edit`` to change that) are automatically activated and the tag will
813         be saved to ``refs/tgstash`` instead of ``refs/tags/<tagname>``.
814         The ``--stash`` tag name may also be used with the ``-g``/``--reflog``
815         option.
817         A TopGit annotated/signed tag is simply a Git annotated/signed tag with
818         a "TOPGIT REFS" section appended to the end of the tag message (and
819         preceding the signature for signed tags).  PEM-style begin and end
820         lines surround one line per ref where the format of each line is
821         full-hash SP ref-name.  A line will be included for each branch given
822         on the command line and each ref they depend on either directly or
823         indirectly.
825         If more than one TopGit branch is given on the command line, a new
826         commit will be created that has an empty tree and all of the given
827         TopGit branches as parents and that commit will be tagged.  If a single
828         TopGit branch is given, then it will be tagged.
830         All the options for creating a tag serve the same purpose as their Git
831         equivalents except for two.  The ``--refs`` option suppresses tag
832         creation entirely and emits the "TOPGIT REFS" section that would have
833         been included with the tag.  If the ``--no-edit`` option is given and
834         no message is supplied (via the ``-m`` or ``-F`` option) then the
835         default message created by TopGit will be used without running the
836         editor.
838         With ``-g`` or ``--reflog`` show the reflog for a tag.  Unlike
839         ``git log -g``, ``tg tag --reflog`` normally shows the message from the
840         tag (if a tag) or the commit (if a commit) if available rather than
841         the message from the reflog itself.  With ``--reflog-message`` only
842         show the message (if any) from the reflog.  Non-tag entries are
843         annotated with their type unless ``--no-type`` is given.  TopGit tags
844         are created with a reflog if core.logallrefupdates is enabled (the
845         default for non-bare repositories).  Unfortunately Git is incapable
846         of showing a tag's reflog (using git log -g) as it will first resolve
847         the tag before checking to see if it has a reflog.  Git can, however,
848         show reflogs for lightweight tags (using git log -g) just fine but
849         that's not helpful here.  Use the ``-g`` or ``--reflog`` option to see
850         the reflog for an actual tag object.  This also works on non-TopGit
851         annotated/signed tags as well provided they have a reflog.  The number
852         of entries shown may be limited with the ``-n`` option.  If the tagname
853         is omitted then ``--stash`` is assumed and ``--reflog-message`` will
854         be implied (use ``--no-reflog-message`` to change that).
856 tg rebase
857 ~~~~~~~~~
858         Provides a ``git rebase`` rerere auto continue function.  It may be
859         used as a drop-in replacement front-end for ``git rebase -m`` that
860         automatically continues the rebase when ``git rerere`` information is
861         sufficient to resolve all conflicts.
863         You have enabled ``git rerere`` haven't you?
865         If the ``-m`` or ``--merge`` option is not present then ``tg rebase``
866         will complain and not do anything.
868         When ``git rerere`` is enabled, previously resolved conflicts are
869         remembered and can be automatically staged (see ``rerere.autoUpdate``).
871         However, even with auto staging, ``git rebase`` still stops and
872         requires an explicit ``git rebase --continue`` to keep going.
874         In the case where ``git rebase -m`` is being used to flatten history
875         (such as after a ``tg export --collapse`` prior to a
876         ``git format-patch``), there's a good chance all conflicts have already
877         been resolved during normal merge maintenance operations so there's no
878         reason ``git rebase`` could not automatically continue, but there's no
879         option to make it do so.
881         The ``tg rebase`` command provides a ``git rebase --auto-continue``
882         function.
884         All the same rebase options can be used (they are simply passed through
885         to Git unchanged).  However, the ``rerere.autoUpdate`` option is
886         automatically temporarily enabled while running ``git rebase`` and
887         should ``git rebase`` stop asking one to resolve and continue, but all
888         conflicts have already been resolved and staged using rerere
889         information, then ``git rebase --continue`` will be automatically run.
891 tg revert
892 ~~~~~~~~~
893         Provides the ability to revert one or more TopGit branches and their
894         dependents to a previous state contained within a tag created using the
895         ``tg tag`` command.  In addition to the actual revert mode operation a
896         list mode operation is also provided to examine a tag's ref contents.
898         The default mode (``-l`` or ``--list``) shows the state of one or more
899         of the refs/branches stored in the tag data.  When no refs are given on
900         the command line, all refs in the tag data are shown.  With the special
901         ref name ``--heads`` then the indepedent heads contained in the tag
902         data are shown.  The ``--deps`` option shows the specified refs and all
903         of their dependents in single list with no duplicates.  The ``--rdeps``
904         option shows a display similar to ``tg summary --rdeps`` for each ref
905         or all independent heads if no ref is given on the command line.
907         The revert mode has three submodes, dry-run mode (``-n`` or
908         ``--dry-run``), force mode (``-f`` or ``--force``) and interactive mode
909         (``-i`` or ``--interactive``).  If ``--dry-run`` (or ``-n``) is given
910         no ref updates will actually be performed but what would have been
911         updated is shown instead.  If ``--interactive`` (or ``-i``) is given
912         then the editor is invoked on an instruction sheet allowing manual
913         selection of the refs to be updated before proceeding.  Since revert is
914         potentially a destructive operation, at least one of the submodes must
915         be specified explicitly.  If no refs are listed on the command line
916         then all refs in the tag data are reverted.  Otherwise the listed refs
917         and all of their dependents (unless ``--no-deps`` is given) are
918         reverted.  Unless ``--no-stash`` is given a new stash will be created
919         using ``tg tag --stash`` (except, of course, in dry-run mode) just
920         before actually performing the updates to facilitate recovery from
921         accidents.
923         Both modes accept fully-qualified (i.e. starts with ``refs/``) ref
924         names as well as unqualified names (which will be assumed to be located
925         under ``refs/heads/``).  In revert mode a tgish ref will always have
926         both its ``refs/heads/`` and ``refs/top-bases/`` values included no
927         matter how it's listed unless ``--no-deps`` is given and the ref is
928         fully qualified (i.e. starts with ``refs/``) or one or the other of its
929         values was removed from the instruction sheet in interactive mode.  In
930         list mode a tgish ref will always have both its ``refs/heads/`` and
931         ``refs/top-bases/`` values included only when using the ``--deps`` or
932         ``--rdeps`` options.
934         The ``--tgish-only`` option excludes non-tgish refs (i.e. refs that do
935         not have a ``refs/heads/<name>``, ``refs/top-bases/<name>`` pair).
937         The ``--exclude`` option (which can be repeated) excludes specific
938         refs.  If the name given to ``--exclude`` is not fully-qualified (i.e.
939         starts with ``refs/``) then it will exclude both members of a tgish ref
940         pair.
942         The ``--quiet`` (or ``-q``) option may be used in revert mode to
943         suppress non-dry-run ref change status messages.
945         The special tag name ``--stash`` (as well as with ``@{n}`` suffixes)
946         can be used to refer to ``refs/tgstash``.
948         NOTE:  If HEAD points to a ref that is updated by a revert operation
949         then NO WARNING whatsoever will be issued, but the index and working
950         tree will always be left completely untouched (and the reflog for
951         the pointed-to ref can always be used to find the previous value).
953 tg prev
954 ~~~~~~~
955         Outputs the direct dependencies for the current or named branch.
957         Options:
958           -i            show dependencies based on index instead of branch
959           -w            show dependencies based on working tree instead of branch
961 tg next
962 ~~~~~~~
963         Outputs all branches which directly depend on the current or
964         named branch.
966         Options:
967           -i            show dependencies based on index instead of branch
968           -w            show dependencies based on working tree instead of branch
970 TODO: tg rename
971 ~~~~~~~~~~~~~~~
973 IMPLEMENTATION
974 --------------
976 TopGit stores all the topic branches in the regular ``refs/heads/``
977 namespace (so we recommend distinguishing them with the ``t/`` prefix).
978 Apart from that, TopGit also maintains a set of auxiliary refs in
979 ``refs/top-*``.  Currently, only ``refs/top-bases/`` is used, containing the
980 current *base* of the given topic branch -- this is basically a merge of
981 all the branches the topic branch depends on; it is updated during ``tg
982 update`` and then merged to the topic branch, and it is the base of a
983 patch generated from the topic branch by ``tg patch``.
985 All the metadata is tracked within the source tree and history of the
986 topic branch itself, in ``.top*`` files; these files are kept isolated
987 within the topic branches during TopGit-controlled merges and are of
988 course omitted during ``tg patch``.  The state of these files in base
989 commits is undefined; look at them only in the topic branches
990 themselves.  Currently, two files are defined:
992         ``.topmsg``:
993             Contains the description of the topic branch in a
994             mail-like format, plus the author information, whatever
995             Cc headers you choose or the post-three-dashes message.
996             When mailing out your patch, basically only a few extra
997             mail headers are inserted and then the patch itself is
998             appended.  Thus, as your patches evolve, you can record
999             nuances like whether the particular patch should have
1000             To-list / Cc-maintainer or vice-versa and similar
1001             nuances, if your project is into that.  ``From`` is
1002             prefilled from your current ``GIT_AUTHOR_IDENT``; other
1003             headers can be prefilled from various optional
1004             ``topgit.*`` git config options.
1006         ``.topdeps``:
1007             Contains the one-per-line list of branches this branch
1008             depends on, pre-seeded by `tg create`. A (continuously
1009             updated) merge of these branches will be the *base* of
1010             your topic branch.
1012 IMPORTANT: DO NOT EDIT ``.topdeps`` MANUALLY!!! If you do so, you need to
1013 know exactly what are you doing, since this file must stay in sync with
1014 the Git history information, otherwise very bad things will happen.
1016 TopGit also automagically installs a bunch of custom commit-related
1017 hooks that will verify whether you are committing the ``.top*`` files in a
1018 sane state. It will add the hooks to separate files within the ``hooks/``
1019 subdirectory, and merely insert calls to them to the appropriate hooks
1020 and make them executable (but will make sure the original hook's code is
1021 not called if the hook was not executable beforehand).
1023 Another automagically installed piece is a ``.git/info/attributes``
1024 specifier for an ``ours`` merge strategy for the files ``.topmsg`` and
1025 ``.topdeps``, and the (intuitive) ``ours`` merge strategy definition in
1026 ``.git/config``.
1029 REMOTE HANDLING
1030 ---------------
1032 There are two remaining issues with accessing topic branches in remote
1033 repositories:
1035         (i) Referring to remote topic branches from your local repository
1036         (ii) Developing some of the remote topic branches locally
1038 There are two somewhat contradictory design considerations here:
1040         (a) Hacking on multiple independent TopGit remotes in a single
1041             repository
1042         (b) Having a self-contained topic system in local refs space
1044 To us, (a) does not appear to be very convincing, while (b) is quite
1045 desirable for ``git-log topic`` etc. working, and increased conceptual
1046 simplicity.
1048 Thus, we choose to instantiate all the topic branches of given remote
1049 locally; this is performed by ``tg remote --populate``. ``tg update``
1050 will also check if a branch can be updated from its corresponding remote
1051 branch.  The logic needs to be somewhat involved if we are to "do the
1052 right thing".  First, we update the base, handling the remote branch as
1053 if it was the first dependency; thus, conflict resolutions made in the
1054 remote branch will be carried over to our local base automagically.
1055 Then, the base is merged into the remote branch and the result is merged
1056 to the local branch -- again, to carry over remote conflict resolutions.
1057 In the future, this order might be adjustable on a per-update basis, in
1058 case local changes happen to be diverging more than the remote ones.
1060 All commands by default refer to the remote that ``tg remote --populate``
1061 was called on the last time (stored in the ``topgit.remote`` git
1062 configuration variable). You can manually run any command with a
1063 different base remote by passing ``-r REMOTE`` *before* the subcommand
1064 name.
1067 REFERENCES
1068 ----------
1070 The following references are useful to understand the development of
1071 topgit and its subcommands.
1073 * tg depend:
1074   http://lists-archives.org/git/688698-add-list-and-rm-sub-commands-to-tg-depend.html
1077 THIRD-PARTY SOFTWARE
1078 --------------------
1080 The following software understands TopGit branches:
1082 * `magit <http://magit.github.io/>`_ -- a git mode for emacs
1084 IMPORTANT: Magit requires its topgit mode to be enabled first, as
1085 described in its documentation, in the "Activating extensions"
1086 subsection.  If this is not done, it will not push TopGit branches
1087 correctly, so it's important to enable it even if you plan to mostly use
1088 TopGit from the command line.