#!/bin/sh if git diff-index --quiet HEAD --; then git fetch --all # -or- git fetch else echo Working directory not clean. Exiting. exit 1 fi if [ -n "$1" ]; then tag=$(git describe --tags $1) else tag=$(git describe --tags $(git rev-list --tags='v[0-9]*' --max-count=1)) fi ver=$(echo $tag|sed s/^v//) dstag=upstream/${ver}+ds rmfiles=$(awk 'BEGIN{RS=ORS="\n\n";FS=OFS="\n"}/Files-Excluded:/' debian/copyright|sed -n -e '/^Files-Excluded:/,${p}'|sed s/Files-Excluded://|sed /^$/d) if git rev-parse -q --verify "refs/tags/${dstag}" >/dev/null; then echo Upstream tag "${dstag}" exists already. Exiting. exit 1 fi if ! git merge $tag; then git add -u fi # remove all 'Files-Excluded' files listed in debian/copyright, except debian/ folder for i in $rmfiles; do if [ "$i" != "debian" ]; then git rm -rf "$i"; fi; done # restore the debian/ folder from previous commit git checkout HEAD debian/ # since backported patches should be all included in the new release, remove them all here sed -i '/^backport\//d' debian/patches/series git add debian/patches/series git rm debian/patches/backport/*.patch if git diff-index --quiet HEAD --; then git commit --amend -m "Merge upstream tag: $tag" else git commit -m "Merge upstream tag: $tag" fi git rm -qrf debian/ git commit -m "Pristine source of ${ver}+ds" git tag ${dstag} git reset --hard HEAD^ echo echo If you need to remove more files, do it now then run script to update the ds tag: printf \\tdebian/maint-tools/update_ds_tag\\n