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