scripts: use more portable export
[topgit/pro.git] / README
blobdd5d2240c7ac038e5293a4f24f48280d8c3acb39
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] <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
232 The ``tg`` tool has several subcommands:
234 tg help
235 ~~~~~~~
236         Our sophisticated integrated help facility.  Mostly duplicates
237         what is below::
239          # to list commands:
240          $ tg help
241          # to get help for a particular command:
242          $ tg help <command>
243          # to get help for a particular command in a browser window:
244          $ tg help -w <command>
245          # to get help on TopGit itself
246          $ tg help tg
247          # to get help on TopGit itself in a browser
248          $ tg help -w tg
250 tg create
251 ~~~~~~~~~
252         Create a new TopGit-controlled topic branch of the given name
253         (required argument) and switch to it.  If no dependencies are
254         specified (by extra arguments passed after the first one), the
255         current branch is assumed to be the only dependency.
257         After ``tg create``, you should insert the patch description into
258         the ``.topmsg`` file, which will already contain some prefilled
259         bits.  You can set the ``topgit.to``, ``topgit.cc`` and ``topgit.bcc``
260         git configuration variables (see ``man git-config``) in order to
261         have ``tg create`` add these headers with the given default values
262         to ``.topmsg``.
264         The main task of ``tg create`` is to set up the topic branch base
265         from the dependencies.  This may fail due to merge conflicts.
266         In that case, after you commit the conflict resolution, you
267         should call ``tg create`` again (without any arguments); it will
268         detect that you are on a topic branch base ref and resume the
269         topic branch creation operation.
271         In an alternative use case, if ``-r <branch>`` is given instead of a
272         dependency list, the topic branch is created based on the given
273         remote branch.  With just ``-r`` the remote branch name is assumed
274         to be the same as the local topic branch being created.
276 tg delete
277 ~~~~~~~~~
278         Remove a TopGit-controlled topic branch of the given name
279         (required argument). Normally, this command will remove only an
280         empty branch (base == head) without dependendents; use ``-f`` to
281         remove a non-empty branch or a branch that is depended upon by
282         another branch.
284         The ``-f`` option is also useful to force removal of a branch's
285         base, if you used ``git branch -D B`` to remove branch B, and then
286         certain TopGit commands complain, because the base of branch B
287         is still there.
289         IMPORTANT: Currently, this command will *NOT* remove the branch
290         from the dependency list in other branches. You need to take
291         care of this *manually*.  This is even more complicated in
292         combination with ``-f`` -- in that case, you need to manually
293         unmerge the removed branch's changes from the branches depending
294         on it.
296         See also ``tg annihilate``.
298         | TODO: ``-a`` to delete all empty branches, depfix, revert
300 tg annihilate
301 ~~~~~~~~~~~~~
302         Make a commit on the current TopGit-controlled topic branch
303         that makes it equal to its base, including the presence or
304         absence of .topmsg and .topdeps.  Annihilated branches are not
305         displayed by ``tg summary``, so they effectively get out of your
306         way.  However, the branch still exists, and ``tg push`` will
307         push it (except if given the ``-a`` option).  This way, you can
308         communicate that the branch is no longer wanted.
310         When annihilating a branch that has dependents (i.e. branches
311         that depend on it), those dependents have the dependencies of
312         the branch being annihilated added to them if they do not already
313         have them as dependencies.  Essentially the DAG is repaired to
314         skip over the annihilated branch.
316         Normally, this command will remove only an empty branch
317         (base == head, except for changes to the .top* files); use
318         ``-f`` to annihilate a non-empty branch.
320 tg depend
321 ~~~~~~~~~
322         Change the dependencies of a TopGit-controlled topic branch.
323         This should have several subcommands, but only ``add`` is
324         supported right now.
326         The ``add`` subcommand takes an argument naming a topic branch to
327         be added, adds it to ``.topdeps``, performs a commit and then
328         updates your topic branch accordingly.  If you want to do other
329         things related to the dependency addition, like adjusting
330         ``.topmsg``, prepare them in the index before calling ``tg depend
331         add``.
333         You have enabled ``git rerere`` haven't you?
335         | TODO: Subcommand for removing dependencies, obviously
337 tg files
338 ~~~~~~~~
339         List files changed by the current or specified topic branch.
341         Options:
342           -i            list files based on index instead of branch
343           -w            list files based on working tree instead of branch
345 tg info
346 ~~~~~~~
347         Show summary information about the current or specified topic
348         branch.
350         Numbers in parenthesis after a branch name such as "(11/3 commits)"
351         indicate how many commits on the branch (11) and how many of those
352         are non-merge commits (3).
354 tg patch
355 ~~~~~~~~
356         Generate a patch from the current or specified topic branch.
357         This means that the diff between the topic branch base and head
358         (latest commit) is shown, appended to the description found in
359         the ``.topmsg`` file.
361         The patch is simply dumped to stdout.  In the future, ``tg patch``
362         will be able to automatically send the patches by mail or save
363         them to files. (TODO)
365         Options:
366           -i            base patch generation on index instead of branch
367           -w            base patch generation on working tree instead of branch
368           --binary      pass --binary to ``git diff-tree`` to enable generation
369                         of binary patches
370           --diff-opt    options after the branch name (and an optional ``--``)
371                         are passed directly to ``git diff-tree``
373         In order to pass a sole explicit ``-w`` through to ``git diff-tree`` it
374         must be separated from the ``tg`` options by an explicit ``--``.
375         Or it can be spelled as ``--ignore-all-space`` to distinguuish it from
376         ``tg``'s ``-w`` option.
378         If additional non-``tg`` options are passed through to
379         ``git diff-tree`` (other than ``--binary`` which is fully supported)
380         the resulting ``tg patch`` output may not be appliable.
382 tg mail
383 ~~~~~~~
384         Send a patch from the current or specified topic branch as
385         email(s).
387         Takes the patch given on the command line and emails it out.
388         Destination addresses such as To, Cc and Bcc are taken from the
389         patch header.
391         Since it actually boils down to ``git send-email``, please refer
392         to the documentation for that for details on how to setup email
393         for git.  You can pass arbitrary options to this command through
394         the ``-s`` parameter, but you must double-quote everything.  The
395         ``-r`` parameter with a msgid can be used to generate in-reply-to
396         and reference headers to an earlier mail.
398         WARNING: be careful when using this command.  It easily sends
399         out several mails.  You might want to run::
401                 git config sendemail.confirm always
403         to let ``git send-email`` ask for confirmation before sending any
404         mail.
406         Options:
407           -i            base patch generation on index instead of branch
408           -w            base patch generation on working tree instead of branch
410         | TODO: ``tg mail patchfile`` to mail an already exported patch
411         | TODO: mailing patch series
412         | TODO: specifying additional options and addresses on command line
414 tg remote
415 ~~~~~~~~~
416         Register the given remote as TopGit-controlled. This will create
417         the namespace for the remote branch bases and teach ``git fetch``
418         to operate on them. However, from TopGit 0.8 onwards you need to
419         use ``tg push``, or ``git push --mirror``, for pushing
420         TopGit-controlled branches.
422         ``tg remote`` takes an optional remote name argument, and an
423         optional ``--populate`` switch.  Use ``--populate`` for your
424         origin-style remotes: it will seed the local topic branch system
425         based on the remote topic branches.  ``--populate`` will also make
426         ``tg remote`` automatically fetch the remote, and ``tg update`` look
427         at branches of this remote for updates by default.
429         Using ``--populate`` with a remote name causes the ``topgit.remote``
430         git configuration variable to be set to the given remote name.
432 tg summary
433 ~~~~~~~~~~
434         Show overview of all TopGit-tracked topic branches and their
435         up-to-date status.  With a branch name limit output to that branch.
436         Using ``--rdeps`` changes the default from all branches to just the
437         current ``HEAD`` branch but using ``--all`` as the branch name will
438         show ``--rdeps`` for all branches.
440                 ``>``
441                         marks the current topic branch
443                 ``0``
444                         indicates that it introduces no changes of its own
446                 ``l``/``r``
447                         indicates respectively whether it is local-only
448                         or has a remote mate
450                 ``L``/``R``
451                         indicates respectively if it is ahead or out-of-date
452                         with respect to its remote mate
454                 ``D``
455                         indicates that it is out-of-date with respect to its
456                         dependencies
458                 ``!``
459                         indicates that it has missing dependencies [even if
460                         they are recursive ones]
462                 ``B``
463                         indicates that it is out-of-date with respect to
464                         its base
466         This can take a long time to accurately determine all the
467         relevant information about each branch; you can pass ``-t`` to get
468         just a terse list of topic branch names quickly.  Alternately,
469         you can pass ``--graphviz`` to get a dot-suitable output to draw a
470         dependency graph between the topic branches.
472         You can also use the ``--sort`` option to sort the branches using
473         a topological sort.  This is especially useful if each
474         TopGit-tracked topic branch depends on a single parent branch,
475         since it will then print the branches in the dependency order.
476         In more complex scenarios, a text graph view would be much more
477         useful, but that has not yet been implemented.
479         The --deps option outputs dependency information between
480         branches in a machine-readable format.  Feed this to ``tsort`` to
481         get the output from --sort.
483         The --rdeps option outputs dependency information in an indented
484         text format that clearly shows all the dependencies and their
485         relationships to one another.  When --rdeps is given the default is
486         to just display information for HEAD, but that can be changed by using
487         --all as the branch name.
489         With --exclude branch, branch can be excluded from the output meaning
490         it will be skipped and its name will be omitted from any dependency
491         output.  The --exclude option may be repeated to omit more than one
492         branch from the output.  Limiting the output to a single branch that
493         has been excluded will result in no output at all.
495         Note that the branch name can be specified as ``HEAD`` as a shortcut for
496         the TopGit-controlled branch that ``HEAD`` is a symbolic ref to.
498         Options:
499           -i            Use TopGit metadata from the index instead of the branch
500           -w            Use TopGit metadata from the working tree instead of the branch
503 tg checkout
504 ~~~~~~~~~~~
505         Switch to a topic branch.  You can use ``git checkout <branch>``
506         to get the same effect, but this command helps you navigate
507         the dependency graph, or allows you to match the topic branch
508         name using a regular expression, so it can be more convenient.
510         There following subcommands are available:
512             ``tg checkout push``
513                                 Check out a branch that directly
514                                 depends on your current branch.
516             ``tg checkout pop``
517                                 Check out a branch that this branch
518                                 directly depends on.
520             ``tg checkout goto <pattern>``
521                                 Check out a topic branch that
522                                 matches ``<pattern>``.  ``<pattern>``
523                                 is used as a sed pattern to filter
524                                 all the topic branches.
526             ``tg checkout next``
527                                 An alias for ``push``.
529             ``tg checkout child``
530                                 An alias for ``push``.
532             ``tg checkout``
533                                 An alias for ``push``.
535             ``tg checkout prev``
536                                 An alias for ``pop``.
538             ``tg checkout parent``
539                                 An alias for ``pop``.
541             ``tg checkout ..``
542                                 An alias for ``pop``.
544         If any of the above commands can find more than one possible
545         branch to switch to, you will be presented with the matches
546         and ask to select one of them.
548         The ``<pattern>`` of ``tg checkout goto`` is optional.  If you don't
549         supply it, all the available topic branches are listed and you
550         can select one of them.
552         Normally, the ``push`` and ``pop`` commands moves one step in
553         the dependency graph of the topic branches.  The ``-a`` option
554         causes them (and their aliases) to move as far as possible.
555         That is, ``tg checkout push -a`` moves to a topic branch that
556         depends (directly or indirectly) on the current branch and
557         that no other branch depends on.  ``tg checkout pop -a``
558         moves to a regular branch that the current topic branch
559         depends on (directly or indirectly).  If there is more than
560         one possibility, you will be prompted for your selection.
562 tg export
563 ~~~~~~~~~
564         Export a tidied-up history of the current topic branch and its
565         dependencies, suitable for feeding upstream.  Each topic branch
566         corresponds to a single commit or patch in the cleaned up
567         history (corresponding basically exactly to ``tg patch`` output
568         for the topic branch).
570         The command has three possible outputs now -- either a Git branch
571         with the collapsed history, a Git branch with a linearized
572         history, or a quilt series in new directory.
574         In the case where you are producing collapsed history in a new
575         branch, you can use this collapsed structure either for
576         providing a pull source for upstream, or for further
577         linearization e.g. for creation of a quilt series using git log::
579                 git log --pretty=email -p --topo-order origin..exported
581         To better understand the function of ``tg export``, consider this
582         dependency structure::
584          origin/master - t/foo/blue - t/foo/red - master
585                       `- t/bar/good <,----------'
586                       `- t/baz      ------------'
588         (where each of the branches may have a hefty history). Then::
590          master$ tg export for-linus
592         will create this commit structure on the branch ``for-linus``::
594          origin/master - t/foo/blue -. merge - t/foo/red -.. merge - master
595                       `- t/bar/good <,-------------------'/
596                       `- t/baz      ---------------------'
598         In this mode, ``tg export`` works on the current topic branch, and
599         can be called either without an option (in that case,
600         ``--collapse`` is assumed), or with the ``--collapse`` option, and
601         with one mandatory argument: the name of the branch where the
602         exported result will be stored.
604         When using the linearize mode::
606          master$ tg export --linearize for-linus
608         you get a linear history respecting the dependencies of your
609         patches in a new branch ``for-linus``.  The result should be more
610         or less the same as using quilt mode and then reimporting it
611         into a Git branch.  (More or less because the topological order
612         can usually be extended in more than one way into a total order,
613         and the two methods may choose different ones.)  The result
614         might be more appropriate for merging upstream, as it contains
615         fewer merges.
617         Note that you might get conflicts during linearization because
618         the patches are reordered to get a linear history.  If linearization
619         would produce conflicts then using ``--quilt`` will also likely result
620         in conflicts when the exported quilt series is applied.  Since the
621         ``--quilt`` mode simply runs a series of ``tg patch`` commands to
622         generate the patches in the exported quilt series and those patches
623         will end up being applied linearly, the same conflicts that would be
624         produced by the ``--linearize`` option will then occur at that time.
626         To avoid conflicts produced by ``--linearize`` (or by applying the
627         ``--quilt`` output), use the default ``--collapse`` mode and then use
628         ``git rebase -m`` on the collapsed branch (with a suitable <upstream>)
629         followed by ``git format-patch`` on the rebased result to produce a
630         conflict-free patch set.
632         You have enabled ``git rerere`` haven't you?
634         When using the quilt mode::
636          master$ tg export --quilt for-linus
638         would create the following directory ``for-linus``::
640          for-linus/t/foo/blue.diff
641          for-linus/t/foo/red.diff
642          for-linus/t/bar/good.diff
643          for-linus/t/baz.diff
644          for-linus/series:
645                 t/foo/blue.diff -p1
646                 t/bar/good.diff -p1
647                 t/foo/red.diff -p1
648                 t/baz.diff -p1
650         With ``--quilt``, you can also pass the ``-b`` parameter followed
651         by a comma-separated explicit list of branches to export, or
652         the ``--all`` parameter (which can be shortened to ``-a``) to
653         export them all.  The ``--binary`` option enables producing Git
654         binary patches.  These options are currently only supported
655         with ``--quilt``.
657         In ``--quilt`` mode the patches are named like the originating
658         topgit branch.  So usually they end up in subdirectories of the
659         output directory.  With the ``--flatten`` option the names are
660         mangled so that they end up directly in the output dir (slashes
661         are substituted by underscores).  With the ``--strip[=N]`` option
662         the first ``N`` subdirectories (all if no ``N`` is given) get
663         stripped off.  Names are always ``--strip``'d before being
664         ``--flatten``'d.  With the option ``--numbered`` (which implies
665         ``--flatten``) the patch names get a number as prefix to allow
666         getting the order without consulting the series file, which
667         eases sending out the patches.
669         | TODO: Make stripping of non-essential headers configurable
670         | TODO: Make stripping of [PATCH] and other prefixes configurable
671         | TODO: ``--mbox`` option to export instead as an mbox file
672         | TODO: support ``--all`` option in other modes of operation
673         | TODO: For quilt exporting, export the linearized history created in
674                 a temporary branch--this would allow producing conflict-less
675                 series
677 tg import
678 ~~~~~~~~~
679         Import commits within the given revision range into TopGit,
680         creating one topic branch per commit. The dependencies are set
681         up to form a linear sequence starting on your current branch --
682         or a branch specified by the ``-d`` parameter, if present.
684         The branch names are auto-guessed from the commit messages and
685         prefixed by ``t/`` by default; use ``-p <prefix>`` to specify an
686         alternative prefix (even an empty one).
688         Alternatively, you can use the ``-s NAME`` parameter to specify
689         the name of the target branch; the command will then take one
690         more argument describing a *single* commit to import.
692 tg update
693 ~~~~~~~~~
694         Update the current, specified or all topic branches with respect
695         to changes in the branches they depend on and remote branches.
696         This is performed in two phases -- first, changes within the
697         dependencies are merged to the base, then the base is merged
698         into the topic branch.  The output will guide you on what to do
699         next in case of conflicts.
701         You have enabled ``git rerere`` haven't you?
703         When ``-a`` is specifed, updates all topic branches matched by
704         ``<pattern>``'s (see ``git-for-each-ref(1)`` for details), or all
705         if no ``<pattern>`` is given.  Any topic branches with missing
706         dependencies will be skipped entirely unless ``--skip`` is specified.
708         When ``--skip`` is specifed, an attempt is made to update topic
709         branches with missing dependencies by skipping only the dependencies
710         that are missing.  Caveat utilitor
712         After the update, if a single topic branch was specified, it is
713         left as the current one; if ``-a`` was specified, it returns to
714         the branch which was current at the beginning.
716         If your dependencies are not up-to-date, ``tg update`` will first
717         recurse into them and update them.
719         If a remote branch update brings in dependencies on branches
720         that are not yet instantiated locally, you can either bring in
721         all the new branches from the remote using ``tg remote
722         --populate``, or only pick out the missing ones using ``tg create
723         -r`` (``tg summary`` will point out branches with incomplete
724         dependencies by showing an ``!`` next to them).
726         | TODO: ``tg update -a -c`` to autoremove (clean) up-to-date branches
728 tg push
729 ~~~~~~~
730         If ``-a`` or ``--all`` was specified, pushes all non-annihilated
731         TopGit-controlled topic branches, to a remote repository.
732         Otherwise, pushes the specified topic branches -- or the
733         current branch, if you don't specify which.  By default, the
734         remote gets all the dependencies (both TopGit-controlled and
735         non-TopGit-controlled) and bases pushed to it too.  If
736         ``--tgish-only`` was specified, only TopGit-controlled
737         dependencies will be pushed, and if ``--no-deps`` was specified,
738         no dependencies at all will be pushed.
740         The ``--dry-run`` and ``--force`` options are passed directly to
741         ``git push`` if given.
743         The remote may be specified with the ``-r`` option. If no remote
744         was specified, the configured default TopGit remote will be
745         used.
747 tg base
748 ~~~~~~~
749         Prints the base commit of each of the named topic branches, or
750         the current branch if no branches are named.  Prints an error
751         message and exits with exit code 1 if the named branch is not
752         a TopGit branch.
754 tg log
755 ~~~~~~
756         Prints the git log of the named topgit branch -- or the current
757         branch, if you don't specify a name.
759         NOTE: if you have merged changes from a different repository, this
760         command might not list all interesting commits.
762 tg prev
763 ~~~~~~~
764         Outputs the direct dependencies for the current or named branch.
766         Options:
767           -i            show dependencies based on index instead of branch
768           -w            show dependencies based on working tree instead of branch
770 tg next
771 ~~~~~~~
772         Outputs all branches which directly depend on the current or
773         named branch.
775         Options:
776           -i            show dependencies based on index instead of branch
777           -w            show dependencies based on working tree instead of branch
779 TODO: tg rename
780 ~~~~~~~~~~~~~~~
782 IMPLEMENTATION
783 --------------
785 TopGit stores all the topic branches in the regular ``refs/heads/``
786 namespace (so we recommend distinguishing them with the ``t/`` prefix).
787 Apart from that, TopGit also maintains a set of auxiliary refs in
788 ``refs/top-*``.  Currently, only ``refs/top-bases/`` is used, containing the
789 current *base* of the given topic branch -- this is basically a merge of
790 all the branches the topic branch depends on; it is updated during ``tg
791 update`` and then merged to the topic branch, and it is the base of a
792 patch generated from the topic branch by ``tg patch``.
794 All the metadata is tracked within the source tree and history of the
795 topic branch itself, in ``.top*`` files; these files are kept isolated
796 within the topic branches during TopGit-controlled merges and are of
797 course omitted during ``tg patch``.  The state of these files in base
798 commits is undefined; look at them only in the topic branches
799 themselves.  Currently, two files are defined:
801         ``.topmsg``:
802             Contains the description of the topic branch in a
803             mail-like format, plus the author information, whatever
804             Cc headers you choose or the post-three-dashes message.
805             When mailing out your patch, basically only a few extra
806             mail headers are inserted and then the patch itself is
807             appended.  Thus, as your patches evolve, you can record
808             nuances like whether the particular patch should have
809             To-list / Cc-maintainer or vice-versa and similar
810             nuances, if your project is into that.  ``From`` is
811             prefilled from your current ``GIT_AUTHOR_IDENT``; other
812             headers can be prefilled from various optional
813             ``topgit.*`` git config options.
815         ``.topdeps``:
816             Contains the one-per-line list of branches this branch
817             depends on, pre-seeded by `tg create`. A (continuously
818             updated) merge of these branches will be the *base* of
819             your topic branch.
821 IMPORTANT: DO NOT EDIT ``.topdeps`` MANUALLY!!! If you do so, you need to
822 know exactly what are you doing, since this file must stay in sync with
823 the Git history information, otherwise very bad things will happen.
825 TopGit also automagically installs a bunch of custom commit-related
826 hooks that will verify whether you are committing the ``.top*`` files in a
827 sane state. It will add the hooks to separate files within the ``hooks/``
828 subdirectory, and merely insert calls to them to the appropriate hooks
829 and make them executable (but will make sure the original hook's code is
830 not called if the hook was not executable beforehand).
832 Another automagically installed piece is a ``.git/info/attributes``
833 specifier for an ``ours`` merge strategy for the files ``.topmsg`` and
834 ``.topdeps``, and the (intuitive) ``ours`` merge strategy definition in
835 ``.git/config``.
838 REMOTE HANDLING
839 ---------------
841 There are two remaining issues with accessing topic branches in remote
842 repositories:
844         (i) Referring to remote topic branches from your local repository
845         (ii) Developing some of the remote topic branches locally
847 There are two somewhat contradictory design considerations here:
849         (a) Hacking on multiple independent TopGit remotes in a single
850             repository
851         (b) Having a self-contained topic system in local refs space
853 To us, (a) does not appear to be very convincing, while (b) is quite
854 desirable for ``git-log topic`` etc. working, and increased conceptual
855 simplicity.
857 Thus, we choose to instantiate all the topic branches of given remote
858 locally; this is performed by ``tg remote --populate``. ``tg update``
859 will also check if a branch can be updated from its corresponding remote
860 branch.  The logic needs to be somewhat involved if we are to "do the
861 right thing".  First, we update the base, handling the remote branch as
862 if it was the first dependency; thus, conflict resolutions made in the
863 remote branch will be carried over to our local base automagically.
864 Then, the base is merged into the remote branch and the result is merged
865 to the local branch -- again, to carry over remote conflict resolutions.
866 In the future, this order might be adjustable on a per-update basis, in
867 case local changes happen to be diverging more than the remote ones.
869 All commands by default refer to the remote that ``tg remote --populate``
870 was called on the last time (stored in the ``topgit.remote`` git
871 configuration variable). You can manually run any command with a
872 different base remote by passing ``-r REMOTE`` *before* the subcommand
873 name.
876 REFERENCES
877 ----------
879 The following references are useful to understand the development of
880 topgit and its subcommands.
882 * tg depend:
883   http://lists-archives.org/git/688698-add-list-and-rm-sub-commands-to-tg-depend.html
886 THIRD-PARTY SOFTWARE
887 --------------------
889 The following software understands TopGit branches:
891 * `magit <http://magit.github.io/>`_ -- a git mode for emacs
893 IMPORTANT: Magit requires its topgit mode to be enabled first, as
894 described in its documentation, in the "Activating extensions"
895 subsection.  If this is not done, it will not push TopGit branches
896 correctly, so it's important to enable it even if you plan to mostly use
897 TopGit from the command line.