Abstract

Here are some tentative workflow and naming conventions developed at Sage Days 54, together with some FAQs about using git.

Rationale

Why does this page give instructions using git directly instead of the dev scripts?

Currently, the dev scripts are in a state of flux, and it's easy for a user to get their sage tree into a state where the dev scripts are not working properly, or not working at all. The situation will eventually stabilize, and at that point the scripts will be reliable in addition to being useful. Until then, it's important to know how to work with git directly.

What is a git branch?

In the git model (see Git for computer scientists for a nice description), there is a history graph (that is, a directed acyclic graph), which contains every change to the sage code together with descriptions of these changes. A node in this graph is called a "commit", and in general the history graph only ever grows (gets more nodes/commits). A "branch" is just a movable label to a particular point in the history graph. We think of a branch as pointing to a particular commit, together with all of its ancestors in the history graph.

What is Trac?

Trac is the server that acts as the git repository (it is also refers to the ticket manager). In this document the identifier origin always refers to Trac.

Since this is confusing, let's say it again: Trac refers to the url trac.sagemath.org, which runs two services, namely a git repository (this is our main concern in this document), and a ticket tracker (which is only a secondary concern in this document).

What should I name my branch on Trac?

Trac with single author

If you are working on a branch yourself, then it is best to put your patches on trac in your personal space

u/<myname>/<mystuff>

or

u/<myname>/ticket/<tracnumber>-<mystuff>

Trac with collaboration

If you collaborate on a branch with others or have already a ticket number, then please put your branch on the public space and mark

public/ticket/<tracnumber>-<mystuff>

If the ticket is combinat related mark it (so it can be searched as such) as

public/combinat/<mystuff>
public/combinat/<tracnumber>-<mystuff>

First, it should be noted that the name of a branch on your computer does not have to match the name of the (corresponding) branch on Trac. Git has the ability to keep track of a mapping between local branch names and remote branch names for convenience. However, some people prefer to keep the same name for local and remote branches, to avoid confusion. Now, the question is: what should you name your remote branches on Trac?

This is mainly important because different people have different permission for reading and writing branches on Trac:

Given this, the discussions at Sage Days 54 settled on some suggestions:

These conventions make it easy to:

If a branch is on Trac, who does it belong to?

Suppose Alice creates a branch aardvarks starting from origin/master. Then Bob sees this and creates a further branch bowling starting from the branch aardvarks. Later, Alice decides (whether rightly or wrongly) to rebase the branch aardvarks on a more recent version of origin/master, without consulting Bob. This creates a conflict between the new history of aardvarks and the current history of bowling. Who is now responsible for fixing the conflict? (See RebaseVsMerge for more details about this situation.)

Based on discussions at Sage Days 54, the following statements should not be controversial:

This leaves the following question unanswered, because there is currently no consensus. It may be best to avoid such ambiguities for now when naming branches on Trac:

There is also the following corollary:

First-time setup

There is some scattered documentation on how to install and configure the git version of Sage. For convenience, we compile all of the correct (as of November 7, 2013) steps here.

Sources:

Step 1: make sure git is installed on your computer

This step is different for different people, but is described in the git setup section of the new developer guide. Note that to use git with sage, you must always be somewhere in the sage tree (in $SAGE_ROOT, which may be something like /opt/sage-git on your computer) when running any git ... commands.

Step 2: tell Trac about your ssh key

Follow the excellent directions at the authentication section of the new developer guide (everything starting at the heading "Authentication" and ending before the heading "Reporting bug"). This is necessary if you want to actually push your code changes to the Trac server using git.

TODO:: something about avoiding linebreaks on the Trac page?

Step 3: clone the git repository from Trac

Get a copy of the whole sage tree from the Trac server using git. In the following example, we are working in the /tmp directory, and we choose to put the sage tree in the /tmp/sage-git directory.

mguaypaq@chmmr:/tmp$ git clone [email protected]:sage.git sage-git
Cloning into 'sage-git'...
remote: Counting objects: 205444, done.
remote: Compressing objects: 100% (36317/36317), done.
remote: Total 205444 (delta 137341), reused 205055 (delta 137070)
Receiving objects: 100% (205444/205444), 57.55 MiB | 11.18 MiB/s, done.
Resolving deltas: 100% (137341/137341), done.
mguaypaq@chmmr:/tmp$ cd sage-git
mguaypaq@chmmr:/tmp/sage-git$ ls
build  COPYING.txt  Makefile  README.txt  sage  src  VERSION.txt

Note for experts:: Actually, it is faster for the first time to clone the sage git repository using the git:// protocol instead of the ssh protocol from github.com rather than trac.sagemath.org. This also has the upside that you can do it without setting up Trac authentication (Step 2). However, the downside is that you will have to change your remote url later in your configuration.

Step 4: make sure your git configuration is correct

TODO:: Talk about a sample ~/.gitconfig and a sample $SAGE_ROOT/.git/config.

git remote set-url origin [email protected]:sage.git
git config --global push.default upstream

Step 5: install ccache to speed up future compilations

TODO:: an example

Step 6: build sage and/or the sage documentation

TODO:: Talk about make

git config --global push.default upstream

Talk about make? Certainly mention that git should be run inside $SAGE_ROOT.

Basic git commands

Latest version of Sage itself

Getting the latest version of Sage

$ git checkout master
$ git pull --ff-only

Latest status of everything on trac

Getting the latest information about all the branches published on trac

$ git remote update origin

Pushing and pulling branches to and from trac

If you have a local branch on your personal computer that you would like to push to trac, there are three options:

$ git push --set-upstream origin <mybranch>:u/<mytracname>/<mybranch>
$ git push --set-upstream origin <mybranch>:public/combinat/<mybranch>
$ git push --set-upstream origin <mybranch>:public/ticket/<ticketnumber>-<mybranch>

The third option is for tickets unrelated to combinat. You would use the first one for code you personally work on. The second option is for collaborative code with other combinat people. If you already have a ticket number, use

$ git push --set-upstream origin <mybranch>:public/combinat/<ticketnumber>-<mybranch>

The first time you pull a branch from trac onto your local computer:

$ git remote update origin
$ git checkout -b 10305-partition origin/public/ticket/10305-partition

After the initial pull or push, this is the workflow to push your local changes to trac:

$ git checkout <mybranch>
$ git pull --ff-only
$ git push

The option --ff-only for the pull command makes sure that if there are big merge conflicts with the new changes on trac, you can handle them manually without messing up your entire branch and your local changes. If there are big changes, you can use these commands:

$ git checkout <mybranch>
$ git pull --ff-only
*git complains*
$ git fetch
$ git merge FETCH_HEAD
...
*resolve any merge conflicts*
*or give up and say: "git merge --abort"*
...
$ git status
...
*some output???*
...
$ git commit -a -m '<some message>'
$ git push

the git fetch command downloads a list of latest commits for the branch you are on, it does not change the state of your local branch. The command git merge FETCH_HEAD updates your branch to the latest version of the branch on Trac.

Deleting branches

If you want to delete a local branch:

$ git checkout <somethingelse>
$ git branch -d <mybranch>

This might complain if you are trying to delete a branch that has not been merged yet. If nonetheless you would like to delete it, try a hard delete:

$ git branch -D <mybranch>

Even in a hard delete this can be undone in the next 30 days (before the commits get garbage collected).

To delete a remote branch:

$ git push origin :u/aschilling/<something>

The syntax here may look confusing, so here is a little explanation: it is actually a special case of the syntax

$ git push origin <localbranch>:<remotebranch>

which updates <remotebranch> on the remote server to be the same as <localbranch>. To delete a branch, we make <localbranch> be completely blank and push it onto <remotebranch>.

Resetting unwanted changes

If you accidentally edited master and want to undo your change

$ git branch -m master <mybranch>
$ git branch master origin/master

If you do not care about the changes you can do a hard reset

$ git reset --hard origin/master

Branch naming conventions

On Trac

See the section about naming conventions on trac.

Local machine

On your local machine you can call your branches however you like. However, it might be useful to use the same names that you use on trac.

<mystuff>

Naming and searching

The branch name should be descriptive. If you have a ticket number (say 10305) that should be the first part of the name. The rest should describe what is in the branch, so people can easily search it

public/combinat/10305-partition-tableaux

Consistently using these naming conventions among all (sage-combinat) developers will make it easier to search for stuff. For example, trying to find all branches related to combinatorics can be found as follows

$ git ls-remote origin '*combinat*'
5feebdbfa73f64dafe28a5e4fe0144ab36083ab0        refs/heads/public/combinat/15361-branching-rules
7f974aeb3446206c029ac047c31938d55d86e651        refs/heads/u/aschilling/combinat/kschur

If you want to see what a specific author did on trac within the last day, you do

$ git remote update origin
$ git log --all --author="Bump" --since=1.day
commit 5feebdbfa73f64dafe28a5e4fe0144ab36083ab0
Author: Daniel Bump <[email protected]>
Date:   Wed Nov 6 09:51:08 2013 -0800

    get_branching_rule for F4=>B3 and G2=>A1 should return vectors of the correct length

Checking how the ticket branches of author mguaypaq differ from main sage (or origin/master) try

$ git log --remotes='origin/u/mguaypaq/ticket/*' ^origin/master --oneline
1c7458a #15300: Implement Weyl and Clifford algebras.
fb33147 Merge branch 'master' into ticket/10305
405178b Remove extra chunk from farahat_higman.py and fix related formatting issues.
25ff1fd Split off SymmetricGroupAlgebraCenter to its own file.
9b72574 Add rings for the center of the symmetric group algebras.

Tornado branches

Sometimes you might want to share certain features that are not yet in main-sage with a collaborator who is not a developer. Suppose these features are in two different branches on trac. Then you can create a tornado branch by merging the two. Note, that you want to make sure that other developers will not base other code on those, so please label them as tornado branches!

Go to one of the two branches you would like to merge

$ git checkout kschur
$ git branch
  combinat/kschur
  master
* public/combinat/15361-branching-rules
  ticket/15300

From there create your new tornado branch

$ git checkout -b tornado-kschur-branching
$ git branch
  combinat/kschur
  master
  public/combinat/15361-branching-rules
  ticket/15300
* tornado-kschur-branching

Now merge in the other branch

$ git merge combinat/kschur
$ git log
commit 510520a52e44bace997784370cacbfdd75ae4473
Merge: 5feebdb 7f974ae
Author: Anne Schilling <[email protected]>
Date:   Wed Nov 6 21:59:20 2013 -0800

    Merge branch 'combinat/kschur' into tornado-kschur-branching

Finally push to trac

$ git push --set-upstream origin tornado-kschur-branching:u/aschilling/tornado-kschur-branching
Counting objects: 44, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 523 bytes | 0 bytes/s, done.
Total 5 (delta 4), reused 0 (delta 0)
To [email protected]:sage.git
 * [new branch]      tornado-kschur-branching -> u/aschilling/tornado-kschur-branching
Branch tornado-kschur-branching set up to track remote branch u/aschilling/tornado-kschur-branching from origin.

Example workflow

Moving a ticket from patches to git

Import patch from a local file

Make sure that your file has the header data by an hg export. If your patch is on your local computer at /pathname/patchname.patch then

$ sage --dev import-patch --local-file /pathname/patchname.patch

If your patch is on trac or on the internet at a url

$ sage --dev import-patch --url http://trac.sagemath.org/raw-attachment/ticket/12345/trac_12345-patchname.patch

If you find that the author field is set to unknown user then it could be that the patch needs to be exported first.

Moving a patch from the combinat queue to git

All patches in the queue will soon be merged from the sage-combinat queue to git branches on trac. Authors who want to do this themselves are encouraged to do so. The script will by default put the branches to public/combinat/branchname and might loose author information if the patch does not have the appropriate meta information.

Here is a sample workflow on how to transform your patch to git:

Export hg patch

First make sure that your patch has the correct meta data by exporting it.

Create new local branch

Make a new branch on your local machine:

$ git checkout -b combinat/kschur master
$ git branch
* combinat/kschur
  master
  ticket/15300

Import patch from queue

Next import the patch from the queue

$ sage --dev import-patch --local-file /Applications/sage-5.13.beta2/devel/sage-combinat/.hg/patches/kschur-as.patch

Create branch on trac

Now we create a branch on trac

$ git push --set-upstream origin combinat/kschur:u/aschilling/combinat/kschur
Counting objects: 47, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 1.27 KiB | 0 bytes/s, done.
Total 7 (delta 6), reused 0 (delta 0)
To [email protected]:sage.git
 * [new branch]      combinat/kschur -> u/aschilling/combinat/kschur
Branch combinat/kschur set up to track remote branch u/aschilling/combinat/kschur from origin.

Mark patch in series file

Mark the patch in the sage-combinat series file as moved to git by changing

kschur-as.patch

to

kschur-as.patch # git:u/aschilling/combinat/kschur

References