# Special use cases

# Handling non-DFSG clean upstream sources

If you have to handle non DFSG clean upstream sources you can use a different branch which you have to create once:

    git branch dfsg_clean upstream

This creates the dfsg_clean branch from the tip of a branch called upstream. Then, when importing a new upstream version, you import the new version on the `upstream-branch` (by default named upstream) as usual and just don't merge to the debian-branch (by default named master):

    gbp import-orig --no-merge /path/to/nondfsg-clean-package_10.4.orig.tar.gz
    git tag 10.4

After the import you can switch to the dfsg_clean branch and get the newly imported changes from the upstream branch:

    git checkout dfsg_clean
    git pull . upstream

Now make this checkout dfsg clean (preverably by a cleanup script), commit your changes and merge to your `debian-branch`:

    cleanup-script.sh
    git commit -a -m "Make source dfsg clean"
    git tag 10.4.dfsg
    git checkout master
    git pull . dfsg_clean

# Importing NMUs

First create a branch that holds the NMUs from the tip of your `debian-branch` (default is master) once:

    git branch nmu master

To import an NMU change into the git repository and use gbp import-dsc:

    git checkout master
    gbp import-dsc --debian-branch=nmu /path/to/package_1.0-1nmu0.dsc

This will import the NMU onto the branched named nmu instead of the default `master`. This method can also be used to import "old" releases into the Git repository when migrating to Git from another VCS.

# Using Pbuilder

Since Pbuilder uses different command line arguments than Debuild and Dpkg-buildpackage we can't simply pass the options on the command line but have to wrap them in the `--git-builder` option instead. git-pbuilder helps you with that:

    git-buildpackage --git-builder="git-pbuilder"  --git-cleaner="fakeroot debian/rules clean"

Note that we also used a different clean command since since pdebuild `clean` means something different than debuild `clean`. We can shorten this further by using `~/.gbp.conf`:

    cat <<EOF > ~/.gbp.conf
    [DEFAULT]
    # tell git-buildpackage howto clean the source tree
    cleaner = fakeroot debian/rules clean
    # this is how we invoke pbuilder, arguments passed to git-buildpackage will be
    # passed to dpkg-buildpackge in the chroot
    builder = /usr/bin/git-pbuilder

git-pbuilder defaults to building a package for the `sid` distribution. If you want to build for another distribution pass this in the `DIST` environment variable. Invoking gbp buildpackage will now invoke pdebuild by default and all additional command line arguments are passed to dpkg-buildpackage. If you want to use debuild again (without modifying `~/.gbp.conf`) you can use:

    git-buildpackage --git-builder=debuild

Furthermore, if you don't want this for all your invocations of gbp buildpackage you can use `.git/gbp.conf` in one of your Git repositories instead of `~/.gbp.conf`.

# Working on random packages

Whenever you need to work on an arbitrary Debian package you can check it right into Git with one command:

    git-import-dsc --download package
    cd package
    git-branch debian

This uses apt-get to download the source package, puts the orig tarball on the `upstream-branch` and the Debian changes on the `debian-branch` (by default master). The second command creates a branch called debian. Now you can easily modify the package, revert changes you made, create other branches for testing, see what changes you made, etc.. When finished just do

    git-commit -a
    git-diff debian --

to get a nice patch that can be submitted to the Debian BTS. You can also fetch the source package from an URL:

    git-import-dsc --download http://mentors.debian.net/debian/pool/main/i/ipsec-tools/ipsec-tools_0.7.3-9.dsc

The import works incrementally, you can import new versions on top of already imported ones for e.g. easy review of changes.