git

Revision 8 as of 2018-06-13 11:13:28

Clear message

The DesktopTeam uses git to manage its packages. Here's how to do some common things. You need git-buildpackage installed for most of this.

Suggested configuration is available in the end. If you are using it, any local changes to the git repor

General concepts

Branches and repo layout

We will use a layout with 3 remote repositories:

$ git remote show
origin          # will point to launchpad (default for pull and push without any argument)
debian          # will point to debian salsa repository, to cherry-pick easily fixes from debian and rebase
upstream        # will point to upstream repository, to cherry-pick easily upstream fixes

Launchpad remote branches

Let's look at the various branches in the origin (launchpad) remote repository:

$ git remote show origin 
* remote origin
[…]
  HEAD branch: ubuntu/master
  Local branches configured for 'git pull':
    pristine-tar  merges with remote pristine-tar
    ubuntu/bionic merges with remote ubuntu/bionic
    ubuntu/master merges with remote ubuntu/master
  Local refs configured for 'git push':
    pristine-tar    pushes to pristine-tar    (up to date)
    ubuntu/bionic   pushes to ubuntu/bionic   (up to date)
    ubuntu/master   pushes to ubuntu/master   (up to date)
    upstream/latest pushes to upstream/latest (up to date)
  • ubuntu/master branch is the content of the latest development release. Work mostly happens here. It's the default branch.

  • ubuntu/bionic branch is the content for the corresponding release, once a particular release it out.

  • pristine-tar is an internal gbp-buildpackage branch, used to reconstruct release tarballs (using upstream/latest). You are not intended to interact with itdon't touch directly, but via gbp-buildpackage tools.

  • upstream/latest branch corresponds to the latest master branch from the upstream repository. It can be used to cherry-pick works. Updating it is manual. It's needed to help reconstructing the release tarballs.

We find back those 4 branches locally:

  • ubuntu/master -> pull and push from origin (launchpad) remote repository, on ubuntu/master branch (origin/ubuntu/master)

  • ubuntu/bionic -> pull and push from origin (launchpad) remote repository, on ubuntu/bionic branch (origin/ubuntu/bionic)

  • pristine-tar -> pull and push from origin (launchpad) remote repository, on pristine-tar branch (origin/pristine-tar)

  • upstream/latest -> pull from upstream remote repository, on the master branch (upstream/master), and push to origin (launchpad) remote repository, on upstream/latest branch (origin/upstream/master).

Debian remote branches

In addition, we'll have at least another branch tracking debian remote repository. Their master branch is named debian/master:

  • debian/master -> pull (no push, unless you are a debian developer) from debian remote repository, on debian/master branch. This will thus be "debian/debian/master". Don't be mislead by the fact that branch names have "/" in them, and so in remote/branch schema, we end up with debian/debian/master for the remote branch name.

Upstream remote branches

We have upstream/master tracking the upstream repo on master branch. We can track any additional branches as needed for cherry-picking fixes.

For instances:

$ git remote show upstream
* remote usptream
[…]
  HEAD branch: master
[…]
    gnome-3-28                                  tracked
[…]
  Local branch configured for 'git pull':
    upstream/latest merges with remote master

Let's checkout locally gnome-3-28 branch and make it the current checkout (-b):

$ git checkout -b upstream/gnome-3-28 upstream/gnome-3-28
Branch 'upstream/gnome-3-28' set up to track remote branch 'gnome-3-28' from 'upstream'.
Switched to a new branch 'upstream/gnome-3-28'

We asked to create a new local branch named upstream/gnome-3.28 (first argument), tracking the remote upstream, on the branch gnome-3-28 (second argument).

Local branches

To sum up all this, for instance ([] are tracked branch):

$ git branch -vv
  debian/master   c02b29966 [debian/debian/master] Revert "Don't recommend libnss-myhostname since it doesn't seem needed any more (LP: #1766575)"
  pristine-tar    e59ab7422 [origin/pristine-tar] pristine-tar data for gnome-control-center_3.28.1.orig.tar.xz
  ubuntu/bionic   59adb2d88 [origin/ubuntu/bionic] Reintegrate 1:3.28.1-0ubuntu1.18.04.1
* ubuntu/master   63337a4cd [origin/ubuntu/master] releasing package gnome-control-center version 1:3.28.1-0ubuntu5
  upstream/latest 0bd90ca34 [upstream/master] region: Show scrollbars if needed

Note that the fact we push upstream/lastest to origin/usptream/latest is the only missing information in that command.

With the 3-28 branch local checkout, we have in addition:

  upstream/gnome-3-28 4f3035eff [remotes/upstream/gnome-3-28] user-accounts: Force symlink creation

Note that to disambiguate local branch and remote + branch name being the same, git prints the remote branch as remotes/upstream/gnome-3-28 instead of upstream/gnome-3-28. Both are equivalents when using a remote argument.


git config branch.upstream/latest.pushremote origin

git config branch.pristine-tar.pushremote origin


Local changes

With the suggested configuration, any non committed changes (file modifications, additions or removal) will halt the build, as they won't be included as a safety reminder.

You can either: * ignore them, appending --git-ignore-new. The resulting package and build won't include those uncommitted changes. (../build-area/<your-package> will match the last commit). * force using the current directory with your local modifications instead of build-area, and include (despite the "ignore-new" option) any local modifications to the package. For this, append --git-ignore-new --git-export-dir=""

Configurations

~/.gitconfig

To easily access to launchpad git repositories with git clone lp:~name-or-team/repo, you should add to your .gitconfig file the following paragraph:

[url "git+ssh://<your_user_name>@git.launchpad.net/"]
        insteadof = lp:

See https://help.launchpad.net/Code/Git for more information on git configuration with launchpad.

~/.gbp.conf

git-buildpackage uses this file for its default configuration; some tweaks are recommended.

[buildpackage]
# use this for exporting first your directory in a ../build-area:
export-dir = ../build-area/
# automatically GPG sign tags with associated keyid
sign-tags = True
keyid = 0xGPGKEYID

See gbp.conf(5) and man of gbp-buildpackage for more options.

Useful tips for gbp buildpackage

Some useful options:

  • Don't purge the build-area directory when building: gbp buildpackage --git-no-purge

  • Build current branch with local uncomitted modifications: gbp buildpackage --git-ignore-new --git-export-dir=""

check out a package

If the Vcs-Git field is correct, you can

ubuntu@gbp-demo:~$ debcheckout --git-track=* glib2.0
declared git repository at https://git.launchpad.net/~ubuntu-desktop/ubuntu/+source/glib2.0
git clone https://git.launchpad.net/~ubuntu-desktop/ubuntu/+source/glib2.0 glib2.0 ...
Cloning into 'glib2.0'...
remote: Counting objects: 133911, done.
remote: Compressing objects: 100% (24298/24298), done.
remote: Total 133911 (delta 109608), reused 133521 (delta 109263)
Receiving objects: 100% (133911/133911), 64.44 MiB | 880.00 KiB/s, done.
Resolving deltas: 100% (109608/109608), done.
Branch 'pristine-tar' set up to track remote branch 'pristine-tar' from 'origin'.
Branch 'upstream/2.56.x' set up to track remote branch 'upstream/2.56.x' from 'origin'.
Branch 'upstream/latest' set up to track remote branch 'upstream/latest' from 'origin'.

Otherwise, you can check out any git-buildpackage repository

ubuntu@gbp-demo:~$ gbp clone https://git.launchpad.net/~ubuntu-desktop/ubuntu/+source/glib2.0
gbp:info: Cloning from 'https://git.launchpad.net/~ubuntu-desktop/ubuntu/+source/glib2.0'

build a source package

ubuntu@gbp-demo:~/glib2.0$ gbp buildpackage -S
dh clean --with gnome,python3 --buildsystem=autoconf
   dh_auto_clean -O--buildsystem=autoconf
   dh_gnome_clean -O--buildsystem=autoconf
   debian/rules override_dh_clean
make[1]: Entering directory '/home/ubuntu/glib2.0'
rm -rf /home/ubuntu/glib2.0/debian/build \
       /home/ubuntu/glib2.0/debian/install \
       /home/ubuntu/glib2.0/debian/tmp-xdg-runtime-dir
dh_clean -Xorg.gtk.test.gschema.xml.orig
make[1]: Leaving directory '/home/ubuntu/glib2.0'
gbp:info: Tarballs 'glib2.0_2.56.1.orig.tar.xz' not found at '../tarballs/'
gbp:info: Creating /home/ubuntu/build-area/glib2.0_2.56.1.orig.tar.xz
gbp:info: Exporting 'HEAD' to '/home/ubuntu/build-area/glib2.0-tmp'
gbp:info: Moving '/home/ubuntu/build-area/glib2.0-tmp' to '/home/ubuntu/build-area/glib2.0-2.56.1'
gbp:info: Performing the build
...

If you used the gbp.conf given above, the source package is in ../build-area. We didn't have the orig.tar.xz to hand before this, but gbp used pristine-tar to reconstruct the same one you get from upstream. Check the sha256sum.

release a package

merge a new upstream version

merge with debian

cherry pick a patch

write a new patch

convert a package to git for the first time

XXX: flesh this out

  • clone debian's repository
  • git remote add gnome <url to gnome git repository>; git fetch gnome

  • git remote add lp <url to lp>

  • find the place we diverged from Debian, and make an ubuntu/master branch at that tag - for example if we're on 3.28.1-2ubuntu9, branch from debian/3.28.1-2; if we're on 3.28.2-0ubuntu1, go back in history until you find a non-0 version.

  • on ubuntu/master, run gbp import-dsc --debian-branch=ubuntu/master --debian-tag='ubuntu/%(version)s' ../path/to/the/current/dsc

  • Fix up debian/control.in - mention the Launchpad URLs in Vcs-* and copy Debian's to XS-Debian-Vcs-*

  • Modify or create gbp.conf containing:

[DEFAULT]
pristine-tar = True
debian-branch=ubuntu/master
upstream-branch=upstream/latest
upstream-vcs-tag = %(version)s
debian-tag = ubuntu/%(version)s

note for a stable release that'll be something like

[DEFAULT]
pristine-tar = True
debian-branch=ubuntu/bionic
upstream-branch=upstream/3.28.x
upstream-vcs-tag = %(version)s
debian-tag = ubuntu/%(version)s
  • Add a changelog entry for the above and commit it
  • Now you can work with the repository
  • When finished, push the ubuntu/ branch and tags, any relevant upstream/ branches and tags and the pristine-tar branch. Visit the repository page on Launchpad, and set the default branch to ubuntu/master.