]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/contributor/source-code.itexi
ac8ecb6ee40827b3d5f137f1baeb712ab7b52870
[lilypond.git] / Documentation / contributor / source-code.itexi
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
3
4 @node Working with source code
5 @chapter Working with source code
6
7 @warning{New contributors should read @ref{Quick start}, and in
8 particular @ref{lily-git}, instead of this chapter.}
9
10 Advanced contributors will find this material quite useful,
11 particularly if they are working on major new features.
12
13 @menu
14 * Manually installing lily-git.tcl::
15 * Starting with Git::
16 * Basic Git procedures::
17 * Advanced Git procedures::
18 * Git on Windows::
19 * Repository directory structure::
20 * Other Git documentation::
21 @end menu
22
23
24 @node Manually installing lily-git.tcl
25 @section Manually installing lily-git.tcl
26
27 We have created an easy-to-use GUI to simplify git for new
28 contributors.  If you are comfortable with the command-line, then
29 skip ahead to @ref{Starting with Git}.
30
31 @warning{These instructions are only for people who are @emph{not}
32 using @ref{LilyDev}.}
33
34 @c there's some duplication in this section with stuff covered in
35 @c Quick Start, but moving it into a macro inside included/ would
36 @c be getting a bit icky.  -gp
37
38 @enumerate
39 @item
40 If you haven't already, download and install Git.
41
42 @itemize
43
44 @item Windows users: download the @code{.exe} file labeled
45 @qq{Full installer for official Git} from:
46
47 @example
48 @uref{https://git-for-windows.github.io/}
49 @end example
50
51 @item Other operating systems: either install @command{git} with
52 your package manager, or download it from the @qq{Binaries}
53 section of:
54
55 @example
56 @uref{http://git-scm.com/download}
57 @end example
58
59 @end itemize
60
61
62 @item
63 Download the @command{lily-git.tcl} script from:
64
65 @c don't change the cgit link below to gitweb; gitweb uses
66 @c long filenames like "scripts_auxiliar_lily-git.tcl"
67
68 @smallexample
69 @uref{http://git.sv.gnu.org/cgit/lilypond.git/plain/scripts/auxiliar/lily-git.tcl}
70 @end smallexample
71
72 @item
73 To run the program from the command line, navigate to the
74 directory containing @command{lily-git.tcl} and enter:
75
76 @example
77 wish lily-git.tcl
78 @end example
79
80 @item
81 Click on the @qq{Get source} button.
82
83 This will create a directory called @file{lilypond-git/} within
84 your home directory, and will download the source code into that
85 directory (around 150@tie{}Mb).  When the process is finished, the
86 @qq{Command output} window will display @qq{Done}, and the button
87 label will change to say @qq{Update source}.
88
89 @item
90 Navigate to the @file{lilypond-git/} directory to view the source
91 files.
92
93 @end enumerate
94
95 @warning{Throughout the rest of this manual, most command-line
96 input should be entered from @file{$LILYPOND_GIT}.  This is
97 referred to as the @emph{top source directory}.}
98
99 Further instructions are in @ref{How to use lily-git}.
100
101
102 @node Starting with Git
103 @section Starting with Git
104
105 Using the Git program directly (as opposed to using the
106 @command{lily-git.tcl} GUI) allows you to have much greater control
107 over the contributing process.  You should consider using Git if
108 you want to work on complex projects, or if you want to work on
109 multiple projects concurrently.
110
111
112 @menu
113 * Setting up::
114 * Git for the impatient::
115 * Other repositories::
116 * Downloading remote branches::
117 @end menu
118
119
120 @node Setting up
121 @subsection Setting up
122
123 @warning{These instructions assume that you are using the
124 command-line version of Git 1.5 or higher.  Windows users should
125 skip to @ref{Git on Windows}.}
126
127 @menu
128 * Installing Git::
129 * Initializing a repository::
130 * Configuring Git::
131 @end menu
132
133
134 @node Installing Git
135 @unnumberedsubsubsec Installing Git
136
137 If you are using a Unix-based machine, the easiest way to download
138 and install Git is through a package manager such as @command{rpm}
139 or @command{apt-get} -- the installation is generally automatic.
140 The only required package is (usually) called @command{git-core},
141 although some of the auxiliary @command{git@var{*}} packages are
142 also useful (such as @command{gitk}).
143
144 Alternatively, you can visit the Git website
145 (@uref{http://git-scm.com/}) for downloadable binaries and
146 tarballs.
147
148
149 @node Initializing a repository
150 @unnumberedsubsubsec Initializing a repository
151
152 Once Git is installed, get a copy of the source code:
153
154 @example
155 git clone git://git.sv.gnu.org/lilypond.git ~/lilypond-git
156 @end example
157
158 The above command will put the it in @file{~/lilypond-git}, where
159 @code{~} represents your home directory.
160
161 @subsubheading Technical details
162
163 This creates (within the @file{$LILYPOND_GIT} directory) a
164 subdirectory called @file{.git/}, which Git uses to keep track of
165 changes to the repository, among other things.  Normally you don't
166 need to access it, but it's good to know it's there.
167
168
169 @node Configuring Git
170 @unnumberedsubsubsec Configuring Git
171
172 @warning{Throughout the rest of this manual, all command-line
173 input should be entered from the top directory of the Git
174 repository being discussed (eg. @file{$LILYPOND_GIT}).  This is
175 referred to as the @emph{top source directory}.}
176
177 Before working with the copy of the main LilyPond repository, you
178 should configure some basic settings with the
179 @command{git@tie{}config} command.  Git allows you to set both
180 global and repository-specific options.
181
182 To configure settings that affect all repositories, use the
183 @option{--global} command line option.  For example, the first
184 two options that you should always set are your @var{name} and
185 @var{email}, since Git needs these to keep track of commit
186 authors:
187
188 @example
189 git config --global user.name "@var{John Smith}"
190 git config --global user.email @var{john@@example.com}
191 @end example
192
193 To configure Git to use colored output where possible, use:
194
195 @example
196 git config --global color.ui auto
197 @end example
198
199 The text editor that opens when using @command{git@tie{}commit}
200 can also be changed.  If none of your editor-related environment
201 variables are set ($GIT_EDITOR, $VISUAL, or $EDITOR), the default
202 editor is usually @command{vi} or @command{vim}.  If you're not
203 familiar with either of these, you should probably change the
204 default to an editor that you know how to use.  For example, to
205 change the default editor to @command{nano}, enter:
206
207 @example
208 git config --global core.editor @var{nano}
209 @end example
210
211 Finally, and in some ways most importantly, let's make sure that
212 we know what branch we're on.  If you're not using LilyDev, add
213 this to your @file{~/.bashrc}:
214
215 @verbatim
216 export PS1="\u@\h \w\$(__git_ps1)$ "
217 @end verbatim
218
219 You may need to install the additional @code{bash-completion}
220 package, but it is definitely worth it.  After installation
221 you must log out, and then log back in again to enable it.
222
223
224 @subsubheading Technical details
225
226 Git stores the information entered with
227 @command{git@tie{}config@tie{}--global} in the file
228 @file{.gitconfig}, located in your home directory.  This file can
229 also be modified directly, without using
230 @command{git@tie{}config}.  The @file{.gitconfig} file generated
231 by the above commands would look like this:
232
233 @example
234 [user]
235         name = John Smith
236         email = john@@example.com
237 [color]
238         ui = auto
239 [core]
240         editor = nano
241 @end example
242
243 Using the @command{git@tie{}config} command @emph{without} the
244 @option{--global} option configures repository-specific settings,
245 which are stored in the file @file{.git/config}.  This file is
246 created when a repository is initialized (using
247 @command{git@tie{}init}), and by default contains these lines:
248
249 @example
250 [core]
251         repositoryformatversion = 0
252         filemode = true
253         bare = false
254         logallrefupdates = true
255 @end example
256
257 However, since different repository-specific options are
258 recommended for different development tasks, it is best to avoid
259 setting any now.  Specific recommendations will be mentioned later
260 in this manual.
261
262
263 @node Git for the impatient
264 @subsection Git for the impatient
265
266 @advanced{The intent of this subsection is to get you working on lilypond as
267 soon as possible.  If you want to learn about git, go read
268 @ref{Other Git documentation}.
269 @*
270 Also, these instructions are designed to eliminate the most common
271 problems we have found in using git.  If you already know git and
272 have a different way of working, great!  Feel free to ignore the
273 advice in this subsection.}
274
275
276 Ok, so you've been using @command{lily-git.tcl} for a while, but
277 it's time to take the next step.  Since our review process delays
278 patches by 60-120 hours, and you want to be able to work on other
279 stuff while your previous work is getting reviewed, you're going
280 to use @strong{branches}.
281
282 You can think of a branch as being a separate copy of the source
283 code.  But don't worry about it.
284
285 @subsubheading Start work: make a new branch
286
287 Let's pretend you want to add a section to the Contributor's Guide
288 about using branches.
289
290 Start by updating the repository, then making a new branch.  Call
291 the branch anything you want as long as the name starts with
292 @code{dev/}.  Branch names that don't begin with @code{dev/} are
293 reserved for special things in lilypond.
294
295 @example
296 git checkout master
297 git pull -r origin master
298 git branch dev/cg
299 @end example
300
301 @subsubheading Switch to that branch
302
303 Nothing has happened to the files yet.  Let's change into the new
304 branch.  You can think of this as @qq{loading a file}, although in
305 this case it's really @qq{loading a directory and subdirectories
306 full of files}.
307
308 @example
309 git checkout dev/cg
310 @end example
311
312 Your prompt now shows you that you're on the other branch:
313
314 @example
315 gperciva@@LilyDev:~/lilypond-git (dev/cg)$
316 @end example
317
318 To be able to manage multiple lilypond issues at once, you'll need to switch
319 branches.  You should have each lilypond issue on a separate branch.
320 Switching branches is easy:
321
322 @example
323 git checkout master
324 git checkout origin/staging
325 git checkout origin/release/unstable
326 git checkout dev/cg
327 @end example
328
329 Branches that begin with @code{origin/} are part of the remote repository,
330 rather than your local repository, so when you check them out you get a 
331 temporary local branch.  You should never make changes directly on a
332 branch beginning with @code{origin/}.  You get changes into the remote
333 repository by making them in local branches, and then pushing them to
334 @code{origin/staging} as described below. 
335
336 @subsubheading Make your changes
337
338 Edit files, then commit them.
339
340 @example
341 git commit -a
342 @end example
343
344
345 Remember how I said that switching to a branch was like
346 @qq{loading a directory}?  Well, you've just @qq{saved a
347 directory}, so that you can @qq{load} it later.
348
349 @advanced{If you have used @command{cvs} or @command{svn}, you may
350 be very confused: those programs use @qq{commit} to mean
351 @qq{upload my changes to the shared source repository}.
352 Unfortunately, just to be different, @w{@command{git commit}}
353 means @qq{save my changes to the files}.}
354
355 When you create a new file, you need to add it to git, then commit it:
356
357 @example
358 git add input/regression/avoid-crash-on-condition.ly
359 git commit -a
360 @end example
361
362
363 Edit more files.  Commit them again.  Edit yet more files, commit
364 them again.  Go eat dinner.  Switch to @code{master} so you can
365 play with the latest changes from other developers.  Switch back
366 to your branch and edit some more.  Commit those changes.
367
368 At this stage, don't worry about how many commits you have.
369
370
371 @subsubheading Save commits to external files
372
373 Branches are nerve-wracking until you get used to them.  You can
374 save your hard work as individual @file{.patch} files.  Be sure to
375 commit your changes first.
376
377 @example
378 git commit -a
379 git format-patch master
380 @end example
381
382 I personally have between 4 and 20 of those files saved in a
383 special folder at any point in time.  Git experts might laugh as
384 that behavior, but I feel a @emph{lot} better knowing that I've
385 got those backups.
386
387
388 @subsubheading Prepare your branch for review
389
390 After committing, you can update your branch with the latest master:
391
392 @example
393 git commit -a
394 git checkout master
395 git pull -r origin master
396 git checkout dev/cg
397 git rebase master
398 @end example
399
400
401 Due to the speed of lilypond development, sometimes
402 @code{master} has changed so much that your branch can no
403 longer be applied to it.  In that happens, you will have a merge
404 conflict.  Stop for a moment to either cry or have a stiff drink,
405 then proceed to @ref{Merge conflicts}.
406
407
408 @subsubheading Upload your branch
409
410 Finally, you're finished your changes.  Time to upload for review.
411 Make sure that you're on your branch, then upload:
412
413 @example
414 git checkout dev/cg
415 git-cl upload master
416 @end example
417
418
419 @subsubheading Wait for reviews
420
421 While you're waiting for a countdown and reviews, go back to
422 master, make a @code{dev/doc-beams} branch, and start adding doc
423 suggestions from issue 12345 from the tracker.  Or make a
424 @code{dev/page-breaks} and fix bug in page breaking.  Or whatever.
425 Don't worry, your @code{dev/cg} is safe.
426
427
428 @subsubheading Combining commits (optional unless you have broken commits)
429
430 Does the history of your branch look good?
431
432 @example
433 gitk
434 @end example
435
436 If you have a lot of commits on your branch, you might want to
437 combine some of them.  Alternately, you may like your commits, but
438 want to edit the commit messages.
439
440 @example
441 git rebase -i master
442 @end example
443
444 Follow instructions on the screen.
445
446 @warning{This step gives you the power to completely lose your
447 work.  Make a backup of your commits by saving them to
448 @file{.patch} files before playing with this.  If you do lose
449 your work, don't despair.  You can get it back by using @code{git reflog}.
450 The use of @code{git reflog} is not covered here.}
451
452 @warning{If any of the commits on your branch represent partial work that will
453 not pass @var{make && make doc}, you @strong{must} squash these 
454 commits into a working commit.  Otherwise, your push will break staging
455 and will not be able to be merged to master.  In general, you will
456 be safer to have one commit per push.}
457
458
459 @subsubheading Push to staging
460
461 When you've got the coveted @code{Patch-push} status, time to
462 prepare your upload:
463
464 @example
465 git fetch
466 git rebase origin/staging dev/cg~0
467 gitk HEAD
468 @end example
469
470 @warning{Do not skip the @command{gitk} step; a quick 5-second
471 check of the visual history can save a great deal of frustration
472 later on.  You should see a set of your commits that are ahead of
473 @code{origin/staging}, with no label for the top commit -- only a
474 SHA1 id.}
475
476 @warning{If @code{origin/staging} and @code{origin/master} are the
477 same commit, your branch (@code{dev/cg} in the example) will also
478 be at the top of the @code{gitk} tree.  This is normal.}
479
480 If everything looks good, push it:
481
482 @example
483 git push origin HEAD:staging
484 @end example
485
486 Then change back to your working branch:
487
488 @example
489 git checkout dev/cg
490 @end example
491
492 @warning{It is a best practice to avoid rebasing any of your branches
493 to @code{origin/staging}.  If @code{origin/staging} is broken, it
494 will be deleted and rebuilt.  If you have rebased one of your branches
495 to @code{origin/staging}, the broken commits can end up in your branch.
496 The commands given above do the rebase on a temporary branch, and avoid
497 changing your working branch.}
498
499
500 @subsubheading Delete your branch (safe)
501
502 After a few hours, if there's nothing wrong with your branch, it
503 should be automatically moved to @code{origin/master}.  Update,
504 then try removing your branch:
505
506 @example
507 git checkout master
508 git pull -r origin master
509 git branch -d dev/cg
510 @end example
511
512 The last command will fail if the contents of @code{dev/cg} are
513 not present in @code{origin/master}.
514
515
516 @subsubheading Delete your branch (UNSAFE)
517
518 @c don't give explicit commands here -- this is too dangerous to copy and paste
519 Sometimes everything goes wrong.  If you want to remove a branch even though 
520 it will cause your work to be lost (that is, if the contents of @code{dev/cg}
521 are @strong{not} present in master), follow the instructions in @qq{Delete
522 your branch (safe)}, but replace the @code{-d} on the final line with 
523 a @code{-D}.
524
525
526 @node Other repositories
527 @subsection Other repositories
528
529 We have a few other code repositories.
530
531 @menu
532 * lilypond-extra::
533 * Grand Unified Builder (GUB)::
534 * LilyPad::
535 * yet more repositories::
536 @end menu
537
538 @node lilypond-extra
539 @unnumberedsubsubsec lilypond-extra
540
541 There is a separate repository for general administrative scripts,
542 as well as pictures and media files for the website.  People
543 interested in working on the website should download this
544 repository, and set their @code{$LILYPOND_WEB_MEDIA_GIT}
545 environment variable to point to that repository.
546
547 @example
548 @uref{https://github.com/gperciva/lilypond-extra}
549 @end example
550
551 To configure an environment variable in bash (the default for most
552 GNU/Linux distributions),
553
554 @example
555 export LILYPOND_WEB_MEDIA_GIT=$HOME/dir/of/lilypond-extra/
556 @end example
557
558 Be aware that @code{lilypond-extra} is the definitive source for some binary
559 files - in particular PDF versions of papers concerning LilyPond.  To add
560 further PDFs of this sort, all that is necessary is to add the PDF to
561 @code{lilypond-extra} and then add a reference to it in the documentation.  The
562 file will then be copied to the website when @code{make website} is run.
563
564 However, pictures that are also used in the documentation build are mastered in
565 the main git repository.  If any of these is changed, it should be updated in
566 git, and then the updates copied to @code{lilypond-extra}.
567
568 @node Grand Unified Builder (GUB)
569 @unnumberedsubsubsec Grand Unified Builder (GUB)
570
571 Another item of interest might be the Grand Unified Builder, our
572 cross-platform building tool.  Since it is used by other projects as
573 well, it is not stored in our gub repository.  For more info, see
574 @uref{http://lilypond.org/gub}.
575
576 There are two locations for this repository: the version being used to
577 build lilypond, which is at
578
579 @example
580 @uref{http://github.com/gperciva/gub}
581 @end example
582
583 and the original version by Jan Nieuwenhuizen, kept at
584
585 @example
586 @uref{http://github.com/janneke/gub}
587 @end example
588
589
590 @node LilyPad
591 @unnumberedsubsubsec LilyPad
592
593 Our binary releases on MacOS X and Windows contain a lightweight
594 text editor.
595
596 To make any modifications the Windows editor, you will need to do the
597 following:
598
599 @enumerate
600 @item
601 Clone the git repository from @code{https://github.com/gperciva/lilypad}
602
603 @item
604 Make changes to the source, and check it compiles.  In a Windows environment
605 @code{MinGW} provides both a @code{Git} installation and a @code{gcc}
606 compiler.  This can be obtained from @code{http://www.mingw.org/}
607
608 @item
609 Update the version which is contained in the @file{rsrc.rc}.  Check
610 this compiles, too.
611
612 @item
613 Commit the changes with an informative commit message.
614
615 @item
616 Push the changes to github.  You will need to use syntax similiar to this:
617
618 @example
619 git push https://UserName@@github.com/gperciva/lilypad.git
620 @end example
621
622 You will need to have push access to the git repository for this to be
623 successful.
624
625 @item
626 Make a tarball of the source code to be used by GUB by pulling the updated
627 repository from GitHub.  Ensure that the tarball has the correct Version
628 number.
629
630 @item
631 Copy the tarball to @code{http://lilypond.org/downloads/gub-sources/lilypad/}.
632 You will need to have SSH access to @code{lilypond.org}.  If you do not, contact
633 the Release Manager via the lilypond-devel mailing list.
634
635 @item
636 Update GUB to make it use the new tarball by editing
637 @file{gub/specs/lilypad.py} and changing the @code{source =} line to point to
638 the new source.
639
640 @item
641 Push this updated @file{lilypad.py} version to the GUB repository on GitHub.
642
643 @item
644 Test the changes with a new GUB compile.
645
646 @end enumerate
647
648 @node yet more repositories
649 @unnumberedsubsubsec yet more repositories
650
651 There are a few other repositories floating around, which will
652 hopefully be documented in the near future.
653
654
655 @node Downloading remote branches
656 @subsection Downloading remote branches
657
658 @warning{contains obsolete + misleading info}
659
660 @menu
661 * Organization of remote branches::
662 * LilyPond repository sources::
663 * Downloading individual branches::
664 * Downloading all remote branches::
665 * Other branches::
666 @end menu
667
668
669 @node Organization of remote branches
670 @unnumberedsubsubsec Organization of remote branches
671
672
673 The main LilyPond repository is organized into @emph{branches} to
674 facilitate development.  These are often called @emph{remote}
675 branches to distinguish them from @emph{local} branches you might
676 create yourself (see @ref{Using local branches}).
677
678 The @code{master} branch contains all the source files used to
679 build LilyPond, which includes the program itself (both stable and
680 development releases), the documentation (and its translations),
681 and the website.  Generally, the @code{master} branch is expected
682 to compile successfully.
683
684 The @code{translation} branch is a side branch that
685 allows translators to work without needing to worry about
686 compilation problems.  Periodically, the Translation Meister
687 (after verifying that it doesn't break compilation), will
688 @emph{merge} this branch into @code{staging} to incorporate
689 recent translations.  Similarly, the @code{master} branch is
690 usually merged into the @code{translation} branch after
691 significant changes to the English documentation.  See
692 @ref{Translating the documentation} for details.
693
694
695 @node LilyPond repository sources
696 @unnumberedsubsubsec LilyPond repository sources
697
698
699 The recommended source for downloading a copy of the main
700 repository is:
701
702 @example
703 git://git.sv.gnu.org/lilypond.git
704 @end example
705
706 However, if your internet router filters out connections using the
707 GIT protocol, or if you experience difficulty connecting via GIT,
708 you can try these other sources:
709
710 @example
711 ssh://git.sv.gnu.org/srv/git/lilypond.git
712 http://git.sv.gnu.org/r/lilypond.git
713 @end example
714
715 The SSH protocol can only be used if your system is properly set
716 up to use it.  Also, the HTTP protocol is slowest, so it should
717 only be used as a last resort.
718
719
720 @node Downloading individual branches
721 @unnumberedsubsubsec Downloading individual branches
722
723 @warning{obsolete, should be deleted!}
724
725
726 Once you have initialized an empty Git repository on your system
727 (see @ref{Initializing a repository}), you can download a remote
728 branch into it.  Make sure you know which branch you want to start
729 with.
730
731 To download the @code{master} branch, enter the following:
732
733 @example
734 git remote add -ft master -m master \
735   origin git://git.sv.gnu.org/lilypond.git/
736 @end example
737
738 To download the @code{translation} branch, enter:
739
740 @example
741 git remote add -ft translation -m \
742   translation origin git://git.sv.gnu.org/lilypond.git/
743 @end example
744
745 The @command{git@tie{}remote@tie{}add} process could take up to
746 ten minutes, depending on the speed of your connection.  The
747 output will be something like this:
748
749 @example
750 Updating origin
751 remote: Counting objects: 235967, done.
752 remote: Compressing objects: 100% (42721/42721), done.
753 remote: Total 235967 (delta 195098), reused 233311 (delta 192772)
754 Receiving objects: 100% (235967/235967), 68.37 MiB | 479 KiB/s, done.
755 Resolving deltas: 100% (195098/195098), done.
756 From git://git.sv.gnu.org/lilypond
757  * [new branch]      master     -> origin/master
758 From git://git.sv.gnu.org/lilypond
759  * [new tag]         flower/1.0.1 -> flower/1.0.1
760  * [new tag]         flower/1.0.10 -> flower/1.0.10
761 â‹®
762  * [new tag]         release/2.9.6 -> release/2.9.6
763  * [new tag]         release/2.9.7 -> release/2.9.7
764 @end example
765
766 When @command{git@tie{}remote@tie{}add} is finished, the remote
767 branch should be downloaded into your repository---though not yet
768 in a form that you can use.  In order to browse the source code
769 files, you need to @emph{create} and @emph{checkout} your own
770 local branch.  In this case, however, it is easier to have Git
771 create the branch automatically by using the @command{checkout}
772 command on a non-existent branch.  Enter the following:
773
774 @example
775 git checkout -b @var{branch} origin/@var{branch}
776 @end example
777
778 @noindent
779 where @code{@var{branch}} is the name of your tracking branch,
780 either @code{master} or @code{translation}.
781
782 Git will issue some warnings; this is normal:
783
784 @example
785 warning: You appear to be on a branch yet to be born.
786 warning: Forcing checkout of origin/master.
787 Branch master set up to track remote branch master from origin.
788 Already on 'master'
789 @end example
790
791 By now the source files should be accessible---you should be able
792 to edit any files in the @file{$LILYPOND_GIT} directory using a
793 text editor of your choice.  But don't start just yet!  Before
794 editing any source files, learn how to keep your changes organized
795 and prevent problems later---read @ref{Basic Git procedures}.
796
797 @subsubheading Technical Details
798
799 The @command{git@tie{}remote@tie{}add} command should add some
800 lines to your local repository's @file{.git/config} file:
801
802 @example
803 [remote "origin"]
804         url = git://git.sv.gnu.org/lilypond.git/
805         fetch = +refs/heads/master:refs/remotes/origin/master
806 @end example
807
808
809 @node Downloading all remote branches
810 @unnumberedsubsubsec Downloading all remote branches
811
812
813 To download all remote branches at once, you can @command{clone}
814 the entire repository:
815
816 @example
817 git clone git://git.sv.gnu.org/lilypond.git
818 @end example
819
820
821 @node Other branches
822 @unnumberedsubsubsec Other branches
823
824 Most contributors will never need to touch the other branches.  If
825 you wish to do so, you will need more familiarity with Git; please
826 see @ref{Other Git documentation}.
827
828 @itemize
829 @item @code{dev/XYZ}:
830 These branches are for individual developers.  They store code
831 which is not yet stable enough to be added to the @code{master}
832 branch.
833
834 @item @code{stable/XYZ}:
835 The branches are kept for archival reasons.
836
837 @item @code{archive/XYZ}:
838 The branches are kept for archival reasons.
839
840 @end itemize
841
842
843 @node Basic Git procedures
844 @section Basic Git procedures
845
846
847 @menu
848 * The Git contributor's cycle::
849 * Pulling and rebasing::
850 * Using local branches::
851 * Commits::
852 * Patches::
853 * Uploading a patch for review::
854 * The patch review cycle::
855 @end menu
856
857
858 @node The Git contributor's cycle
859 @subsection The Git contributor's cycle
860
861
862 Here is a simplified view of the contribution process on Git:
863
864 @enumerate
865 @item
866 Update your local repository by @emph{pulling} the most recent
867 updates from the remote repository.
868
869 @item
870 Edit source files within your local repository's @emph{working
871 directory}.
872
873 @item
874 @emph{Commit} the changes you've made to a local @emph{branch}.
875
876 @item
877 Generate a @emph{patch} to share your changes with the developers.
878 @end enumerate
879
880
881 @node Pulling and rebasing
882 @subsection Pulling and rebasing
883
884
885 When developers push new patches to the @code{git.sv.gnu.org}
886 repository, your local repository is @strong{not} automatically
887 updated.  It is important to keep your repository up-to-date by
888 periodically @emph{pulling} the most recent @emph{commits} from
889 the remote branch.  Developers expect patches to be as current as
890 possible, since outdated patches require extra work before they
891 can be used.
892
893 Occasionally you may need to rework some of your own modifications
894 to match changes made to the remote branch (see @ref{Resolving
895 conflicts}), and it's considerably easier to rework things
896 incrementally.  If you don't update your repository along the way,
897 you may have to spend a lot of time resolving branch conflicts and
898 reconfiguring much of the work you've already done.
899
900 Fortunately, Git is able to resolve certain types of branch
901 conflicts automatically with a process called @emph{rebasing}.
902 When rebasing, Git tries to modify your old commits so they appear
903 as new commits (based on the latest updates).  For a more involved
904 explanation, see the @command{git-rebase} man page.
905
906 To pull without rebasing (recommended for translators), use the
907 following command:
908
909 @example
910 git pull    # recommended for translators
911 @end example
912
913 If you're tracking the remote @code{master} branch, you should add
914 the @option{-r} option (short for @option{--rebase}) to keep commits
915 on your local branch current:
916
917 @example
918 git pull -r # use with caution when translating
919 @end example
920
921 If you don't edit translated documentation and don't want to type
922 @option{-r} every time, configure the master branch to rebase by
923 default with this command:
924
925 @example
926 git config branch.master.rebase true
927 @end example
928
929 If pull fails because of a message like
930
931 @example
932 error: Your local changes to 'Documentation/learning/tutorial.itely'
933 would be overwritten by merge.  Aborting.
934 @end example
935
936 @noindent
937 or
938
939 @example
940 Documentation/learning/tutorial.itely: needs update
941 refusing to pull with rebase: your working tree is not up-to-date
942 @end example
943
944 @noindent
945 it means that you have modified some files in you working tree
946 without committing changes (see @ref{Commits}); you
947 can use the @command{git@tie{}stash} command to work around this:
948
949 @example
950 git stash      # save uncommitted changes
951 git pull -r    # pull using rebase (translators omit "-r")
952 git stash pop  # reapply previously saved changes
953 @end example
954
955 Note that @command{git@tie{}stash@tie{}pop} will try to apply a
956 patch, and this may create a conflict.  If this happens, see
957 @ref{Resolving conflicts}.
958
959 TODO: I think the next paragraph is confusing.  Perhaps prepare
960 the reader for new terms `committish' and `head'?  -mp
961
962 @warning{translators and documentation editors, if you have
963 changed committishes in the head of translated files using commits
964 you have not yet pushed to @code{git.sv.gnu.org}, please do not
965 rebase.  If you want to avoid wondering whether you should rebase
966 each time you pull, please always use committishes from master
967 and/or translation branch on @code{git.sv.gnu.org}, which
968 in particular implies that you must push your changes to
969 documentation except committishes updates (possibly after having
970 rebased), then update the committishes and push them.}
971
972 TODO: when committishes automatic conditional update have been
973 tested and documented, append the following to the warning above:
974 Note that using update-committishes make target generally touches
975 committishes.
976
977 @subsubheading Technical details
978
979 The @command{git@tie{}config} command mentioned above adds the
980 line @code{rebase = true} to the master branch in your local
981 repository's @file{.git/config} file:
982
983 @example
984 [branch "master"]
985         remote = origin
986         merge = refs/heads/master
987         rebase = true
988 @end example
989
990
991 @node Using local branches
992 @subsection Using local branches
993
994
995 @menu
996 * Creating and removing branches::
997 * Listing branches and remotes::
998 * Checking out branches::
999 * Merging branches::
1000 @end menu
1001
1002
1003 @node Creating and removing branches
1004 @unnumberedsubsubsec Creating and removing branches
1005
1006
1007 Local branches are useful when you're working on several different
1008 projects concurrently.  To create a new branch, enter:
1009
1010 @example
1011 git branch @var{name}
1012 @end example
1013
1014 To delete a branch, enter:
1015
1016 @example
1017 git branch -d @var{name}
1018 @end example
1019
1020 Git will ask you for confirmation if it sees that data would be
1021 lost by deleting the branch.  Use @option{-D} instead of @option{-d}
1022 to bypass this.  Note that you cannot delete a branch if it is
1023 currently checked out.
1024
1025
1026 @node Listing branches and remotes
1027 @unnumberedsubsubsec Listing branches and remotes
1028
1029 You can get the exact path or URL of all remote branches by
1030 running:
1031
1032 @example
1033 git remote -v
1034 @end example
1035
1036 To list Git branches on your local repositories, run
1037
1038 @example
1039 git branch     # list local branches only
1040 git branch -r  # list remote branches
1041 git branch -a  # list all branches
1042 @end example
1043
1044
1045 @node Checking out branches
1046 @unnumberedsubsubsec Checking out branches
1047
1048 To know the currently checked out branch, i.e. the branch whose
1049 source files are present in your working tree, read the first line
1050 of the output of
1051
1052 @example
1053 git status
1054 @end example
1055
1056 @noindent
1057 The currently checked out branch is also marked with an asterisk
1058 in the output of @command{git branch}.
1059
1060 You can check out another branch @code{@var{other_branch}}, i.e.
1061 check out @code{@var{other_branch}} to the working tree, by
1062 running
1063
1064 @example
1065 git checkout @var{other_branch}
1066 @end example
1067
1068 Note that it is possible to check out another branch while having
1069 uncommitted changes, but it is not recommended unless you know
1070 what you are doing; it is recommended to run @command{git status}
1071 to check this kind of issue before checking out another branch.
1072
1073 @node Merging branches
1074 @unnumberedsubsubsec Merging branches
1075
1076 To merge branch @code{@var{foo}} into branch @code{@var{bar}},
1077 i.e. to @qq{add} all changes made in branch @code{@var{foo}} to
1078 branch @code{@var{bar}}, run
1079
1080 @example
1081 git checkout @var{bar}
1082 git merge @var{foo}
1083 @end example
1084
1085 If any conflict happens, see @ref{Resolving conflicts}.
1086
1087 There are common usage cases for merging: as a translator, you will
1088 often want the Translations meister to merge @code{master} into
1089 @code{translation}; on the other hand, the Translations meister wants
1090 to merge @code{translation} into @code{staging} whenever he has
1091 checked that @code{translation} builds successfully.
1092
1093
1094 @node Commits
1095 @subsection Commits
1096
1097 @menu
1098 * Understanding commits::
1099 * How to make a commit::
1100 * Commit messages::
1101 @end menu
1102
1103
1104 @node Understanding commits
1105 @unnumberedsubsubsec Understanding commits
1106
1107 Technically, a @emph{commit} is a single point in the history of a
1108 branch, but most developers use the term to mean a @emph{commit
1109 object}, which stores information about a particular revision.  A
1110 single commit can record changes to multiple source files, and
1111 typically represents one logical set of related changes (such as a
1112 bug-fix).  You can list the ten most recent commits in your
1113 current branch with this command:
1114
1115 @example
1116 git log -10 --oneline
1117 @end example
1118
1119 If you're using an older version of Git and get an @q{unrecognized
1120 argument} error, use this instead:
1121
1122 @example
1123 git log -10 --pretty=oneline --abbrev-commit
1124 @end example
1125
1126 More interactive lists of the commits on the remote @code{master}
1127 branch are available at
1128 @uref{http://git.sv.gnu.org/gitweb/?p=lilypond.git;a=shortlog} and
1129 @uref{http://git.sv.gnu.org/cgit/lilypond.git/log/}.
1130
1131
1132 @node How to make a commit
1133 @unnumberedsubsubsec How to make a commit
1134
1135
1136 Once you have modified some source files in your working
1137 directory, you can make a commit with the following procedure:
1138
1139 @enumerate
1140 @item
1141 Make sure you've configured Git properly (see @ref{Configuring
1142 Git}).  Check that your changes meet the requirements described in
1143 @ref{Code style} and/or @ref{Documentation policy}.  For advanced
1144 edits, you may also want to verify that the changes don't break
1145 the compilation process.
1146
1147 @item
1148 Run the following command:
1149
1150 @example
1151 git status
1152 @end example
1153
1154 @noindent
1155 to make sure you're on the right branch, and to see which files
1156 have been modified, added or removed, etc.  You may need to tell
1157 Git about any files you've added by running one of these:
1158
1159 @example
1160 git add @var{file}  # add untracked @var{file} individually
1161 git add .     # add all untracked files in current directory
1162 @end example
1163
1164 @noindent
1165 After @command{git@tie{}add}, run @command{git@tie{}status} again
1166 to make sure you got everything.  You may also need to modify
1167 @file{GNUmakefile}.
1168
1169 @item
1170 Preview the changes about to be committed (to make sure everything
1171 looks right) with:
1172
1173 @example
1174 git diff HEAD
1175 @end example
1176
1177 @noindent
1178 The @code{HEAD} argument refers to the most recent commit on the
1179 currently checked-out branch.
1180
1181 @item
1182 Generate the commit with:
1183
1184 @example
1185 git commit -a
1186 @end example
1187
1188 @noindent
1189 The @option{-a} is short for @option{--all} which includes modified
1190 and deleted files, but only those newly created files that have
1191 previously been added.
1192
1193 @end enumerate
1194
1195
1196 @node Commit messages
1197 @unnumberedsubsubsec Commit messages
1198
1199
1200 When you run the @command{git@tie{}commit@tie{}-a} command, Git
1201 automatically opens the default text editor so you can enter a
1202 @emph{commit message}.  If you find yourself in a foreign editing
1203 environment, you're probably in @command{vi} or @command{vim}.  If
1204 you want to switch to an editor you're more familiar with, quit by
1205 typing @code{:q!} and pressing @code{<Enter>}.  See
1206 @ref{Configuring Git} for instructions on changing the default
1207 editor.
1208
1209 In any case, Git will open a text file for your commit message
1210 that looks like this:
1211
1212 @example
1213
1214 # Please enter the commit message for your changes.  Lines starting
1215 # with '#' will be ignored, and an empty message aborts the commit.
1216 # On branch master
1217 # Changes to be committed:
1218 #   (use "git reset HEAD <file>..." to unstage)
1219 #
1220 #       modified:   working.itexi
1221 #
1222 @end example
1223
1224 Your commit message should begin with a one-line summary
1225 describing the change (no more than 50 characters long), and if
1226 necessary a blank line followed by several lines giving the
1227 details:
1228
1229 @c $ git log -1 --pretty=medium 4d6f1e5
1230 @example
1231 Doc: add Baerenreiter and Henle solo cello suites
1232
1233 Added comparison of solo cello suite engravings to new essay with
1234 high-res images, fixed cropping on Finale example.
1235 @end example
1236
1237 Commit messages often start with a short prefix describing the
1238 general location of the changes.
1239
1240 @itemize
1241 @item
1242 Doc: and Doc-@var{**}:  If a commit affects the
1243 documentation in English (or in several languages simultaneously)
1244 the commit message should be prefixed with @qq{Doc:@tie{}}.  If the
1245 commit affects only one of the translations, the commit
1246 message should be prefixed with @qq{Doc-@var{**}:@tie{}}, where
1247 @var{**} is the two-letter language code.
1248
1249 @item
1250 Web: and Web-@var{**}:  Commits that affect the
1251 website should use @qq{Web:@tie{}} for English, and
1252 @qq{Web-@var{**}:@tie{}} for other languages.
1253
1254 @item
1255 CSS: Commits that change CSS files should use @qq{Web:@tie{}CSS:@tie{}}
1256 or @qq{Doc:@tie{}CSS:@tie{}} depending on whether they affect the
1257 website or the documentation/manuals.
1258
1259 @item
1260 Changes to a single file are often prefixed with the name of the file
1261 involved.
1262 @end itemize
1263
1264 Visit the links listed in @ref{Understanding commits} for examples.
1265
1266
1267
1268 @node Patches
1269 @subsection Patches
1270
1271 @menu
1272 * How to make a patch::
1273 * Emailing patches::
1274 @end menu
1275
1276 @node How to make a patch
1277 @unnumberedsubsubsec How to make a patch
1278
1279 If you want to share your changes with other contributors and
1280 developers, you need to generate @emph{patches} from your commits.
1281 We prefer it if you follow the instructions in
1282 @ref{Uploading a patch for review}.  However, we present an
1283 alternate method here.
1284
1285 You should always run @command{git@tie{}pull@tie{}-r} (translators
1286 should leave off the @option{-r}) before doing this to ensure that
1287 your patches are as current as possible.
1288
1289 Once you have made one or more commits in your local repository,
1290 and pulled the most recent commits from the remote branch, you can
1291 generate patches from your local commits with the command:
1292
1293 @example
1294 git format-patch origin
1295 @end example
1296
1297 The @code{origin} argument refers to the remote tracking branch at
1298 @code{git.sv.gnu.org}.  This command generates a separate patch
1299 for each commit that's in the current branch but not in the remote
1300 branch.  Patches are placed in the current working directory and
1301 will have names that look something like this:
1302
1303 @example
1304 0001-Doc-Fix-typos.patch
1305 0002-Web-Remove-dead-links.patch
1306 â‹®
1307 @end example
1308
1309 Send an email (must be less than 64 KB) to
1310 @email{lilypond-devel@@gnu.org} briefly explaining your work, with
1311 the patch files attached.  Translators should send patches to
1312 @email{translations@@lilynet.net}.  After your patches are
1313 reviewed, the developers may push one or more of them to the main
1314 repository or discuss them with you.
1315
1316
1317 @node Emailing patches
1318 @unnumberedsubsubsec Emailing patches
1319
1320 The default @code{x-diff} MIME type associated with patch files
1321 (i.e., files whose name ends in @code{.patch}) means that the
1322 encoding of line endings may be changed from UNIX to DOS format
1323 when they are sent as attachments.  Attempting to apply such an
1324 inadvertently altered patch will cause git to fail with a message
1325 about @q{whitespace errors}.
1326
1327 The solution to such problems is surprisingly simple---just change
1328 the default file extension of patches generated by git to end in
1329 @code{.txt}, for example:
1330
1331 @example
1332 git config format.suffix '.patch.txt'
1333 @end example
1334
1335 This should cause email programs to apply the correct base64
1336 encoding to attached patches.
1337
1338 If you receive a patch with DOS instead of UNIX line-endings, it
1339 can be converted back using the @code{dos2unix} utility.
1340
1341 Lots of useful information on email complications with patches is
1342 provided on the Wine wiki at
1343 @uref{http://wiki.winehq.org/GitWine}.
1344
1345
1346 @node Uploading a patch for review
1347 @subsection Uploading a patch for review
1348
1349 Any non-trivial change should be uploaded to our @qq{Rietveld}
1350 code review website:
1351
1352 @example
1353 @uref{http://codereview.appspot.com/}
1354 @end example
1355
1356 You can upload a patch for review by using our custom @code{git-cl}
1357 @q{helper-script}.  This section assumes you have already installed,
1358 updated, and configured @code{git-cl}.  See @ref{git-cl}.
1359
1360 @warning{Unless you are familiar with branches, only work on one
1361 set of changes at once.}
1362
1363 There are two methods, depending on your git setup.
1364
1365 @itemize
1366 @item
1367 @strong{Master branch}: (easy option)
1368
1369 If you added your patch to @code{master}, then:
1370
1371 @example
1372 git pull -r
1373 git-cl upload origin/master
1374 @end example
1375
1376 @c Mention staging here?
1377 If you have git push ability, make sure that you @emph{remove}
1378 your patch (with @command{git rebase} or @command{git reset})
1379 before pushing other stuff.
1380
1381 @c don't make this one an @example; we don't want to make it easy
1382 @c for people to use this accidently
1383 Notifications of patches are automatically added to our issue
1384 tracker to reduce the chance of patches getting lost.  To suppress
1385 this (not recommended), add the @code{-n / --no-code-issue}
1386 option.
1387
1388 @item
1389 @strong{Separate branch}: (complicated option)
1390
1391 Ensure your changes are committed in a separate branch, which should
1392 differ from the reference branch to be used (usually
1393 @code{origin/master}) by just the changes to be uploaded.  Checkout the
1394 branch with the changes:
1395
1396 @example
1397 git checkout some-branch-with-changes
1398 @end example
1399
1400 If the reference branch is to be @code{origin/master}, ensure that the
1401 branch containing the changes is up-to-date with it.  Use
1402 @command{git rebase} or @command{git pull -r} to rebase the branch to
1403 the head of @code{origin/master}.  For example:
1404
1405 @example
1406 git pull -r origin master
1407 @end example
1408
1409 Finally, start the upload by entering:
1410
1411 @example
1412 git-cl upload <reference SHA1 ID>
1413 @end example
1414
1415 @noindent
1416 where <reference SHA1 ID> is the SHA1 ID of the commit to be used
1417 as a reference source for the patch.  Generally, this will be the
1418 SHA1 ID of origin/master, and in that case you can just use the command:
1419
1420 @example
1421 git-cl upload origin/master
1422 @end example
1423
1424 @end itemize
1425
1426 First you will see a terminal editor where you can edit the
1427 message that will accompany your patch. @command{git-cl} will
1428 respect the @env{EDITOR} environment variable if defined,
1429 otherwise it will use @command{vi} as the default editor.
1430
1431 After prompting for your Google email address and password, the
1432 patch set will be posted to Rietveld, and you will be given a URL
1433 for your patch.
1434
1435 @warning{Some installations of git-cl fail when uploading a patch
1436 with certain filename extensions.  If this happens, it can
1437 generally be fixed by editing the list of exceptions at top of
1438 @file{git-cl.py}.}
1439
1440 @subsubheading Announcing your patch set
1441
1442 You should then announce the patch by logging into the code review
1443 issue webpage and using @qq{Publish + Mail Comments} to add a
1444 (mostly bogus) comment to your issue.  The text of your comment
1445 will be sent to our developer mailing list.
1446
1447 @warning{There is no automatic notification of a new patch; you
1448 must add a comment yourself.}
1449
1450 @subsubheading Revisions
1451
1452 As revisions are made in response to comments, successive patch sets
1453 for the same issue can be uploaded by reissuing the git-cl command
1454 with the modified branch checked out.
1455
1456 Sometimes in response to comments on revisions, the best way to
1457 work may require creation of a new branch in git.  In order to
1458 associate the new branch with an existing Rietveld issue,
1459 the following command can be used:
1460
1461 @example
1462 git-cl issue issue-number
1463 @end example
1464
1465 @noindent
1466 where @code{issue-number} is the number of the existing Rietveld
1467 issue.
1468
1469 @subsubheading Resetting git-cl
1470
1471 If @command{git-cl} becomes confused, you can @qq{reset} it by
1472 running:
1473
1474 @example
1475 git-cl issue 0
1476 @end example
1477
1478
1479 @node The patch review cycle
1480 @subsection The patch review cycle
1481
1482 Your patch will be available for reviews for the next few hours or
1483 days.  Three times a week, patches with no known problems are
1484 gathered into a @qq{patch countdown} and their status changed to
1485 @code{patch-countdown}.  The countdown is a 48-hour waiting period
1486 in which any final reviews or complaints should be made.
1487
1488 During the countdown, your patch may be set to
1489 @code{patch-needs_work}, indicating that you should fix something
1490 (or at least discuss why the patch needs no modification).  If no
1491 problems are found, the patch will be set to @code{patch-push}.
1492
1493 Once a patch has @code{patch-push}, it should be sent to your
1494 mentor for uploading.  If you have git push ability, look at
1495 @ref{Pushing to staging}.
1496
1497 @itemize
1498
1499 @item
1500 Patches get added to the tracker and to Rietveld by the @qq{git-cl} tool, with
1501 a status of @qq{patch-new}.
1502
1503 @item
1504 The automated tester, Patchy, verifies that the patch can be applied
1505 to current master.  By default, it checks that the patch allows @code{make}
1506 and @code{make test} to complete successfully.  It can also be configured to
1507 check that @code{make doc} is successful. If it passes, Patchy changes the
1508 status to @qq{patch-review} and emails the developer list.  If the patch
1509 fails, Patchy sets it to @qq{patch-needs_work} and notifies the developer list.
1510
1511 @item
1512 The Patch Meister reviews the tracker periodically, to list patches
1513 which have been on review for at least 24 hours. The list is found at
1514
1515 @smallexample
1516 @uref{http://code.google.com/p/lilypond/issues/list?can=2&q=label:patch%20patch=review&sort=modified+patch&colspec=ID%20Type%20Status%20Priority%20Owner%20Patch%20Summary%20Modified}
1517 @end smallexample
1518
1519 @item
1520 For each patch, the Handler reviews any discussion on the tracker
1521 and on Rietveld, to determine whether the patch can go forward.  If
1522 there is any indication that a developer thinks the patch is not
1523 ready, the Handler marks it @qq{patch-needs_work} and makes a comment
1524 regarding the reason, referring to the Rietveld item if needed.
1525
1526 @item
1527 Patches with explicit approval, or at least no negative comment, can
1528 be updated to @qq{patch-countdown}.  When saving the tracker item,
1529 clear the @qq{send email} box to prevent sending notification for
1530 each patch.
1531
1532 @item
1533 The Patch Meister sends an email to the developer list, with a fixed
1534 subject line, to enable filtering by email clients:
1535
1536 @example
1537 PATCH: Countdown to 20130113
1538 @end example
1539
1540 The text of the email sets the deadline for this countdown batch.  At
1541 present, batches are done on Tuesday, Thursday and Sunday evenings.
1542
1543 To create the countdown announcement, use the
1544 @code{make-countdown-announcement.sh} script, which takes the
1545 deadline date, and optionally your name.  Follow the instructions
1546 provided:
1547
1548 @example
1549 cd $LILYPOND_GIT
1550 scripts/auxiliar/make-countdown-announcement.sh "Jan 1, 2001" James
1551 @end example
1552
1553 The script produces an announcement that is easily readable in all
1554 email clients.  Also, whenever a new contributor submits a patch,
1555 you will be prompted to add the new username and author name to
1556 the script itself, and then commit those changes to the main git
1557 repository.
1558
1559
1560 @item
1561 On the scheduled countdown day, the Patch Meister reviews the
1562 previous list of patches on countdown, with the same procedure and
1563 criteria as before.  Patches with no controversy can be set to
1564 @qq{patch-push} with a courtesy message added to the comment block.
1565
1566 @item
1567 Roughly at six month intervals, the Patch Meister can list the
1568 patches which have been set to @qq{patch-needs-work} and send the
1569 results to the developer list for review.  In most cases, these
1570 patches should be marked @qq{patch-abandoned} but this should come
1571 from the developer if possible.
1572
1573 @item
1574 As in most organisations of unpaid volunteers, fixed procedures are
1575 useful in as much as they get the job done.  In our community, there
1576 is room for senior developers to bypass normal patch handling flows,
1577 particularly now that the testing of patches is largely automated.
1578 Similarly, the minimum age of 24 hours can reasonably be waived if
1579 the patch is minor and from an experienced developer.
1580
1581
1582 @end itemize
1583
1584 @ignore
1585 There is a single Patch Meister, and a number of Patch Helpers
1586 (rename this?).  The list of known patches awaiting review is:
1587
1588 @example
1589 @uref{http://code.google.com/p/lilypond/issues/list?can=2&q=label:patch&sort=patch}
1590 @end example
1591
1592
1593 @subheading Helpers: adding patches
1594
1595 The primary duty is to add patches to the google tracker; we have
1596 a bad track record of losing patches in email.  Patches generally
1597 come to the @code{lilypond-devel} mailing list, but are sometimes
1598 sent to @code{bug-lilypond}, @code{lilypond-users}, or
1599 @code{frogs} mailing list instead.
1600
1601 @itemize
1602 @item
1603 Unless a patch is clearly in response to an existing issue, add a
1604 new issue with the @code{Patch-new} label and a link to the patch
1605 (either on the mailing list archives or the codereview url).
1606
1607 Issue numbers are cheap; losing developers because they got fed up
1608 with us losing their hard work is expensive.
1609
1610
1611 @c if we enter patches immediately, I don't think this is relevant.
1612
1613 @item
1614 Before adding a patch-reminder issue, do a quick check to see if
1615 it was pushed without sending any email.  This can be checked for
1616 searching for relevant terms (from the patch subject or commit
1617 message) on the webgit page:
1618
1619 @example
1620 @uref{http://git.savannah.gnu.org/gitweb/?p=lilypond.git}
1621 @end example
1622
1623
1624 @item
1625 If the patch is clearly in response to an existing issue, then
1626 update that issue with the @code{Patch-new} label and a link to
1627 the patch (either on the mailing list archives or the codereview
1628 url).
1629
1630 @item
1631 After adding the issue, please send a response email to the same
1632 group(s) that the initial patch was sent to.
1633
1634 If the initial email was sent to multiple mailing lists (such as
1635 both @code{bugs} and @code{devel}), then reply to all those
1636 mailing lists as well.  The email should contain a link to the
1637 issue you just added.
1638
1639 @end itemize
1640
1641 @subheading Helpers: @code{Patch-review} label
1642
1643 The secondary duty is to do make sure that every issue in the
1644 tracker with a @code{Patch-review} label has passed these
1645 @qq{obvious} tests:
1646
1647 @itemize
1648 @item
1649 Applies automatically to git master.
1650
1651 It's ok to have offsets, but not conflicts.
1652
1653 @item
1654 Regtest comparison looks ok; no unexpected changes.
1655
1656 @item
1657 Descriptive subject line.
1658
1659 Avoid subjects like @qq{fixes 123}; instead write @qq{Doc: discuss
1660 stacking-dir for BassFigureAlignment (fix 123)}.
1661
1662 @item
1663 Compiles docs from scratch.  Only check this if you have reason to
1664 suspect it might not work.
1665
1666 @item
1667 (maybe)
1668
1669 Check code indentation and style.  This should be easier post-GOP
1670 when we have a better-defined code style.
1671
1672 @end itemize
1673
1674
1675 @subheading Patch Meister
1676
1677 The Patch Meister will:
1678
1679 @itemize
1680
1681 @item
1682 send @qq{countdown} emails to
1683 @code{lilypond-devel} when patches appear to be ready.
1684
1685 @item
1686 send general requests to review patches, or even nasty requests to
1687 review patches.
1688
1689 @item
1690 downgrade patches from @code{Patch-review} to
1691 @code{Patch-needs_work} as appropriate.
1692
1693 @item
1694 downgrade patches from @code{Patch-needs_work} to
1695 @code{Patch-abandoned} if no actions have been taken in four
1696 weeks.
1697
1698 @end itemize
1699
1700 @end ignore
1701
1702
1703 @node Advanced Git procedures
1704 @section Advanced Git procedures
1705
1706
1707 @warning{This section is not necessary for normal contributors;
1708 these commands are presented for information for people interested
1709 in learning more about git.}
1710
1711 It is possible to work with several branches on the same local Git
1712 repository; this is especially useful for translators who may have
1713 to deal with both @code{translation} and a stable branch,
1714 e.g. @code{stable/2.12}.
1715
1716 Some Git commands are introduced first, then a workflow with
1717 several Git branches of LilyPond source code is presented.
1718
1719
1720 @menu
1721 * Merge conflicts::
1722 * Advanced Git concepts::
1723 * Resolving conflicts::
1724 * Reverting all local changes::
1725 * Working with remote branches::
1726 * Git log::
1727 * Applying remote patches::
1728 * Cleaning up multiple patches::
1729 * Commit access::
1730 * Pushing to staging::
1731 @end menu
1732
1733
1734 @node Merge conflicts
1735 @subsection Merge conflicts
1736
1737 To be filled in later, and/or moved to a different section.  I
1738 just wanted to make sure that I had a stub ready somewhere.
1739
1740
1741 @node Advanced Git concepts
1742 @subsection Advanced Git concepts
1743
1744
1745 A bit of Git vocabulary will be explained below.  The following is
1746 only introductory; for a better understanding of Git concepts, you
1747 may wish to read @ref{Other Git documentation}.
1748
1749 The @code{git@tie{}pull@tie{}origin} command above is just a
1750 shortcut for this command:
1751
1752 @example
1753 git pull git://git.sv.gnu.org/lilypond.git/ @var{branch}:origin/@var{branch}
1754 @end example
1755
1756 @noindent
1757 where @code{@var{branch}} is typically @code{master} or
1758 @code{translation}; if you do not know or remember, see
1759 @ref{Downloading remote branches} to remember which commands you
1760 issued or which source code you wanted to get.
1761
1762 A @emph{commit} is a set of changes made to the sources; it also
1763 includes the committish of the parent commit, the name and e-mail
1764 of the @emph{author} (the person who wrote the changes), the name
1765 and e-mail of the @emph{committer} (the person who brings these
1766 changes into the Git repository), and a commit message.
1767
1768 A @emph{committish} is the SHA1 checksum of a commit, a number
1769 made of 40 hexadecimal digits, which acts as the internal unique
1770 identifier for this commit.  To refer to a particular revision,
1771 don't use vague references like the (approximative) date, simply
1772 copy and paste the committish.
1773
1774 A @emph{branch} is nothing more than a pointer to a particular
1775 commit, which is called the @emph{head} of the branch; when
1776 referring to a branch, one often actually thinks about its head
1777 and the ancestor commits of the head.
1778
1779 Now we will explain the two last commands you used to get the
1780 source code from Git---see @ref{Downloading individual branches}.
1781
1782 @example
1783 git remote add -ft @var{branch} -m @var{branch} \
1784   origin git://git.sv.gnu.org/lilypond.git/
1785
1786 git checkout -b @var{branch} origin/@var{branch}
1787 @end example
1788
1789 The @command{git@tie{}remote} has created a branch called
1790 @code{origin/@var{branch}} in your local Git repository.  As this
1791 branch is a copy of the remote branch web from git.sv.gnu.org
1792 LilyPond repository, it is called a @emph{remote branch}, and is
1793 meant to track the changes on the branch from git.sv.gnu.org: it
1794 will be updated every time you run
1795 @command{git@tie{}pull@tie{}origin} or
1796 @command{git@tie{}fetch@tie{}origin}.
1797
1798 The @command{git@tie{}checkout} command has created a branch named
1799 @code{@var{branch}}.  At the beginning, this branch is identical
1800 to @code{origin/@var{branch}}, but it will differ as soon as you
1801 make changes, e.g. adding newly translated pages or editing some
1802 documentation or code source file.  Whenever you pull, you merge
1803 the changes from @code{origin/@var{branch}} and
1804 @code{@var{branch}} since the last pulling.  If you do not have
1805 push (i.e. @qq{write}) access on git.sv.gnu.org, your
1806 @code{@var{branch}} will always differ from
1807 @code{origin/@var{branch}}.  In this case, remember that other
1808 people working like you with the remote branch @code{@var{branch}}
1809 of git://git.sv.gnu.org/lilypond.git/ (called
1810 @code{origin/@var{branch}} on your local repository) know nothing
1811 about your own @code{@var{branch}}: this means that whenever you
1812 use a committish or make a patch, others expect you to take the
1813 latest commit of @code{origin/@var{branch}} as a reference.
1814
1815 Finally, please remember to read the man page of every Git command
1816 you will find in this manual in case you want to discover
1817 alternate methods or just understand how it works.
1818
1819
1820 @node Resolving conflicts
1821 @subsection Resolving conflicts
1822
1823
1824 Occasionally an update may result in conflicts -- this happens
1825 when you and somebody else have modified the same part of the same
1826 file and git cannot figure out how to merge the two versions
1827 together.  When this happens, you must manually merge the two
1828 versions.
1829
1830 If you need some documentation to understand and resolve
1831 conflicts, see paragraphs @emph{How conflicts are presented} and
1832 @emph{How to resolve conflicts} in @command{git merge} man page.
1833
1834 If all else fails, you can follow the instructions in
1835 @ref{Reverting all local changes}.  Be aware that this eliminates
1836 any changes you have made!
1837
1838
1839 @node Reverting all local changes
1840 @subsection Reverting all local changes
1841
1842 Sometimes git will become hopelessly confused, and you just want
1843 to get back to a known, stable state.  This command destroys any
1844 local changes you have made in the currently checked-out branch,
1845 but at least you get back to the current online version:
1846
1847 @example
1848 git reset --hard origin/master
1849 @end example
1850
1851
1852 @node Working with remote branches
1853 @subsection Working with remote branches
1854
1855
1856 @subsubheading Fetching new branches from git.sv.gnu.org
1857
1858 To fetch and check out a new branch named @code{@var{branch}} on
1859 git.sv.gnu.org, run from top of the Git repository
1860
1861 @example
1862 git config --add remote.origin.fetch \
1863   +refs/heads/@var{branch}:refs/remotes/origin/@var{branch}
1864
1865 git checkout --track -b @var{branch} origin/@var{branch}
1866 @end example
1867
1868 After this, you can pull @code{@var{branch}} from git.sv.gnu.org
1869 with:
1870
1871 @example
1872 git pull
1873 @end example
1874
1875 Note that this command generally fetches all branches you added
1876 with @command{git@tie{}remote@tie{}add} (when you initialized the
1877 repository) or @command{git@tie{}config@tie{}--add}, i.e. it
1878 updates all remote branches from remote @code{origin}, then it
1879 merges the remote branch tracked by the current branch into the
1880 current branch.  For example, if your current branch is
1881 @code{master}, @code{origin/master} will be merged into
1882 @code{master}.
1883
1884
1885 @subsubheading Local clones, or having several working trees
1886
1887 If you play with several Git branches, e.g. @code{master},
1888 @code{translation}, @code{stable/2.12}), you may want to
1889 have one source and build tree for each branch; this is possible
1890 with subdirectories of your local Git repository, used as local
1891 cloned subrepositories.  To create a local clone for the branch
1892 named @code{@var{branch}}, run
1893
1894 @example
1895 git checkout @var{branch}
1896 git clone -lsn . @var{subdir}
1897 cd @var{subdir}
1898 git reset --hard
1899 @end example
1900
1901 Note that @code{@var{subdir}} must be a directory name which does
1902 not already exist.  In @code{@var{subdir}}, you can use all Git
1903 commands to browse revisions history, commit and uncommit changes;
1904 to update the cloned subrepository with changes made on the main
1905 repository, cd into @code{@var{subdir}} and run
1906 @command{git@tie{}pull}; to send changes made on the subrepository
1907 back to the main repository, run @command{git@tie{}push} from
1908 @code{@var{subdir}}.  Note that only one branch (the currently
1909 checked out branch) is created in the subrepository by default; it
1910 is possible to have several branches in a subrepository and do
1911 usual operations (checkout, merge, create, delete...) on these
1912 branches, but this possibility is not detailed here.
1913
1914 When you push @code{@var{branch}} from @code{@var{subdir}} to the
1915 main repository, and @code{@var{branch}} is checked out in the
1916 main repository, you must save uncommitted changes (see
1917 @command{git@tie{}stash}) and do
1918 @command{git@tie{}reset@tie{}--hard} in the main repository in
1919 order to apply pushed changes in the working tree of the main
1920 repository.
1921
1922
1923 @node Git log
1924 @subsection Git log
1925
1926
1927 The commands above don't only bring you the latest version of the
1928 sources, but also the full history of revisions (revisions, also
1929 called commits, are changes made to the sources), stored in the
1930 @file{.git} directory.  You can browse this history with
1931
1932 @example
1933 git log     # only shows the logs (author, committish and commit message)
1934 git log -p  # also shows diffs
1935 gitk        # shows history graphically
1936 @end example
1937
1938 @warning{The @code{gitk} command may require a separate
1939 @code{gitk} package, available in the appropriate distribution's
1940 repositories.}
1941
1942
1943 @node Applying remote patches
1944 @subsection Applying remote patches
1945
1946
1947 TODO: Explain how to determine if a patch was created with
1948 @code{git@tie{}format-patch}.
1949
1950 Well-formed git patches created with @code{git@tie{}format-patch}
1951 should be committed with the following command:
1952
1953 @example
1954 git am @var{patch}
1955 @end example
1956
1957 Patches created without @code{git@tie{}format-patch} can be
1958 applied in two steps.  The first step is to apply the patch to the
1959 working tree and the index:
1960
1961 @example
1962 git apply --index @var{patch}
1963 @end example
1964
1965 @noindent
1966 The second step is to commit the changes and give credit to the
1967 author of the patch.  This can be done with the following command:
1968
1969 @example
1970 git commit --author="@var{John Smith} <@var{john@@example.com}>"
1971 @end example
1972
1973 Please note that using the @code{--index} option for patching is quite
1974 important here and @emph{cannot} reliably be replaced by using the
1975 @code{-a} option when committing: that would only commit files from the
1976 working tree that are already registered with git, so every file that
1977 the patch actually @emph{adds}, like a regtest for a fixed bug, would
1978 get lost.  For the same reason, you should not use the git-independent
1979 @samp{patch} program for applying patches.
1980
1981
1982
1983 @node Cleaning up multiple patches
1984 @subsection Cleaning up multiple patches
1985
1986 If you have been developing on your own branch for a while, you
1987 may have more commmits than is really sensible.  To revise your
1988 work and condense commits, use:
1989
1990 @example
1991 git rebase origin/master
1992 git rebase -i origin/master
1993 @end example
1994
1995 @warning{Be a bit cautious -- if you completely remove commits
1996 during the interactive session, you will... err... completely
1997 remove those commits.}
1998
1999
2000 @node Commit access
2001 @subsection Commit access
2002
2003 Most contributors are not able to commit patches directly to the
2004 main repository---only members of the LilyPond development team
2005 have @emph{commit access}.  If you are a contributor and are
2006 interested in joining the development team, contact the Project
2007 Manager through the mailing list
2008 (@email{lilypond-devel@@gnu.org}).  Generally, only contributors
2009 who have already provided a number of patches which have been
2010 pushed to the main repository will be considered for membership.
2011
2012 If you have been approved by the Project Manager, use the
2013 following procedure to obtain commit access:
2014
2015 @enumerate
2016 @item
2017 If you don't already have one, set up a Savannah user account at
2018 @uref{https://savannah.gnu.org/account/register.php}.  If your web
2019 browser responds with an @qq{untrusted connection} message when
2020 you visit the link, follow the steps for including the CAcert root
2021 certificate in your browser, given at
2022 @uref{http://savannah.gnu.org/tls/tutorial/}.
2023
2024 @warning{Savannah will silently put your username in lower-case --
2025 do not try to use capital letters.}
2026
2027
2028 @item
2029 After registering, if you are not logged in automatically, login
2030 at @uref{https://savannah.gnu.org/account/login.php}---this should
2031 take you to your @qq{my} page
2032 (@uref{https://savannah.gnu.org/my/}).
2033
2034
2035 @item
2036 Click on the @qq{My Groups} link to access the @qq{My Group
2037 Membership} page.  From there, find the @qq{Request for Inclusion}
2038 box and search for @qq{LilyPond}.  Among the search results, check
2039 the box labeled @qq{GNU LilyPond Music Typesetter} and write a
2040 brief (required) message for the Project Manager (@qq{Hey it's
2041 me!} should be fine).
2042
2043 Note that you will not have commit access until the Project
2044 Manager activates your membership.  Once your membership is
2045 activated, LilyPond should appear under the heading @qq{Groups I'm
2046 Contributor of} on your @qq{My Group Membership} page.
2047
2048
2049 @item
2050 Generate an SSH @q{rsa} key pair.  Enter the following at the
2051 command prompt:
2052
2053 @example
2054 ssh-keygen -t rsa
2055 @end example
2056
2057 When prompted for a location to save the key, press <ENTER> to
2058 accept the default location (@file{~/.ssh/id_rsa}).
2059
2060 Next you are asked to enter an optional passphrase.  On most
2061 systems, if you use a passphrase, you will likely be prompted for
2062 it every time you use @command{git@tie{}push} or
2063 @command{git@tie{}pull}.  You may prefer this since it can protect
2064 you from your own mistakes (like pushing when you mean to pull),
2065 though you may find it tedious to keep re-entering it.
2066
2067 You can change/enable/disable your passphrase at any time with:
2068
2069 @example
2070 ssh-keygen -f ~/.ssh/id_rsa -p
2071 @end example
2072
2073 Note that the GNOME desktop has a feature which stores your
2074 passphrase for you for an entire GNOME session.  If you use a
2075 passphrase to @qq{protect you from yourself}, you will want to
2076 disable this feature, since you'll only be prompted once.  Run the
2077 following command, then logout of GNOME and log back in:
2078
2079 @example
2080 gconftool-2 --set -t bool \
2081   /apps/gnome-keyring/daemon-components/ssh false
2082 @end example
2083
2084 After setting up your passphrase, your private key is saved as
2085 @file{~/.ssh/id_rsa} and your public key is saved as
2086 @file{~/.ssh/id_rsa.pub}.
2087
2088
2089 @item
2090 Register your public SSH @q{rsa} key with Savannah.  From the
2091 @qq{My Account Configuration} page, click on @qq{Edit SSH Keys},
2092 then paste the contents of your @file{~/.ssh/id_rsa.pub} file into
2093 one of the @qq{Authorized keys} text fields, and click
2094 @qq{Update}.
2095
2096 Savannah should respond with something like:
2097
2098 @example
2099 Success: Key #1 seen Keys registered
2100 @end example
2101
2102
2103 @item
2104 Configure Git to use the SSH protocol (instead of the GIT
2105 protocol).  From your local Git repository, enter:
2106
2107 @example
2108 git config remote.origin.url \
2109   ssh://@var{user}@@git.sv.gnu.org/srv/git/lilypond.git
2110 @end example
2111
2112 @noindent
2113 replacing @var{user} with your Savannah username.
2114
2115
2116 @item
2117 After your membership has been activated and you've configured Git
2118 to use SSH, test the connection with:
2119
2120 @example
2121 git pull --verbose
2122 @end example
2123
2124 SSH should issue the following warning:
2125
2126 @example
2127 The authenticity of host 'git.sv.gnu.org (140.186.70.72)' can't
2128 be established.
2129 RSA key fingerprint is
2130 80:5a:b0:0c:ec:93:66:29:49:7e:04:2b:fd:ba:2c:d5.
2131 Are you sure you want to continue connecting (yes/no)?
2132 @end example
2133
2134 Make sure the RSA key fingerprint displayed matches the one above.
2135 If it doesn't, respond @qq{no} and check that you configured Git
2136 properly in the previous step.  If it does match, respond
2137 @qq{yes}.  SSH should then issue another warning:
2138
2139 @example
2140 Warning: Permanently added 'git.sv.gnu.org,140.186.70.72' (RSA) to
2141 the list of known hosts.
2142 @end example
2143
2144 The list of known hosts is stored in the file
2145 @file{~/.ssh/known_hosts}.
2146
2147 At this point, you are prompted for your passphrase if you have
2148 one, then Git will attempt a pull.
2149
2150 If @command{git@tie{}pull@tie{}--verbose} fails, you should see
2151 error messages like these:
2152
2153 @example
2154 Permission denied (publickey).
2155 fatal: The remote end hung up unexpectedly
2156 @end example
2157
2158 If you get the above error, you may have made a mistake when
2159 registering your SSH key at Savannah.  If the key is properly
2160 registered, you probably just need to wait for the Savannah server
2161 to activate it.  It usually takes a few minutes for the key to be
2162 active after registering it, but if it still doesn't work after an
2163 hour, ask for help on the mailing list.
2164
2165 If @command{git@tie{}pull@tie{}--verbose} succeeds, the output
2166 will include a @q{From} line that shows @q{ssh} as the protocol:
2167
2168 @example
2169 From ssh://git.sv.gnu.org/srv/git/lilypond
2170 @end example
2171
2172 If the protocol shown is not @q{ssh}, check that you configured
2173 Git properly in the previous step.
2174
2175
2176 @item
2177 Test your commit access with a dry run:
2178
2179 @warning{Do not push directly to master; instead, push to staging.
2180 See @ref{Pushing to staging}.}
2181
2182 @example
2183 git push --dry-run --verbose
2184 @end example
2185
2186 Note that recent versions of Git (Git 1.6.3 or later) will issue a
2187 big warning if the above command is used.  The simplest solution
2188 is to tell Git to push all matching branches by default:
2189
2190 @example
2191 git config push.default matching
2192 @end example
2193
2194 @noindent
2195 Then @code{git@tie{}push} should work as before.  For more
2196 details, consult the @code{git@tie{}push} man page.
2197
2198
2199 @item
2200 Repeat the steps from generating an RSA key through to testing
2201 your commit access, for each machine from which you will be
2202 making commits, or you may simply copy the files from your
2203 local @file{~/.ssh} folder to the same folder on the other
2204 machine.
2205
2206 @end enumerate
2207
2208 @subsubheading Technical details
2209
2210 @itemize
2211 @item
2212 On Firefox, to view or remove the CAcert root certificate, go to:
2213 Edit > Preferences > Advanced > Encryption > View Certificates >
2214 Authorities > Certificate Name > Root CA > CA Cert Signing
2215 Authority.
2216
2217 @item
2218 The @command{git@tie{}config} commands above should modify your
2219 local repository's @file{.git/config} file.  These lines:
2220
2221 @example
2222 [remote "origin"]
2223         url = git://git.sv.gnu.org/lilypond.git/
2224 @end example
2225
2226 @noindent
2227 should now be changed to:
2228
2229 @example
2230 [remote "origin"]
2231         url = ssh://@var{user}@@git.sv.gnu.org/srv/git/lilypond.git
2232 @end example
2233
2234 @noindent
2235 where @var{user} is your login name on Savannah.
2236
2237 @item
2238 Similarly, the
2239 @command{git@tie{}config@tie{}push.default@tie{}matching} command
2240 should add these lines to @file{.git/config}:
2241
2242 @example
2243 [push]
2244         default = matching
2245 @end example
2246 @end itemize
2247
2248 @knownissues
2249 Encryption protocols, including ssh, generally do not permit packet
2250 fragmentation to avoid introducing a point of insecurity.  This
2251 means that the maximum packet size must not exceed the smallest
2252 MTU (Maximum Transmission Unit) set in the routers along the path.
2253 This smallest MTU is determined by a procedure during call set-up
2254 which relies on the transmission over the path of ICMP packets.
2255 If any of the routers in the path block ICMP packets this mechanism
2256 fails, resulting in the possibility of packets being transmitted
2257 which exceed the MTU of one of the routers.  If this happens the
2258 packet is discarded, causing the ssh session to hang, timeout or
2259 terminate with the error message
2260
2261 @example
2262 ssh: connect to host <host ip addr> port 22: Bad file number
2263 fatal: The remote end hung up unexpectedly
2264 @end example
2265
2266 depending on precisely when in the proceedings the first large
2267 packet is transmitted.  Most routers on the internet have MTU
2268 set to 1500, but routers installed in homes to connect via
2269 broadband may use a slightly smaller MTU for efficient transmission
2270 over ATM.  If this problem is encountered a possible work-around is
2271 to set the MTU in the local router to 1500.
2272
2273
2274 @node Pushing to staging
2275 @subsection Pushing to staging
2276
2277 Do not push directly to the git @code{master} branch.  Instead,
2278 push to @code{staging}.
2279
2280 You will not see your patch on @code{origin/master} until some
2281 automatic tests have been run.  These tests are run every couple
2282 of hours; please wait at least 12 hours before wondering if your
2283 patch has been lost.  Note that you can check the commits on
2284 @code{origin/staging} by looking at the git web interface on
2285 savannah.
2286
2287 It may happen occasionally that the staging branch breaks automated
2288 testing.  In this case the automatic move of staging material to
2289 master gets halted in order to avoid broken material entering master.
2290 This is a safety net.  Please do not try breaking out from it by
2291 adding fixes on top of staging: in that case the whole sequence will
2292 end up in master after all, defeating the purpose of the system.  The
2293 proper fix usually involves rewriting the staging branch and is best
2294 left to core developers after discussion on the developer list.
2295
2296 Before pushing to staging it is a good practice to check whether
2297 staging is ahead of master, and if so, wait until master has caught up
2298 with staging before pushing.  This simplifies things if changes to
2299 staging have to be backed out for some reason.  To check whether
2300 master has caught up with staging you can look at the git web interface
2301 on savannah, or do:
2302
2303 @example
2304 git fetch
2305 gitk
2306 @end example
2307
2308 and check that @code{origin/master} is at the same commit as
2309 @code{origin/staging}.  Another option is to see if any commits are
2310 listed when you do:
2311
2312 @example
2313 git fetch
2314 git log origin/master..origin/staging
2315 @end example
2316
2317 @subsubheading If your work is in a patch file
2318
2319 Assuming that your patch is in a file called
2320 @file{0001-my-patch.patch} (see @ref{Patches}), and you are currently
2321 on git master, do:
2322
2323 @example
2324 git checkout staging
2325 git pull -r
2326 git am 0001-my-patch.patch
2327 gitk
2328 git push origin staging
2329 git checkout master
2330 @end example
2331
2332 @warning{Do not skip the @command{gitk} step; a quick 5-second
2333 check of the visual history can save a great deal of frustration
2334 later on.  You should only see that @command{staging} is only 1
2335 commit ahead of @code{origin/staging}.}
2336
2337 @subsubheading If your work is in a branch
2338
2339 If you are working on branches and your work is in
2340 @code{my_branch_name}, then do:
2341
2342 @example
2343 git checkout my_branch_name
2344 git pull -r origin staging
2345 @end example
2346
2347 This will rebase your branch on @code{origin/staging}.  At this point
2348 git will let you know if there are any conflicts.  If so, resolve them
2349 before continuing:
2350
2351 @example
2352 gitk
2353 git push origin HEAD:staging
2354 @end example
2355
2356 @warning{Do not skip the @command{gitk} step; a quick 5-second
2357 check of the visual history can save a great deal of frustration
2358 later on.  You should see that @code{my_branch_name} is only ahead of
2359 @code{origin/staging} by the commits from your branch.}
2360
2361
2362
2363 @node Git on Windows
2364 @section Git on Windows
2365
2366 @warning{We heavily recommend that development be done with our
2367 virtual machine @ref{LilyDev}.}
2368
2369 @c Some of this may duplicate stuff in other sections
2370 @c But it is probably best for windows users to have it all together
2371 @c If necessary, clear this up later  -td
2372
2373 TODO: Decide what to do with this...  Pare it down?  Move
2374 paragraphs next to analogous Unix instructions? -mp
2375
2376 @subsection Background to nomenclature
2377
2378 Git is a system for tracking the changes made to source files by a
2379 distributed set of editors.  It is designed to work without a
2380 master repository, but we have chosen to have a master repository
2381 for LilyPond files.  Editors hold a local copy of the master
2382 repository together with any changes they have made locally.
2383 Local changes are held in a local @q{branch}, of which there may
2384 be several, but these instructions assume you are using just one.
2385 The files visible in the local repository always correspond to
2386 those on the currently @q{checked out} local branch.
2387
2388 Files are edited on a local branch, and in that state the changes
2389 are said to be @q{unstaged}.  When editing is complete, the
2390 changes are moved to being @q{staged for commit}, and finally the
2391 changes are @q{committed} to the local branch.  Once committed,
2392 the changes (called a @q{commit}) are given a unique 40-digit
2393 hexadecimal reference number called the @q{Committish} or @q{SHA1
2394 ID} which identifies the commit to Git.  Such committed changes
2395 can be sent to the master repository by @q{pushing} them (if you
2396 have write permission) or by sending them by email to someone who
2397 has, either as a complete file or as a @q{diff} or @q{patch}
2398 (which send just the differences from the master repository).
2399
2400 @subsection Installing git
2401
2402 Obtain Git from
2403 @uref{https://git-for-windows.github.io/}.
2404
2405 Note that most users will not need to install SSH.  That is not
2406 required until you have been granted direct push permissions to
2407 the master git repository.
2408
2409 Start Git by clicking on the desktop icon.  This will bring up a
2410 command line bash shell.  This may be unfamiliar to Windows users.
2411 If so, follow these instructions carefully.  Commands are entered
2412 at a $ prompt and are terminated by keying a newline.
2413
2414 @subsection Initialising Git
2415
2416 Decide where you wish to place your local Git repository, creating
2417 the folders in Windows as necessary.  Here we call the folder to
2418 contain the repository @code{[path]/Git}, but if you intend using
2419 Git for other projects a directory name like @code{lilypond-git}
2420 might be better.  You will need to have space for around
2421 100Mbytes.
2422
2423 Start the Git bash shell by clicking on the desk-top icon
2424 installed with Git and type
2425
2426 @example
2427 cd [path]/Git
2428 @end example
2429
2430 to position the shell at your new Git repository.
2431
2432 Note: if [path] contains folders with names containing spaces use
2433
2434 @example
2435 cd "[path]/Git"
2436 @end example
2437
2438 Then type
2439
2440 @example
2441 git init
2442 @end example
2443
2444 to initialize your Git repository.
2445
2446 Then type (all on one line; the shell will wrap automatically)
2447
2448 @example
2449 git remote add -ft master origin git://git.sv.gnu.org/lilypond.git
2450 @end example
2451
2452 to download the lilypond master files.
2453
2454 @warning{Be patient!  Even on a broadband connection this can take
2455 10 minutes or more.  Wait for lots of [new tag] messages and the $
2456 prompt.}
2457
2458 We now need to generate a local copy of the downloaded files in a
2459 new local branch.  Your local branch needs to have a name.  It is
2460 usual to call it @q{master} and we shall do that here.
2461
2462 To do this, type
2463
2464 @example
2465 git checkout -b master origin/master
2466 @end example
2467
2468 This creates a second branch called @q{master}.  You will see two
2469 warnings (ignore these), and a message advising you that your
2470 local branch @q{master} has been set up to track the remote
2471 branch.  You now have two branches, a local branch called
2472 @q{master}, and a tracking branch called @q{origin/master}, which
2473 is a shortened form of @q{remotes/origin/master}.
2474
2475 Return to Windows Explorer and look in your Git repository.  You
2476 should see lots of folders.  For example, the LilyPond
2477 documentation can be found in [path]/Git/Documentation/.
2478
2479 The Git bash shell is terminated by typing @code{exit} or by
2480 clicking on the usual Windows close-window widget.
2481
2482 @subsection Git GUI
2483
2484 Almost all subsequent work will use the Git Graphical User
2485 Interface, which avoids having to type command line commands.  To
2486 start Git GUI first start the Git bash shell by clicking on the
2487 desktop icon, and type
2488
2489 @example
2490 cd [path]/Git
2491 git gui
2492 @end example
2493
2494 The Git GUI will open in a new window.  It contains four panels
2495 and 7 pull-down menus.  At this stage do not use any of the
2496 commands under Branch, Commit, Merge or Remote.  These will be
2497 explained later.
2498
2499 The top panel on the left contains the names of files which you
2500 are in the process of editing (Unstaged Changes), and the lower
2501 panel on the left contains the names of files you have finished
2502 editing and have staged ready for committing (Staged Changes).  At
2503 present, these panels will be empty as you have not yet made any
2504 changes to any file.  After a file has been edited and saved the
2505 top panel on the right will display the differences between the
2506 edited file selected in one of the panels on the left and the last
2507 version committed on the current branch.
2508
2509 The panel at bottom right is used to enter a descriptive message
2510 about the change before committing it.
2511
2512 The Git GUI is terminated by entering CNTL-Q while it is the
2513 active window or by clicking on the usual Windows close-window
2514 widget.
2515
2516 @subsection Personalising your local git repository
2517
2518 Open the Git GUI, click on
2519
2520 @example
2521 Edit -> Options
2522 @end example
2523
2524 and enter your name and email address in the left-hand (Git
2525 Repository) panel.  Leave everything else unchanged and save it.
2526
2527 Note that Windows users must leave the default setting for line
2528 endings unchanged.  All files in a git repository must have lines
2529 terminated by just a LF, as this is required for Merge to work,
2530 but Windows files are terminated by CRLF by default.  The git
2531 default setting causes the line endings of files in a Windows git
2532 repository to be flipped automatically between LF and CRLF as
2533 required.  This enables files to be edited by any Windows editor
2534 without causing problems in the git repository.
2535
2536 @subsection Checking out a branch
2537
2538 At this stage you have two branches in your local repository,
2539 both identical.  To see them click on
2540
2541 @example
2542 Branch -> Checkout
2543 @end example
2544
2545 You should have one local branch called @q{master} and one
2546 tracking branch called @q{origin/master}.  The latter is your
2547 local copy of the @q{remotes/origin/master} branch in the master
2548 LilyPond repository.  The local @q{master} branch is where you
2549 will make your local changes.
2550
2551 When a particular branch is selected, i.e., checked out, the files
2552 visible in your repository are changed to reflect the state of the
2553 files on that branch.
2554
2555 @subsection Updating files from @q{remote/origin/master}
2556
2557 Before starting the editing of a file, ensure your local
2558 repository contains the latest version of the files in the remote
2559 repository by first clicking
2560
2561 @example
2562 Remote -> Fetch from -> origin
2563 @end example
2564
2565 @noindent
2566 in the Git GUI.
2567
2568 This will place the latest version of every file, including all
2569 the changes made by others, into the @q{origin/master} branch of
2570 the tracking branches in your git repository.  You can see these
2571 files by checking out this branch, but you must @emph{never} edit
2572 any files while this branch is checked out.  Check out your local
2573 @q{master} branch again.
2574
2575 You then need to merge these fetched files into your local
2576 @q{master} branch by clicking on
2577
2578 @example
2579 Merge -> Local Merge
2580 @end example
2581
2582 @noindent
2583 and if necessary select the local @q{master} branch.
2584
2585 Note that a merge cannot be completed if you have made any local
2586 changes which have not yet been committed.
2587
2588 This merge will update all the files in the @q{master} branch to
2589 reflect the current state of the @q{origin/master} branch.  If any
2590 of the changes conflict with changes you have made yourself
2591 recently you will be notified of the conflict (see below).
2592
2593 @subsection Editing files
2594
2595 First ensure your @q{master} branch is checked out, then simply
2596 edit the files in your local Git repository with your favourite
2597 editor and save them back there.  If any file contains non-ASCII
2598 characters ensure you save it in UTF-8 format.  Git will detect
2599 any changes whenever you restart Git GUI and the file names will
2600 then be listed in the Unstaged Changes panel.  Or you can click
2601 the Rescan button to refresh the panel contents at any time.  You
2602 may break off and resume editing any time.
2603
2604 The changes you have made may be displayed in diff form in the top
2605 right-hand panel of Git GUI by clicking on the file name shown in
2606 one of the left panels.
2607
2608 When your editing is complete, move the files from being Unstaged
2609 to Staged by clicking the document symbol to the left of each
2610 name.  If you change your mind it can be moved back by clicking on
2611 the ticked box to the left of the name.
2612
2613 Finally the changes you have made may be committed to your
2614 @q{master} branch by entering a brief message in the Commit
2615 Message box and clicking the Commit button.
2616
2617 If you wish to amend your changes after a commit has been made,
2618 the original version and the changes you made in that commit may
2619 be recovered by selecting
2620
2621 @example
2622 Commit -> Amend Last Commit
2623 @end example
2624
2625 @noindent
2626 or by checking the Amend Last Commit radio button at bottom right.
2627 This will return the changes to the Staged state, so further
2628 editing made be carried out within that commit.  This must only be
2629 done @emph{before} the changes have been Pushed or sent to your
2630 mentor for Pushing - after that it is too late and corrections
2631 have to be made as a separate commit.
2632
2633
2634 @subsection Sending changes to @q{remotes/origin/master}
2635
2636 If you do not have write access to @q{remotes/origin/master} you
2637 will need to send your changes by email to someone who does.
2638
2639 First you need to create a diff or patch file containing your
2640 changes.  To create this, the file must first be committed.  Then
2641 terminate the Git GUI.  In the git bash shell first cd to your Git
2642 repository with
2643
2644 @example
2645 cd [path]/Git
2646 @end example
2647
2648 if necessary, then produce the patch with
2649
2650 @example
2651 git format-patch origin
2652 @end example
2653
2654 This will create a patch file for all the locally committed files
2655 which differ from @q{origin/master}.  The patch file can be found
2656 in [path]/Git and will have a name formed from the commit message.
2657
2658 @subsection Resolving merge conflicts
2659
2660 As soon as you have committed a changed file your local
2661 @code{master} branch has diverged from @code{origin/master}, and
2662 will remain diverged until your changes have been committed in
2663 @code{remotes/origin/master} and Fetched back into your
2664 @code{origin/master} branch.  Similarly, if a new commit has been
2665 made to @code{remotes/origin/master} by someone else and Fetched,
2666 your local @code{master} branch is divergent.  You can detect a
2667 divergent branch by clicking on
2668
2669 @example
2670 Repository -> Visualise all branch history
2671 @end example
2672
2673 This opens up a very useful new window called @q{gitk}.  Use this
2674 to browse all the commits made by yourself and others.
2675
2676 If the diagram at top left of the resulting window does not show
2677 your @code{master} tag on the same node as the
2678 @code{remotes/origin/master} tag your branch has diverged from
2679 @code{origin/master}.  This is quite normal if files you have
2680 modified yourself have not yet been Pushed to
2681 @code{remotes/origin/master} and Fetched, or if files modified and
2682 committed by others have been Fetched since you last Merged
2683 @code{origin/master} into your local @code{master} branch.
2684
2685 If a file being merged from @code{origin/master} differs from one
2686 you have modified in a way that cannot be resolved automatically
2687 by git, Merge will report a Conflict which you must resolve by
2688 editing the file to create the version you wish to keep.
2689
2690 This could happen if the person updating
2691 @code{remotes/origin/master} for you has added some changes of his
2692 own before committing your changes to
2693 @code{remotes/origin/master}, or if someone else has changed the
2694 same file since you last fetched the file from
2695 @code{remotes/origin/master}.
2696
2697 Open the file in your editor and look for sections which are
2698 delimited with ...
2699
2700 [to be completed when I next have a merge conflict to be sure I
2701 give the right instructions  -td]
2702
2703
2704 @subsection Other actions
2705
2706 The instructions above describe the simplest way of using git on
2707 Windows.  Other git facilities which may usefully supplement these
2708 include
2709
2710 @itemize
2711 @item Using multiple local branches (Create, Rename, Delete)
2712 @item Resetting branches
2713 @item Cherry-picking commits
2714 @item Pushing commits to @w{remote/origin/master}
2715 @item Using gitk to review history
2716 @end itemize
2717
2718 Once familiarity with using git on Windows has been gained the
2719 standard git manuals can be used to learn about these.
2720
2721
2722 @node Repository directory structure
2723 @section Repository directory structure
2724
2725
2726 @c TODO: integrate the roadmap better
2727 @verbatiminclude ROADMAP
2728
2729
2730 @node Other Git documentation
2731 @section Other Git documentation
2732
2733 @itemize
2734 @item
2735 Official git man pages:
2736 @uref{http://www.kernel.org/pub/software/scm/git/docs/}
2737
2738 @item
2739 More in-depth tutorials: @uref{http://git-scm.com/documentation}
2740
2741 @item
2742 Book about git: @uref{http://progit.org/,Pro Git}
2743
2744 @item
2745 Github help: @uref{http://help.github.com/}
2746 (very highly recommended by Graham)
2747
2748 @end itemize
2749