gitpkg-0.31/0002755000000000000000000000000014505757621007626 5ustar gitpkg-0.31/debian/0002755000000000000000000000000014505757621011050 5ustar gitpkg-0.31/debian/NEWS0000644000000000000000000000111114505757621011537 0ustar gitpkg (0.18) unstable; urgency=low gitpkg no longer calls the package's clean target by default during the export process. Since that gives a shell to whatever you are exporting, this is something which should be explicitly enabled, for each trusted repo that needs it, by the local admin. To do that, you can run: $ git config gitpkg.prebuild-target clean Which will restore the previous behaviour. If you've already set that option explicitly, then your current configuration will be preserved. -- Ron Lee Sun, 09 Jan 2011 02:32:59 +1030 gitpkg-0.31/debian/changelog0000644000000000000000000004557714505757621012742 0ustar gitpkg (0.31) unstable; urgency=medium * Support exporting submodules as part of the superproject package. Closes: #734360 It's been a while since we had any follow up or feedback on the discussion in that bug, so it's not clear that submodules remain a wide use case, but I've now got one upstream repo really using them (though it probably would be better organised differently too) so I at least have something concrete to base the gitpkg behaviour on rather than just a strawman speculation on my part about how a repo with submodules might be arranged and operated. The originally proposed patch had quite a few limitations, it only worked on exports of the debian-treeish, not for a real orig-branch, and it used git submodule foreach, which only works on the current checked out state of the working dir and so breaks one of gitpkg's fundamental modes of operation where any revision can be exported at any time, regardless of the current state of the repo working dir. This implementation is quite a bit more involved, but it should handle most or all cases, including where submodules have been moved or later deleted, provided the local repo has been fully initialised and all submodules which may need to be exported have been cloned into the superproject and its full history is intact. It will not simply export submodules by default, though it if finds them present in a repo that has not been configured to export (or ignore) them then it will prompt asking what immediate action should be taken and suggest configuration to avoid be prompted again subsequently. This way existing repos that have been silently ignoring submodules thus far will not silently do something surprisingly different with this gitpkg release. * Sanity check and/or warn if gitpkg is invoked from a submodule dir, since that probably won't do what a lot of people might naively assume, but it might still be something that some pathological repo actually has a use case for. We probably shouldn't encourage it though. * Bump to debhelper compat 12. That give us no-patch builds back to buster which is still a supported release. We don't actually need anything from newer dh in this package, so this is just to stay ahead of the arbitrary 'deprecated version' warnings rather than to actually fix anything. -- Ron Lee Sat, 30 Sep 2023 18:12:57 +0930 gitpkg (0.30) unstable; urgency=medium * New utility functions in repo-config-helper which simplify configuration option handling in hook scripts. * Provide finer grained overrides for usefully configurable options in the cowpoke and dpkg-buildpackage exit hooks, so that overriding things like the target to build for, or where to upload, don't necessarily override all of the other configured defaults. * Support creating "source only" changes files for upload, even when doing a full binary package build. -- Ron Lee Tue, 10 Aug 2021 01:00:34 +0930 gitpkg (0.29+nmu1) unstable; urgency=medium * Non maintainer upload by the Reproducible Builds team. * No source change upload to rebuild on buildd with .buildinfo files. -- Holger Levsen Sun, 03 Jan 2021 17:49:28 +0100 gitpkg (0.29) unstable; urgency=medium * Fix git-debcherry for a change in the behaviour of how git rev-parse handles tag refs. Thanks to James McCoy for spotting it and the initial patch to fix it. Closes: #887963 * Support passing arbitrary options to the orig compressor, and default to passing -n (--no-name) to gzip, so that it doesn't add a timestamp, making the compressed orig tarball more reproducible. Thanks to Antoine Beaupré for noticing the current default behaviour, the idea of passing this option to gzip to improve it, and testing that it worked. The actual fix here is a bit different, because -n (meaning this) is specific to gzip, so now we have support for setting per-compressor options too. Closes: #820842 -- Ron Lee Sun, 18 Mar 2018 17:29:35 +1030 gitpkg (0.28) unstable; urgency=medium * pristine-pre-export-hook: copy with data from pre-1.22 versions of pristine-tar that used commits rather than trees. Closes: #817081. Thanks to David Bremner for catching it and patching it. -- Ron Lee Wed, 16 Mar 2016 23:39:42 +1030 gitpkg (0.27) unstable; urgency=medium * git-debcherry: Strip trailing slash from patch dir. Closes: #784130 * Preserve git notes in git-debcherry. Closes: #784159 * Don't include a signature in patch series output. Closes: #772626 Thanks to Niko Tyni and Tino Mettler for reports and patches, and David Bremner for reviewing the debcherry changes. -- Ron Lee Tue, 11 Aug 2015 23:45:47 +0930 gitpkg (0.26) unstable; urgency=low * Avoid ambiguity in the pristine-tar hook when branch and directory names are the same, which isn't entirely unlikely if people have a branch named 'debian'. Thanks to David Bremner for further testing and a patch. * Low urgency because we're in the pre-freeze 'be cautious' slowdown now. -- Ron Lee Thu, 09 Oct 2014 04:44:26 +1030 gitpkg (0.25) unstable; urgency=medium * Introduce a new command 'git-debcherry' and an export hook to use it 'debcherry-deb-export-hook'. This exports a quilt patch series for the differences between 'ref' and 'origref' by analysing the changes in the repository to files outside the debian directory. It allows a much more natural workflow of pushing proper patches to git that upstream can cherry-pick, and automatically removes them from your quilt patch series when they do. Many, many thanks to David Bremner for the many, many hours he spent patiently writing, and testing, and rewriting, and refining this until I stopped finding things to whine about and saying "wait, but what if we ...". It's time to see if others can find a way to surprise us with it now. Closes: #662726 -- Ron Lee Sun, 05 Oct 2014 21:57:17 +1030 gitpkg (0.24) unstable; urgency=medium * Actually support orig.tar.xz in git-debimport, by fixing the copy/paste fail that returned .bz2 as the extension for those. * Update sanitise_git_ref() for the git 2.1.0 rules. * Add a command line parser. Mostly this is for the benefit of hook scripts which can reasonably be passed per-invocation options to control their behaviour that don't actually change the source package which is exported for a particular treeish (such as passing --dist or --arch options to the cowpoke exit hook). For gitpkg itself, the --deb-dir and --exit-hook options are similarly 'harmless' so overriding the normal gitconfig can be useful to do sometimes. The cowpoke exit hook can now have its options overridden with --cowpoke, and the dpkg-buildpackage exit hook can have its options overridden by passing --dpkg-bp. People who create their own hooks can also transparently add their own options for them if needed. Closes: #674246 * Make the --version and --help options work even when not running inside a git repository. * Report all errors to stderr. Previously we leaked some of them to stdout. * Add a --keep-unpacked-source option (and corresponding gitconfig). Previously we always kept the unpacked source directory unless people removed it themselves in their own exit hook, but that wasn't everybody's ideal behaviour. Now that it's easy to request this on invocation, let's keep the export directory clean by default. -- Ron Lee Mon, 29 Sep 2014 01:51:49 +0930 gitpkg (0.23) unstable; urgency=low * Depend on git with an epoch, since the versions of gnuit before the name change otherwise satisfy this dep, as do earlier versions of git which already have an epoch too. Thanks to Jonathan Nieder for catching this. Closes: #676851 -- Ron Lee Sun, 10 Jun 2012 18:42:52 +0930 gitpkg (0.22) unstable; urgency=low * Add bash completion for gitpkg. Closes: #675522 Many thanks to Stig Sandbeck Mathisen for contributing this. -- Ron Lee Sun, 03 Jun 2012 22:06:43 +0930 gitpkg (0.21) unstable; urgency=low * Remove the quilt hook git-patches file if no patches were exported. This avoids the lintian check misfiring if people keep a wildcard revision range in it but there are no patches to export for a particular release. Closes: #633891 * Don't try to export the --help revision of a package if people pass that to gitpkg without reading its manual page first. This is a community- service exception to the usual policy of having no command line options (and so no way to screw up an export by passing the wrong ones). Closes: #633869 -- Ron Lee Sun, 17 Jul 2011 01:52:35 +0930 gitpkg (0.20) unstable; urgency=low * Check if PATCHES is empty in quilt-patches-deb-export-hook, to avoid adding an empty line to the series file, which will in turn trigger the lintian warning about patches not being exported. -- Ron Lee Wed, 13 Jul 2011 22:16:06 +0930 gitpkg (0.19) unstable; urgency=low * Move sanitise_git_ref to repo-config-helper. Use it in quilt-patches-deb-export-hook to export valid git refnames, based on {DEB,UPSTREAM}_VERSION, in {DEB,UPSTREAM}_REF. Closes: #620969 -- Ron Lee Mon, 18 Apr 2011 00:43:25 +0930 gitpkg (0.18) unstable; urgency=low * Be nice to emacs users of the quilt-patches hook. * We don't call the package clean target by default anymore. There's a bunch of good reasons not to, and not many packages that really need this. If you want the old behaviour back, you can enable it with: $ git config gitpkg.prebuild-target clean -- Ron Lee Sun, 09 Jan 2011 02:32:59 +1030 gitpkg (0.17) unstable; urgency=low * More cool things from David Bremner, quilt-patches-deb-export-hook. Closes: #607279 -- Ron Lee Sun, 19 Dec 2010 05:56:59 +1030 gitpkg (0.16) unstable; urgency=low * Catch the case of two treeishes passed, but a native changelog version. Mild hilarity will ensue if we don't, for people who accidentally use a native package version when they have debian patches being applied. Which is probably as it should be, but we can be friendlier than that. -- Ron Lee Tue, 16 Nov 2010 20:41:43 +1030 gitpkg (0.15) unstable; urgency=low * Updates to git-debimport. * The git 1.7.0-rc1 release breaks status -a, replacing it with a --dry-run option to commit. There is no option compatible with git from both before and after that so go with the flow and version the git Depends accordingly. Closes: #587178 * Switch the git Depends from git-core too while we are at that. * Tweak the package sorting a bit further. Prune off all non-version text when feeding the comparator, since the initial find may include packages in different subdirs which can otherwise distort the sort. Protect the arithmetic operation in the sort from tripping the `set -e` trap if the sort does go all the way up to the first entry in the list. Thanks to Yann Dirson for noticing this and sending patches. Closes: #587175 * Add support for format 3.0 packages. Thanks to Craig Small for a proof patch that showed how little actually needed to be changed to provide initial support for debian.tar.gz 'diffs'. Closes: #565503 * Add support for xz and bz2 compressed packages too. * Fix for debsnap gratuitously breaking its argument passing convention, but this now works again with snapshot.debian.org if you have debsnap from devscripts 2.10.63 or later (modulo some already known bugs in debsnap itself with handling certain snapshot data). Closes: #521764 * Handle tarballs that don't have their source under a single subdir. dpkg-source special cases that, so do something similar here too rather than just blindly stripping off the top level when unpacking. Closes: #587181 -- Ron Lee Sun, 27 Jun 2010 09:51:24 +0930 gitpkg (0.14) unstable; urgency=low * Update sanitise_git_ref for changes to git's rules about what is legal. * Hook script tweaks: - Save a build log in the dpkg-buildpackage exit hook. - Ensure the destination directory exists before calling pristine-tar. -- Ron Lee Fri, 01 Jan 2010 07:05:17 +1030 gitpkg (0.13) unstable; urgency=low * Lucky for some. * Don't hardcode .gitignore removal here, people should use gitattributes(5) for that sort of thing instead. * Move all configuration options to use git-config(1). There is no sense in reinventing a(nother) config file hierarchy and format ourselves. Existing config should continue working for now, and gitpkg itself will hint to you about how to migrate. * Pass the contents of gitpkg.dpkg-source options verbatim to dpkg-source. Closes: #554519 * Support being invoked from a subdir of the repo to export. * Pander to "format 3.0" which can't build orig tarballs itself anymore and gags on the dpkg-source options that specify how the source is presented. * Drop the .orig suffix from paths in the orig tarballs. * Make the hardcoded rule to call the debian/rules clean target prior to building the package more flexible. Not all packages need this, and some may have some other special rule they'd rather call instead. * Rehash the user hook handling entirely (though any existing hooks should still work for now too). We now provide support for multiple distinct hooks that are run at key times and places during the build process, and a more complete set of environment variables are guaranteed to be available to them. Closes: #544210 * Add /usr/share/gitpkg/hooks initially populated with simple off the shelf support for cowpoke, dpkg-buildpackage, and pristine-tar. * Now with 30% less typing! That's right, you only need to pass the second treeish if you actually do need gitpkg to export a new orig tarball. This isn't really a "new feature", but it's now safe to formalise that it isn't just an accident. The second tag was always ignored previously if a suitable orig tarball already existed, but now we give you more choice over what should actually happen in that case, and make it explicit that you don't need to pass the second treeish if you already have an orig. -- Ron Lee Sun, 15 Nov 2009 06:04:26 +1030 gitpkg (0.12) unstable; urgency=low * Ack moving this to the new 'vcs' section of the archive. * Don't leak failure from a subshell that didn't really fail. Special exceptions can't cross that line. Closes: #550624. -- Ron Lee Mon, 12 Oct 2009 23:17:28 +1030 gitpkg (0.11) unstable; urgency=low * Note in git-debimport(1) that the snapshot.debian.net archive is broken and so --fetch cannot currently work with it. * Add missing dependencies on git-core and dpkg-dev. Apparently these things aren't already essential :) Closes: #536221 Thanks! -- Ron Lee Thu, 09 Jul 2009 00:59:25 +0930 gitpkg (0.10) unstable; urgency=low * Fix the test for debsnap to not trap on set -e if not present. -- Ron Lee Sat, 10 Jan 2009 23:58:16 +1030 gitpkg (0.9) unstable; urgency=low * Add a --fetch option to git-debimport to retrieve packages from snapshot.debian.net rather than requiring an existing local archive to import. Many thanks to David Paleino for his work on making that a very useful reality. * Enable importing Debian 'native' packages too, this is much more useful now that we have --fetch. * Add a --late-merge option, which implements the previous behaviour wrt to merging the upstream branch after an import and default to merging each new upstream incrementally now. This gives a much better history if it succeeds without conflicts, and lets us still fall back if not. Closes: #468218 * Make git-debimport generally more robust. Being able to kickstart a new repo quickly and easily from package snapshots means this might be with us and still useful for considerably longer than was initially planned. -- Ron Lee Sat, 10 Jan 2009 09:32:41 +1030 gitpkg (0.8) unstable; urgency=low * Reuse an existing orig.tar.gz for single branch exports too. Generally it wouldn't be a great idea to package most things with a Debian version in this way, but it should Work Right if you do and shouldn't trash an existing orig.tar.gz if you use the single tag invocation by mistake. -- Ron Lee Mon, 01 Dec 2008 08:39:45 +1030 gitpkg (0.7) unstable; urgency=low * Add support for an absolute path to the packages for git-debimport. Thanks to Anuradha Weeraman for the poke to fix this and an initial partial patch. Closes: #482444 * Add Vcs- headers to control. -- Ron Lee Sun, 08 Jun 2008 03:06:19 +0930 gitpkg (0.6) unstable; urgency=low * Strip '.diff.gz' from package names when sorting them -- Ron Lee Wed, 19 Mar 2008 04:51:37 +1030 gitpkg (0.5) unstable; urgency=low * Make git-debimport order things the way dpkg would, other people are starting to notice that too now. Sorry if you got burned by that at some point -- thank Cyril for poking me to fix it. Closes: #458298 * Fix a typo in the reported output of what gitpkg is doing. -- Ron Lee Mon, 31 Dec 2007 02:21:05 +1030 gitpkg (0.4) unstable; urgency=low * Filter out epochs from the DEB_VERSION. Thanks to phil and dato. * Add a section on workflow to gitpkg.1 as one simple example of a way things can be done. Tips, improvements, and alternative to that are welcome. -- Ron Lee Wed, 26 Dec 2007 00:25:23 +1030 gitpkg (0.3) unstable; urgency=low * Sanitise git-debimport tag names extracted from package version strings. Some things that are valid version strings are not valid tag refnames. -- Ron Lee Thu, 29 Nov 2007 21:15:57 +1030 gitpkg (0.2) unstable; urgency=low * Now with extra configurable ability * * Read some configurable things from external config files. * When exporting source, place each project under its own unversioned tree in the output directory to avoid clutter when multiple projects share the same output location. * Execute a per-project hook script if it exists in the checked out source, just before dpkg-source is called. * Include git-debimport patch from Romain Francoise to sanitise the top level directory name from the orig.tar.gz and extract author and date information from the orig.tar.gz and debian/changelog. Thanks! -- Ron Lee Mon, 26 Nov 2007 04:03:38 +1030 gitpkg (0.1) unstable; urgency=low * Initial Release. Closes: #443392 -- Ron Lee Fri, 21 Sep 2007 10:32:55 +0930 gitpkg-0.31/debian/control0000644000000000000000000000273014505757621012453 0ustar Source: gitpkg Section: vcs Priority: optional Maintainer: Ron Lee Build-Depends: debhelper-compat (= 12) Standards-Version: 4.6.2.0 Vcs-Git: https://salsa.debian.org/ron/gitpkg.git Vcs-Browser: https://salsa.debian.org/ron/gitpkg Package: gitpkg Architecture: all Depends: git (>= 1:1.7.0), dpkg-dev Suggests: devscripts Description: tools for maintaining Debian packages with git This package provides tools and automation to assist with maintaining Debian packages in git. . gitpkg - creates a source package from specified repository versions. git-debimport - creates a git repository from a set of existing packages. . No particular repository layout is required for gitpkg to export source from it, existing repositories should require no modification. If there is a valid Debian source tree in there then gitpkg can export a package from any revision of it for you. In the Grand Old Manner these tools are intended to simplify specific parts of your existing packaging process and integrate smoothly with it, not to replace that with its own singular constraints on how you may work. Since not every packaging style suits every package, gitpkg aims to be able to work equally well with all of them by sticking to just its part of the job and staying out of your way entirely until that job needs to be done. Hook points are provided for performing additional package and user specific operations as you may desire or require at export time. gitpkg-0.31/debian/copyright0000644000000000000000000000173414505757621013006 0ustar This package was created from whole cloth by Ron on Fri, 31 Aug 2007 06:53:06 +0930. Copyright (C) 2007 - 2023, Ron Lee This package is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this package; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA On Debian systems, the complete text of the GNU General Public License can be found in `/usr/share/common-licenses/GPL'. gitpkg-0.31/debian/rules0000755000000000000000000000152514505757621012131 0ustar #!/usr/bin/make -f export DH_OPTIONS clean: dh_testdir dh_testroot dh_clean build: build-arch: build-indep: install: BASH_COMPLETIONDIR = usr/share/bash-completion/completions install: dh_testdir dh_testroot dh_prep -i dh_install gitpkg git-debimport git-debcherry usr/bin dh_install hooks usr/share/gitpkg dh_installman gitpkg.1 git-debimport.1 git-debcherry.1 dh_installexamples examples/README.debcherry-export dh_installdirs $(BASH_COMPLETIONDIR) cp gitpkg.bash_completion debian/gitpkg/$(BASH_COMPLETIONDIR)/gitpkg binary: binary-indep binary-arch: binary-indep: DH_OPTIONS = -i binary-indep: install dh_testdir dh_testroot dh_installchangelogs dh_installdocs dh_compress dh_fixperms dh_installdeb dh_gencontrol dh_md5sums dh_builddeb .PHONY: clean build build-arch build-indep install binary binary-arch binary-indep gitpkg-0.31/examples/0002755000000000000000000000000014505757621011444 5ustar gitpkg-0.31/examples/README.debcherry-export0000644000000000000000000000263714505757621015617 0ustar [This file is a template for some explanatory text that you might wish to include somewhere in your git repository if you use the debcherry export hook to create a quilt patch series. It doesn't really need to be a part of the exported package, since this is only relevant to people exporting source directly from git, so it can be export-ignore'd in .gitattributes if you use those.] If you are reading this from a Debian source package, you can stop now; this package should build normally after extracting with dpkg-source -x. The rest of this file gives some hints about generating source packages from the packaging git repository. This repository has patches to upstream source included in the packaging branch. In order to generate a source package, you have several choices: To generate an old-style single patch package, you can use dpkg-source or e.g. gitpkg without any special preparation (with the possible exception of adding "single-debian-patch" to debian/source/local-options). In order to have patches exported individually at source package creation time, you can enable git-debcherry. After installing gitpkg-0.25 or later, see /usr/share/gitpkg/hooks/debcherry-deb-export-hook and its associated documentation in the gitpkg(1) and git-debcherry(1) man pages. [You may wish to include more precise details of what things are on what branches and what configuration options to add for your repository too.] gitpkg-0.31/git-debcherry0000755000000000000000000002055114505757621012305 0ustar #!/bin/bash # git debcherry upstream [head] function _time() { if [ "$debug" = 'yes' ]; then echo "# time=" $(date "+%s.%N") " line=" $1 >&2 fi } function usage() { printf "usage: $0 [options] upstream [head]\n" printf "\t -d | --debug\t\tprint debugging/profiling info\n" printf "\t -s | --stat\t\toutput patch statistics to stdout\n" printf "\t (-o | --output-directory) \toutput patches to \n" } function patch_id() { if [ -z "$(git diff-tree $1)" ]; then echo "empty" else local ident=$(git show $1 | git patch-id) ident=${ident% *} echo $ident fi } function debug (){ if [ "$debug" = 'yes' ]; then printf "$@" >&2 fi } function _cleanup (){ if [ "$debug" = 'no' ]; then rm -rf "$tmpdir" fi } function _checkout (){ local ref=$1 git checkout -f $ref >$log 2>&1 || _die "checkout failed" } function test_apply (){ local hash=$1 local ref=$2 local want_changes=$3 local ret=0; debug "test_apply $hash $ref $want_changes\n" old_head=$(git rev-parse HEAD) _checkout $ref if ! git cherry-pick --no-commit $hash 1>/dev/null 2>&1 ; then debug "cherry-pick failed in test_apply\n" ret=1 fi git diff --cached --quiet local has_changes=$? if [ "$has_changes" != "$want_changes" ]; then ret=1 fi debug "test_apply %d %d %d\n" $has_changes $want_changes $ret # wipe out any changes git reset --hard HEAD >$log 2>&1 || _die "reset failed" _checkout $old_head return $ret } # make a temporary branch. # usage tmpbranch prefix treeish function tmpbranch() { local git_dir=${GIT_DIR-$(pwd)/$(git rev-parse --git-dir)} local filtered=$(mktemp $git_dir/refs/heads/$1_XXXXXXXXXX) # git update-ref is too fussy here. echo $(git rev-parse $2) > $filtered filtered=${filtered##$git_dir/} echo $filtered } function _die() { echo $1 >&2 [ -s $log ] && cat $log exit 1 } tmpdir=$(mktemp --tmpdir -d git-debcherry.XXXXXX) log=$tmpdir/log touch $log stat_only="no" patch_dir="" debug="no" while : ; do case $1 in -h | --help) usage exit 0 ;; -d | --debug) debug="yes" shift ;; -s | --stat) stat_only="yes" shift ;; -o | --output-directory) patch_dir=${2%/} case $patch_dir in /*) ;; *) patch_dir=$(pwd)/$patch_dir esac shift; shift; ;; --) shift break ;; -*) echo "Unknown option $1" >&2 usage exit 1 ;; *) break ;; esac done if [ $# -lt 1 ]; then usage exit 1 fi _time $LINENO upstream=$1 if ! upstream_sha1=$(git rev-parse "$upstream"^{} 2>$log); then _die "bad or missing ref: $upstream" fi head=${2-$(git symbolic-ref HEAD)} head=${head##refs/heads/} if ! head_sha1=$(git rev-parse "$head"^{} 2>$log); then _die "bad or missing ref: $head" fi if [ "$stat_only" = "no" -a -n "$patch_dir" -a -e "$patch_dir" ]; then _die "$patch_dir exists, not overwriting" fi declare -A unmerged orig_git_dir=${GIT_DIR-$(pwd)/$(git rev-parse --git-dir)} git clone "$orig_git_dir" "$tmpdir"/clone 1>$log || _die "clone failed" export GIT_WORK_TREE=$tmpdir/clone export GIT_DIR=$tmpdir/clone/.git # note that origin here is $orig_git_dir, so the following does # not do any network access if git fetch origin refs/notes/commits:refs/notes/commits >/dev/null 2>&1; then debug "git notes found in the repository\n" NOTES=true else debug "no git notes found in the repository\n" NOTES=false fi tmp_upstream=$(tmpbranch upstream $upstream_sha1) tmp_head=$(tmpbranch head $head_sha1) _checkout $tmp_head trap '_cleanup' EXIT # Remove any traces of .pc (from quilt) and ./debian on temporary # branches. This avoids conflicts when dpkg-source tries to apply # quilt patches. --prune-empty means we are only dealing with commits # that do somehow touch upstream. _time $LINENO { # git-filter-branch doesn't really understand GIT_WORK_TREE # git_commit_non_empty_tree provided by git-filter-branch cd $GIT_WORK_TREE if ! git filter-branch -f --index-filter \ 'git rm --ignore-unmatch --cached -r .pc debian' \ --commit-filter '\ NEW=$(git_commit_non_empty_tree "$@"); \ if $NOTES && [ -n "$NEW" ] && \ git notes show "$GIT_COMMIT" >/dev/null 2>&1 && \ ! git notes show "$NEW" >/dev/null 2>&1; then \ git notes copy "$GIT_COMMIT" "$NEW"; \ fi; echo "$NEW"' \ "$tmp_upstream".."$tmp_head" 1>$log 2>&1 ; then _die "filtering failed" fi } _time $LINENO # for every commit reachable from head, but not from # upstream compute its patch-id (essentially sha1 of diff) # and save a map back to the commit. while read -r hash ; do ident=$(patch_id $hash) unmerged[$ident]=$hash done < <(git rev-list --no-merges $tmp_upstream..$tmp_head ) _time $LINENO # now delete any found upstream; note that this only gets exact # matches, so partial application is not caught here while read -r ident commit ; do unset unmerged[$ident] done < <(git log --patch --no-merges $tmp_upstream| git patch-id) _time $LINENO printf 'debcherry fixup patch\n\n' >> $tmpdir/message debug "Starting test reverts at %s\n" $(git rev-parse HEAD) initial_upstream=$(git rev-parse $tmp_upstream) while read -r hash; do ident=$(patch_id $hash) if [ -n "${unmerged[$ident]}" ]; then if [ -z "$(git format-patch --no-binary --stdout -1 $hash | lsdiff)" ]; then shorthash=$(git rev-parse --short $hash) message=$(git log --pretty=format:"%s" -1 $hash) printf "skipping commit $shorthash <$ident>; empty or binary only.\n $message\n\n" >&2 continue fi # the patch should cherry pick against head, but produce no # changes if ! test_apply $hash HEAD 0 ; then git --no-pager log --oneline -1 $hash >> $tmpdir/message printf "\t - extra changes or conflicts\n" >> $tmpdir/message continue fi # the patch should apply to upstream and produce some changes. # XXX: note that this is a bit heuristic (i.e. wrong). It should # really check against something like upstream with all of the # patches so far applied. if ! test_apply $hash $initial_upstream 1 ; then git --no-pager log --oneline -1 $hash >> $tmpdir/message printf "\t - no changes against upstream or conflicts\n" >> $tmpdir/message continue fi if git revert --no-edit $hash 1>/dev/null 2>&1; then echo "$hash" >> $tmpdir/patch-list else git revert --abort git --no-pager log --oneline -1 $hash >> $tmpdir/message printf "\t - conflict" >> $tmpdir/message fi fi done < <(git rev-list --no-merges --topo-order $tmp_upstream..$tmp_head) # this is where we want to build our patch series SAVED_HEAD=$(git rev-parse HEAD) _checkout $(git rev-parse "$tmp_upstream") # group file deletions DELETED_FILES=$(git diff --diff-filter=D --name-only $tmp_upstream $tmp_head); if [ -n "$DELETED_FILES" ]; then git rm $DELETED_FILES git commit -m'File deletions' fi # HEAD is now like upstream, but with files deleted base=$(git rev-parse HEAD) git diff $base $SAVED_HEAD | filterdiff -x '[ab]/debian/*' --clean >> $tmpdir/diff if [ -s $tmpdir/diff ]; then git apply --whitespace=nowarn --index $tmpdir/diff || \ _die "fatal: apply failed" git commit -F $tmpdir/message 1>/dev/null 2>&1 || \ _die "fatal: fixup commit failed" fi if [ -s $tmpdir/patch-list ]; then while read -r hash ; do debug "trying %s\n" $hash if ! git cherry-pick --no-edit $hash 1>/dev/null 2>&1; then if [ -z "$(git diff --cached)" ]; then echo "skipping $hash; empty cherry-pick" >&2 continue fi _die "cherry-pick $hash failed" fi if $NOTES && git notes show $hash >/dev/null 2>&1; then git notes copy $hash HEAD; fi if [ -z "$(git diff $base)" ]; then base=$(git rev-parse HEAD); debug "new base ${base}" fi done < <(tac $tmpdir/patch-list) fi if [ $stat_only = "yes" ]; then git log --reverse --oneline --stat "$base"..HEAD else if [ -n "$patch_dir" ]; then mkdir -p "$patch_dir" || _die "mkdir failed"; echo "# exported from git by git-debcherry" > "$patch_dir/series" if PATCHES=$(git format-patch --no-signature --notes -o "$patch_dir" "$base"..HEAD ); then if [ -n "$PATCHES" ]; then echo "$PATCHES" | sed -e "s,$patch_dir/,,g" -e 's, ,\n,g' >> "$patch_dir/series" else echo "Warning: no patches exported" fi else _die "git format-patch failed" fi else git format-patch --no-signature --notes --stdout $base..HEAD fi fi _time $LINENO gitpkg-0.31/git-debcherry.10000644000000000000000000000561714505757621012447 0ustar .\" Hey, EMACS: -*- nroff -*- .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) .TH GIT\-DEBCHERRY 1 "April 27, 2014" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME git\-debcherry \- export commits touching upstream source as patches .SH SYNOPSIS .B git\-debcherry .RI [ options "] " upstream " [" integration ] .SH DESCRIPTION This program will analyze git history and try to create a set of patches meeting the following conditions: .RS 4 1. Is guaranteed to apply to .I upstream 2. Produces the same work tree as \fIintegration\fP, outside \fI./debian\fP 3. Does not touch \fI./debian\fP 4. As much as possible, matches the git history from .I upstream to .I integration .RE .SH BRANCH PARAMETERS .TP .I upstream This ref should be suitable for export as a .I .orig.tar.gz. In particular note that quilt has no way of deleting files that does not include the material to be deleted in the patch, so your .I upstream branch should include any necessary file deletions. .TP .I integration This branch contains all debian packaging, plus any changes introduced to upstream source by the debian packager. This argument is optional. If .I integration is not passed .B git\-debcherry will use \fIHEAD\fP. .RE .SH OPTIONS The following options are available: .TP .BI "\-o, \-\-output\-directory " directory Place output (patches and series file) in \fIdirectory\fP. If unspecified, output patches (in mbox format) to stdout. .TP .B \-s, \-\-stat Only output diffstat of patches .TP .B \-d, \-\-debug Output some debugging information. Probably only useful to developers or those reporting bugs. .SH EXAMPLE To export the patches between tag \fIv3.0+dfsg1\fP and the current branch into \fI./debian/patches\fP: .nf $ git\-debcherry \-o debian/patches v3.0+dfsg1 .fi .SH NOTES .SS PERFORMANCE \fBgit\-debcherry\fP currently uses .BR git\-filter\-branch (1) to rewrite all commits on the integration branch not present upstream. Depending on the number of such commits, this can be noticeably slow. .SS DELETED FILES \fBgit\-debcherry\fP currently follows .BR dpkg\-source (1) in ignoring file deletions. This has the positive side effect of not bloating the patches, but if you really need the files deleted for the build and/or licensing reasons, you should delete them in \fIupstream\fP. .SH SEE ALSO .BR gitpkg (1) .SH AUTHOR \fBgit\-debcherry\fP was written by David Bremner . gitpkg-0.31/git-debimport0000755000000000000000000003424514505757621012330 0ustar #!/bin/bash # Simple shell script for importing a collection of Debian source packages # into a git repository. # # Copyright(C) 2007, 2008, Ron # This script is distributed according to the terms of the GNU GPL. set -e UPSTREAM_BRANCH="upstream" DEBIAN_BRANCH="master" UPSTREAM_TAG_PREFIX="v" DEBIAN_TAG_PREFIX="v" # We default to the linux kernel style tags, but people who prefer the # git-buildpackage style and like slashes in their tags can do this: #UPSTREAM_TAG_PREFIX="$UPSTREAM_BRANCH/" #DEBIAN_TAG_PREFIX="debian/" usage() { cat 1>&2 </dev/null | sort)" } get_debian_sources() { echo "$(find $1 -type f -name "${2}_*.diff.gz" \ -o -name "${2}_*.debian.tar.gz" \ -o -name "${2}_*.debian.tar.bz2" \ -o -name "${2}_*.debian.tar.xz" \ 2>/dev/null | sort)" } PACKAGE_TARS="$(get_native_sources "$PACKAGES_DIR" "$PACKAGE_NAME")" PACKAGE_DIFFS="$(get_debian_sources "$PACKAGES_DIR" "$PACKAGE_NAME")" if [ -z "$PACKAGE_DIFFS" ] && [ -z "$PACKAGE_TARS" ]; then if [ -z "$fetch_snapshots" ]; then echo "No ${package_path}_* diff.gz or tar.{gz,bz2,xz} files found, aborting." exit 1 fi DEBSNAP="$(which debsnap || true)" if [ -z "$DEBSNAP" ]; then echo "debsnap not found, unable to fetch files." exit 1 fi $DEBSNAP $verbose --destdir="$PACKAGES_DIR" "$PACKAGE_NAME" || ret=$? case "$ret" in "") ;; 2) echo "WARNING: some files failed to be fetched" ;; *) echo "ERROR: return code $ret from $DEBSNAP, aborting." exit 1 ;; esac PACKAGE_TARS="$(get_native_sources "$PACKAGES_DIR" "$PACKAGE_NAME")" PACKAGE_DIFFS="$(get_debian_sources "$PACKAGES_DIR" "$PACKAGE_NAME")" if [ -z "$PACKAGE_DIFFS" ] && [ -z "$PACKAGE_TARS" ]; then echo "No packages were able to be fetched, aborting." exit 1 fi elif [ -n "$fetch_snapshots" ]; then echo "Package files already exist under $PACKAGES_DIR" echo "Please (re)move them first if you wish to --fetch snapshots." exit 1 fi if [ -n "$PACKAGE_DIFFS" ] && [ -n "$PACKAGE_TARS" ]; then echo "A mix of native and non-native package exist in $PACKAGES_DIR" echo "That case isn't handled yet, sorry. Patches welcome if you need it." exit 1 fi CACHE_DIR="../${PACKAGE_NAME}-import-cache" strip_native_suffix() { ( shopt -s extglob echo "${1%.tar.@(gz|bz2|xz)}" ) } strip_debian_suffix() { # This one is a bit more permissive than is actually allowed at present. # Only diff.gz is actually supported by dpkg, but we don't really care # about that here, since we aren't making packages, just unpacking them, # and a diff.xz is as good as anything else for that if someone has one. ( shopt -s extglob echo "${1%.@(diff|debian.tar).@(gz|bz2|xz)}" ) } get_compression_type() { case $1 in *.gz) echo "gz" ;; *.bz2) echo "bz2" ;; *.xz) echo "xz" ;; *) echo "Unsupported compression type for '$1'" >&2 exit 1 ;; esac } get_orig_type() { if [ -e "$1.gz" ]; then echo "gz" elif [ -e "$1.bz2" ]; then echo "bz2" elif [ -e "$1.xz" ]; then echo "xz" else echo "Unable to locate orig '$1.{gz,bz2,xz}'" >&2 exit 1 fi } compare_tars() { p1="$(strip_native_suffix $1)" p2="$(strip_native_suffix $2)" p1="${p1##*_}" p2="${p2##*_}" dpkg --compare-versions "$p1" gt "$p2" } compare_diffs() { p1="$(strip_debian_suffix $1)" p2="$(strip_debian_suffix $2)" p1="${p1##*_}" p2="${p2##*_}" dpkg --compare-versions "$p1" gt "$p2" } single_subdir() { _ssd= for f in $1/*; do [ -z "$_ssd" ] || exit 1 [ -d "$f" ] || exit 1 _ssd="$f" done echo "$_ssd" } unpack_tarball() { rm -rf "$CACHE_DIR" mkdir -p "$CACHE_DIR/$2" tar -xf "$1" -C "$CACHE_DIR/$2" } copy_sourcedir() { if SINGLE_SUBDIR="$(single_subdir $CACHE_DIR/$1)"; then find "$SINGLE_SUBDIR" -maxdepth 1 -mindepth 1 -exec cp -al '{}' . \; else find "$CACHE_DIR/$1" -maxdepth 1 -mindepth 1 -exec cp -al '{}' . \; fi } move_sourcedir() { if SINGLE_SUBDIR="$(single_subdir $CACHE_DIR/$1)"; then find "$SINGLE_SUBDIR" -maxdepth 1 -mindepth 1 -exec mv '{}' . \; else find "$CACHE_DIR/$1" -maxdepth 1 -mindepth 1 -exec mv '{}' . \; fi } mkdir "$PACKAGE_NAME" cd "$PACKAGE_NAME" git init if [ -n "$PACKAGE_TARS" ]; then # See below for details on sorting the package order ... P=( $PACKAGE_TARS ) count=${#P[*]} for(( i=1; i < count; ++i )) do j=$i while (($j)) && compare_tars "${P[j-1]}" "${P[i]}"; do ((--j)) || true; done ((i==j)) || P=( ${P[@]:0:j} ${P[i]} ${P[j]} ${P[@]:j+1:i-(j+1)} ${P[@]:i+1} ) done PACKAGE_TARS="${P[@]}" for f in $PACKAGE_TARS; do PACKAGE_VERSION="$(strip_native_suffix $f)" PACKAGE_VERSION="${PACKAGE_VERSION##*_}" COMP_TYPE="$(get_compression_type $f)" echo "Importing $PACKAGES_DIR/${PACKAGE_NAME}_${PACKAGE_VERSION}.tar.$COMP_TYPE" find -maxdepth 1 -mindepth 1 \! -name ".git" -exec rm -rf '{}' + unpack_tarball "$PKG_ROOT$PACKAGES_DIR/${PACKAGE_NAME}_${PACKAGE_VERSION}.tar.$COMP_TYPE" \ "${PACKAGE_NAME}-${UPSTREAM_VERSION}.tmp" move_sourcedir "${PACKAGE_NAME}-${UPSTREAM_VERSION}.tmp" # Shouldn't be needed here, but just in case ... chmod 755 debian/rules DATE=$(dpkg-parsechangelog | sed -n 's/Date: //p') AUTHOR=$(dpkg-parsechangelog | sed -n 's/Maintainer: //p' | cut -d\< -f1) EMAIL=\<$(dpkg-parsechangelog | sed -n 's/Maintainer: //p' | cut -d\< -f2) git add . if git --no-pager commit --dry-run -a > /dev/null 2>&1; then GIT_AUTHOR_NAME="$AUTHOR" GIT_COMMITTER_NAME="$AUTHOR" \ GIT_AUTHOR_EMAIL="$EMAIL" GIT_COMMITTER_EMAIL="$EMAIL" \ GIT_AUTHOR_DATE="$DATE" GIT_COMMITTER_DATE="$DATE" \ git commit -a -m "git-debimport ${PACKAGE_NAME}_${PACKAGE_VERSION}.tar.$COMP_TYPE" else echo "WARNING: nothing to commit for ${PACKAGE_NAME}_${PACKAGE_VERSION}.tar.$COMP_TYPE" fi git tag $(sanitise_git_ref "$DEBIAN_TAG_PREFIX$PACKAGE_VERSION") done rm -rf "$CACHE_DIR" echo "All done!" exit 0 fi # We really need the packages in the order dpkg thinks they are in here, and # the only way to reliably know that is to ask dpkg what it thinks. Since that # is a rather expensive operation, and the number of operations to be performed # grows rapidly as the number of packages to import gets longer, we must do the # only sane thing feasible, and cheat. # # By doing a fast lexical pre-sort of the list, we can in almost all but the # most pathological cases get the order almost, or even exactly, right. So from # that probable starting point, Simplicity, in her infinite wisdom, will reward # all those people who numbered their packages sanely, with O(n) or near to it # performance in determining the Proper order if we just do a trivial insertion # sort for this next step. # # Pros: # The Good People will get better results than the most fancy patent pending # product of a college education algorithm is likely to do, and the Bad People # will get the time-squared in purgatory that they deserve. # # Cons: # Had you inferred all this from the 4 lines of code below? # # Todo: # Maybe output a warning that this could take a while if $count > N. # Determine N. P=( $PACKAGE_DIFFS ) count=${#P[*]} for(( i=1; i < count; ++i )) do j=$i #echo "was $i: ${P[i]}" while (($j)) && compare_diffs "${P[j-1]}" "${P[i]}"; do ((--j)) || true; done ((i==j)) || P=( ${P[@]:0:j} ${P[i]} ${P[j]} ${P[@]:j+1:i-(j+1)} ${P[@]:i+1} ) done #for(( i=1; i < count; ++i )) do echo "now $i: ${P[i]}"; done PACKAGE_DIFFS="${P[@]}" for f in $PACKAGE_DIFFS; do case "$f" in *.diff.gz) DIFF_TYPE="diff.gz" ;; *.debian.tar.gz | *.debian.tar.bz2 | *.debian.tar.xz) DIFF_TYPE="debian.tar.$(get_compression_type $f)" ;; esac DEBIAN_VERSION="$(strip_debian_suffix $f)" DEBIAN_VERSION="${DEBIAN_VERSION##*_}" UPSTREAM_VERSION="${DEBIAN_VERSION%-*}" if [ -z "$LAST_UPSTREAM_VERSION" ]; then ORIG_TYPE="$(get_orig_type "$PKG_ROOT$PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar")" echo "Initial import of $PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.$ORIG_TYPE" unpack_tarball "$PKG_ROOT$PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.$ORIG_TYPE" \ "${PACKAGE_NAME}-${UPSTREAM_VERSION}.tmp" copy_sourcedir "${PACKAGE_NAME}-${UPSTREAM_VERSION}.tmp" DATE="$(file -L $PKG_ROOT$PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.$ORIG_TYPE \ | sed -n "s/.*, last modified: \([^,]*\),*.*/\1/p")" git add . if git --no-pager commit --dry-run -a > /dev/null 2>&1; then GIT_AUTHOR_DATE="$DATE" GIT_COMMITTER_DATE="$DATE" \ git commit -a -m "git-debimport ${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.$ORIG_TYPE" else # This particular case probably should still crap out, if the # initial orig is empty that doesn't bode well for things to come echo "WARNING: nothing to commit for ${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.$ORIG_TYPE" fi git checkout -b "$UPSTREAM_BRANCH" git tag $(sanitise_git_ref "$UPSTREAM_TAG_PREFIX$UPSTREAM_VERSION") LAST_UPSTREAM_VERSION="$UPSTREAM_VERSION" git checkout "$DEBIAN_BRANCH" fi if [ "$LAST_UPSTREAM_VERSION" != "$UPSTREAM_VERSION" ]; then ORIG_TYPE="$(get_orig_type "$PKG_ROOT$PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar")" echo "Importing $PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.$ORIG_TYPE" git checkout "$UPSTREAM_BRANCH" find -maxdepth 1 -mindepth 1 \! -name ".git" -exec rm -rf '{}' + unpack_tarball "$PKG_ROOT$PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.$ORIG_TYPE" \ "${PACKAGE_NAME}-${UPSTREAM_VERSION}.tmp" copy_sourcedir "${PACKAGE_NAME}-${UPSTREAM_VERSION}.tmp" DATE="$(file -L $PKG_ROOT$PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.$ORIG_TYPE \ | sed -n "s/.*, last modified: \([^,]*\),*.*/\1/p")" git add . if git --no-pager commit --dry-run -a > /dev/null 2>&1; then GIT_AUTHOR_DATE="$DATE" GIT_COMMITTER_DATE="$DATE" \ git commit -a -m "git-debimport ${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.$ORIG_TYPE" else echo "WARNING: nothing to commit for ${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.$ORIG_TYPE" fi git tag $(sanitise_git_ref "$UPSTREAM_TAG_PREFIX$UPSTREAM_VERSION") LAST_UPSTREAM_VERSION="$UPSTREAM_VERSION" git checkout "$DEBIAN_BRANCH" [ -n "$late_merge" ] || git merge "$UPSTREAM_BRANCH" #XXX If we were to just always merge here with -s ours, would that # avoid the chance of merge conflicts but still keep the accurate # history once we've fixed up the branch below? # Try this when we find a set of packages that do have conflicts. fi echo "Importing $f" find -maxdepth 1 -mindepth 1 \! -name ".git" -exec rm -rf '{}' + copy_sourcedir "${PACKAGE_NAME}-${UPSTREAM_VERSION}.tmp" case "$f" in *.diff.gz) zcat "$PKG_ROOT$f" | patch -p1 ;; *.debian.tar.gz | *.debian.tar.bz2 | *.debian.tar.xz) tar -xf "$PKG_ROOT$f" ;; esac chmod 755 debian/rules DATE=$(dpkg-parsechangelog | sed -n 's/Date: //p') AUTHOR=$(dpkg-parsechangelog | sed -n 's/Maintainer: //p' | cut -d\< -f1) EMAIL=\<$(dpkg-parsechangelog | sed -n 's/Maintainer: //p' | cut -d\< -f2) git add . if git --no-pager commit --dry-run -a > /dev/null 2>&1; then GIT_AUTHOR_NAME="$AUTHOR" GIT_COMMITTER_NAME="$AUTHOR" \ GIT_AUTHOR_EMAIL="$EMAIL" GIT_COMMITTER_EMAIL="$EMAIL" \ GIT_AUTHOR_DATE="$DATE" GIT_COMMITTER_DATE="$DATE" \ git commit -a -m "git-debimport ${PACKAGE_NAME}_${DEBIAN_VERSION}.$DIFF_TYPE" else echo "WARNING: nothing to commit for ${PACKAGE_NAME}_${DEBIAN_VERSION}.$DIFF_TYPE" fi git tag $(sanitise_git_ref "$DEBIAN_TAG_PREFIX$DEBIAN_VERSION") done rm -rf "$CACHE_DIR" [ -z "$late_merge" ] || git merge -s ours "$UPSTREAM_BRANCH" echo "All done!" # vi:sts=4:sw=4:noet:foldmethod=marker gitpkg-0.31/git-debimport.10000644000000000000000000001375714505757621012471 0ustar .\" Hey, EMACS: -*- nroff -*- .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) .TH GIT\-DEBIMPORT 1 "September 21, 2007" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME git\-debimport \- create a git repository from a set of existing Debian packages .SH SYNOPSIS .B git\-debimport .RI [ options ] " path\-prefix" .SH DESCRIPTION This program will create a git repository of all files that match ${path\-prefix}_*.diff.gz or ${path\-prefix}_*.debian.tar.{gz,bz2,xz} (with their corresponding orig.tar.{gz,bz2,xz}), or of all files that match ${path\-prefix}_*.tar.{gz,bz2,xz} (for Debian native packages). .SH OPTIONS The following options are available: .TP .B \-\-fetch Attempt to download all available versions from snapshot.debian.org rather than use an existing set of packages. The \fBdebsnap\fP(1) utility, from devscripts 2.10.63 or later, must be available in the path to use this option (earlier \fBdebsnap\fP versions only supported snapshot.debian.net which is no longer a functional mirror). The packages will be downloaded into the location implied by the \fIpath\-prefix\fP where they would normally be expected to exist already without this option. Downloaded packages will not automatically be removed after this operation is complete. .TP .B \-\-late\-merge Early versions of \fBgit\-debimport\fP would only merge the upstream and debian branches after the import of all packages was complete. This avoids an import failing where the merge might have conflicts that would need to be manually resolved. We know the import of the next package in the series will contain a resolution to any such conflict, so delaying the merge allows the import to proceed without intervention or introducing changes that were not part of the original history. It does however produce a lesser quality history for the purposes of browsing the Debian changes. All the original packages may be retrieved from such a repo with perfect fidelity, but the diff between adjacent Debian versions will be mingled with upstream changes too. The default for current versions of \fBgit\-debimport\fP is to merge each new upstream release as it is imported. This gives a much more natural and useful looking history, but may fail in some cases. Use this option to employ the older more reliable method for packages that generate conflicts during import. .TP .B \-v, \-\-verbose Be more noisy about reporting operations in progress. Mostly only useful with the \fB\-\-fetch\fP option at present. .SH EXAMPLE Import an archive of existing 'mypackagename' packages from mysrcdir: .br $ mkdir mydestdir && cd mydestdir .br $ git\-debimport ../mysrcdir/mypackagename Import all available versions of \fBgitpkg\fP from snapshot.debian.org: .br $ mkdir mydestdir && cd mydestdir .br $ git\-debimport \-\-fetch ../my\-gitpkg\-sources/gitpkg .SH NOTES It is unfortunate that at the present time, many of the tools for importing source to git from an existing revision control system all leave something to be desired. This script does not solve that problem. What it does do however is create a repository that makes it possible to accurately extract all of the earlier packages which were injected to it. This is sadly more than can be said for the result of running git\-cvsimport on a repo created by cvs\-buildpackage, for example. It is currently very simple, and makes a number of hard-coded assumptions about the resulting repo. For debian-versioned packages it will create a repo with two branches: .BR upstream " \- for the pristine upstream source" .br .BR master " \- for the Debianised source" Native versioned packages will have only the master branch. While the loss of fine grained history on individual commits is most regrettable, this script enables a maintainer to import a usable record of the previously released packages as a base for future development. This may be an acceptable trade-off for people who feel the advantage of moving future development to git now outweighs the inconvenience of needing to refer to a legacy repository for full details of previous commits. Hopefully the problems of accurately importing from other revision control systems will be solved one day, but in the meantime, a brief but accurate history seems more useful than a detailed but largely bogus one. With the addition of the \fBdebsnap\fP(1) tool, the useful life of this has been extended beyond the originally envisaged need. People who do not have access to the original revision control history at all can build for themselves a useful base for further development, quickly and easily, from the packages that are still available on public snapshot mirrors. .SH BUGS \fBgit\-debimport\fP does not currently handle packages with mixed 'native' and debian-versioned releases. This may be added in a later version if people have real examples of such packages they wish to import with it and we figure out a sensible convention for how they should be stored in the resulting repository. Nothing particularly intelligent is done with format 3.0 (quilt) patches currently. The debian/patches, if any, are simply imported verbatim as found in the source package. Ideally they should be committed to some git branch and generated on demand at export time, rather than perpetuating the patch-in-patch nightmare. Any packages so imported will be recreated accurately on export, but this isn't really the best form to actually work with them in git in most cases. .SH SEE ALSO .BR gitpkg (1), .BR debsnap (1) .SH AUTHOR gitpkg was written by Ron . gitpkg-0.31/gitpkg0000755000000000000000000011142014505757621011036 0ustar #!/bin/bash # Simple shell script for creating Debian source releases from a git repository # # Copyright(C) 2007 - 2023, Ron # This script is distributed according to the terms of the GNU GPL. set -e # This has nothing to do with the release version of the package, it is for # hook scripts to check what guarantees we might make for them. The number # to the right of point will get incremented every time we add some new # variable a hook might access, or add some new knob it might tweak. # Existing interfaces should not have changed. If we do screw up and need # to change some current thing, the number to the left will get bumped. # For what you get with each revision see gitpkg(1). GITPKG_HOOK_API="0.3" # Parse the command line. # # As a general rule it is not in gitpkg's idiom to accept command line options, # or at least that was one of the original design goals that we'd held dear to. # The main reason for this being the importance of ensuring an export is easily # and reliably reproducible - and if reproducing the build depends on recalling # the precise options that gitpkg was called with beyond simply the version you # wish to export, then you've pretty much guaranteed failure at that before you # even begin. The first exception we made to this was to handle the --version # and --help options gracefully, since many people have (valid) expectations of # those doing something other than trying to export a ref with those names ... # That was ok though, because they have nothing to do with actually exporting a # package, so it didn't violate the primary goal. It turns out there are other # options which usefully fit the same exception too though. Things like making # the choice of which exit hook to run, and what options it should be run with # are quite reasonable to make on a per-invocation basis, since they don't make # any difference to the actual package exported, only what is done with it once # it is. For things like that it does seem silly to stick to some false purity # and insist the only way to tweak those is to edit the git config. Ideally it # still should be 'hard' to 'accidentally' make the correct export of a package # depend on the command line options that are passed, so not every option ought # to be able to be overridden here, but there's clearly a few which it is saner # to allow than not to, given the way things have now evolved. # # This parser separates the command line arguments into three main groups based # on how they are handled. Options are of the form --opt or --opt=val, and are # divided into two groups, those that are for gitpkg itself and those which are # ignored by gitpkg but may be used by the hook scripts. The options that will # be handled by gitpkg directly either result in some immediate action (so that # hook scripts are never called at all) or get exposed by the variable which is # already responsible for the option being overridden. All other options which # are passed will be stored verbatim in an indexed array GITPKG_IOPTS to permit # options which may be passed multiple times with multiple values, and they are # also decomposed into an associative array GITPKG_AOPTS, for trivial access to # options which should only be passed once (or for which only the last value to # be passed will be used). Hook scripts can example these for options relevant # to their operation. Options that are specific to a particular hook should be # named something sufficiently unique to avoid unintentional collisions, unless # the option really is generally relevant to multiple hooks. The latter is the # only case where such options need to be coordinated here for all gitpkg users # otherwise hooks can define and handle whatever they please as they please. # # The third group of arguments is 'parameters' which typically don't start with # '--' and provide us with the debian and (optional) orig treeish(s) to export. # In the unlikely event that someone was ever insane enough to create a treeish # ref that does start with '--' (which git does allow in principle), then using # a literal ' -- ' argument can be used to separate options from parameters in # the conventional manner. Parameters are stored in the GITPKG_PARAMS array but # since it is only valid to pass one or two of them they should more usually be # accessed using the GITPKG_TREEISH and GITPKG_ORIG_TREEISH variables instead. declare -A GITPKG_AOPTS declare -a GITPKG_IOPTS for arg; do case $arg in --) no_more_opts=1 ;; --deb-dir=*) OVERRIDE_DEB_DIR=${arg#*=} ;; --admin-config-hook=*) OVERRIDE_ADMIN_CONFIG_HOOK=${arg#*=} if [ -n "$OVERRIDE_ADMIN_CONFIG_HOOK" ] && [ ! -r "$OVERRIDE_ADMIN_CONFIG_HOOK" ]; then echo "ERROR: cannot read admin-config-hook '$OVERRIDE_ADMIN_CONFIG_HOOK'" 1>&2 exit 1 fi ;; --exit-hook=*) OVERRIDE_EXIT_HOOK=${arg#*=} if [ -n "$OVERRIDE_EXIT_HOOK" ]; then if [ ! -r "$OVERRIDE_EXIT_HOOK" ]; then hook_dir="/usr/share/gitpkg/hooks" if [ -r "$hook_dir/$OVERRIDE_EXIT_HOOK" ]; then OVERRIDE_EXIT_HOOK="$hook_dir/$OVERRIDE_EXIT_HOOK" elif [ -r "$hook_dir/${OVERRIDE_EXIT_HOOK}-exit-hook" ]; then OVERRIDE_EXIT_HOOK="$hook_dir/${OVERRIDE_EXIT_HOOK}-exit-hook" else echo "ERROR: cannot read exit-hook '$OVERRIDE_EXIT_HOOK'" 1>&2 exit 1 fi fi fi ;; --keep-unpacked-source) OVERRIDE_KEEP_UNPACKED_SOURCE="true" ;; --keep-unpacked-source=*) case ${arg#*=} in n* | N* | f* | F*) OVERRIDE_KEEP_UNPACKED_SOURCE="false" ;; *) OVERRIDE_KEEP_UNPACKED_SOURCE="true" ;; esac ;; --dpkg-source=*) OVERRIDE_DPKG_SOURCE+=( "${arg#*=}" ) ;; --help) [ -n "$no_more_opts" ] || exec man gitpkg ;& --version) [ -n "$no_more_opts" ] || exec dpkg-query -W -f='${Package} ${Version}\n' gitpkg ;& --*=*) if [ -z "$no_more_opts" ]; then _name="${arg%%=*}" GITPKG_AOPTS[${_name#--}]=${arg#*=} GITPKG_IOPTS+=( "$arg" ) continue fi ;& --*) if [ -z "$no_more_opts" ]; then GITPKG_AOPTS[${arg#--}]= GITPKG_IOPTS+=( "$arg" ) continue fi ;& *) GITPKG_PARAMS+=( "$arg" ) ;; esac done # If we've been run for a repo with submodules, from a working directory that # is managed by a submodule, then all git commands we use will operate on the # submodule, not the superproject, and all bets about what the caller really # intended are off. We can check if there is an immediate superproject, but # if that is also a submodule of some larger superproject then we have no way # of knowing for sure how far up that tree we should climb. # # So the only sane and safe option is to check if the user has configured the # allow-subproject-export option, or to prompt them about whether exporting # just the submodule was what they really wanted to do, and if it wasn't, to # instead run gitpkg from a working dir of the superproject that they wish to # export... Have we mentioned submodules probably aren't the solution you are # looking for ... we can try to accommodate them, but they do add complexity # and novel problems that we just can't hide. if [ -n "$(git rev-parse --show-superproject-working-tree)" ]; then ALLOW_SUBPROJECT_EXPORT="$(git config --get gitpkg.allow-subproject-export)" || true if [ "$ALLOW_SUBPROJECT_EXPORT" = "true" ]; then echo "Exporting submodule package only." else cat <<-EOF You have run gitpkg in the working tree of a submodule. If you wanted to export the super-project, this will not do what you were expecting. You need to run gitpkg from a working dir of the (super) project that you wish to export and there is no sane way to be sure how far up this tree we should climb automatically. EOF if [ "$ALLOW_SUBPROJECT_EXPORT" = "false" ]; then echo "Aborting export because gitpkg.allow-subproject-export is 'false'." exit 1 fi printf "Export just the submodule source (y/N)? " read -e yesno case $yesno in Y* | y*) cat <<-EOF Ok then. If you plan to make a habit of this you may wish to set: git config gitpkg.allow-subproject-export 'true' To avoid being asked about it again each time. EOF ;; *) cat <<-EOF Aborting export. To avoid being asked about this again you can set git config gitpkg.allow-subproject-export 'false' and then in future this will simply print an error and fail. EOF exit 1 ;; esac fi fi # Everything here assumes we started in the TLD of the repo, so if we aren't # there already, let's go there now. Note that if we're in the working dir of # a submodule, this will only go up to the root of the submodule, not to the # root of its superproject (hence the checks above). _TLD=$(git rev-parse --show-cdup) [ -z "$_TLD" ] || cd "$_TLD" # Remember where we are right now, in absolute terms, in case things that run # out of the repo tree really need to do something in it. Like call git-config. # Usually if you're out of the tree you should stay there though, so if you do # use this for something, think carefully about what you are really doing. REPO_DIR=$(pwd) # You can ignore most of this first lot. We temporarily waste a bunch of your # startup cycles being far too friendly about migrating users to the new config. # It could probably be packed into just a few lines of deep recursion, but we'll # just drop it completely once people have migrated. # I figure if it saves me two "how do I ..." email exchanges with users, it will # have paid for every line of itself in time saved for everyone :) # {{{ if [ -r /etc/gitpkg.conf ]; then . /etc/gitpkg.conf if [ -n "$BUILD_ROOTCMD" ]; then EXIT_MSG="${EXIT_MSG}# git config --system gitpkg.build-rootcmd '$BUILD_ROOTCMD'\n" _BUILD_ROOTCMD="$BUILD_ROOTCMD" fi if [ -n "$DEB_DIR" ]; then EXIT_MSG="${EXIT_MSG}# git config --system gitpkg.deb-dir '$DEB_DIR'\n" _DEB_DIR="$DEB_DIR" fi if [ -n "$HOOK_FILE" ]; then EXIT_MSG="${EXIT_MSG} (You may want to hook only one of the next two)\n" EXIT_MSG="${EXIT_MSG}# git config --system gitpkg.deb-export-hook '$HOOK_FILE'\n" EXIT_MSG="${EXIT_MSG}# git config --system gitpkg.orig-export-hook '$HOOK_FILE'\n" _HOOK_FILE="$HOOK_FILE" fi if [ -n "$EXIT_MSG" ]; then OLD_ROOT_CONFIG="# rm /etc/gitpkg.conf\n" fi fi if [ -r ~/.gitpkg ]; then . ~/.gitpkg if [ "$_BUILD_ROOTCMD" != "$BUILD_ROOTCMD" ]; then EXIT_MSG="${EXIT_MSG}\$ git config --global gitpkg.build-rootcmd '$BUILD_ROOTCMD'\n" _BUILD_ROOTCMD="$BUILD_ROOTCMD" _OLD_CONFIG="~/.gitpkg" fi if [ "$_DEB_DIR" != "$DEB_DIR" ]; then EXIT_MSG="${EXIT_MSG}\$ git config --global gitpkg.deb-dir '$DEB_DIR'\n" _DEB_DIR="$DEB_DIR" _OLD_CONFIG="~/.gitpkg" fi if [ "$_HOOK_FILE" != "$HOOK_FILE" ]; then EXIT_MSG="${EXIT_MSG} (You may want to hook only one of the next two)\n" EXIT_MSG="${EXIT_MSG}\$ git config --global gitpkg.deb-export-hook '$HOOK_FILE'\n" EXIT_MSG="${EXIT_MSG}\$ git config --global gitpkg.orig-export-hook '$HOOK_FILE'\n" _HOOK_FILE="$HOOK_FILE" _OLD_CONFIG="~/.gitpkg" fi OLD_CONFIG="$_OLD_CONFIG" _OLD_CONFIG= fi if [ -r .git/gitpkg.conf ]; then . .git/gitpkg.conf if [ "$_BUILD_ROOTCMD" != "$BUILD_ROOTCMD" ]; then EXIT_MSG="${EXIT_MSG}\$ git config gitpkg.build-rootcmd '$BUILD_ROOTCMD'\n" _OLD_CONFIG=".git/gitpkg.conf" fi if [ "$_DEB_DIR" != "$DEB_DIR" ]; then EXIT_MSG="${EXIT_MSG}\$ git config gitpkg.deb-dir '$DEB_DIR'\n" _OLD_CONFIG=".git/gitpkg.conf" fi if [ "$_HOOK_FILE" != "$HOOK_FILE" ]; then EXIT_MSG="${EXIT_MSG} (You may want to hook only one of the next two)\n" EXIT_MSG="${EXIT_MSG}\$ git config gitpkg.deb-export-hook '$HOOK_FILE'\n" EXIT_MSG="${EXIT_MSG}\$ git config gitpkg.orig-export-hook '$HOOK_FILE'\n" _OLD_CONFIG=".git/gitpkg.conf" fi OLD_CONFIG="${OLD_CONFIG:+$OLD_CONFIG }$_OLD_CONFIG" fi if [ -n "$OLD_CONFIG" ]; then OLD_CONFIG="$ rm $OLD_CONFIG\n" fi EXIT_MSG="$EXIT_MSG$OLD_ROOT_CONFIG$OLD_CONFIG" # sorry_dude OLD_VAR new-config new-value # We could loop harder and probably resolve conflicts like this, but it really # is better to just get rid of them asap. This should only bite the hardcore # tweakers, if there is some common pattern of innocent victims then we can see # what to do about those if or as they come. sorry_dude() { #{{{ cat 1>&2 <<-EOF Hmm. You have $1 set in an old-style config file and also have gitpkg.$2 set in git-config. Mixing old and new config options could go badly. Your old-style config options can be migrated into git-config now using the following: $(printf "$EXIT_MSG") The current git-config reported value for gitpkg.$2 is: '$3' When you have merged the desired options into git-config, simply run gitpkg again and everything should be peachy. Sorry for the hassle, but it's best you check this gets untangled in the right way for you before we continue in this repo. EOF exit 1 } #}}} # git-config is where static user preferences should be now. # In the case of a system with a partial transition between old and new config, # we bark and stop until the user can have a look and set it right. If it's # purely using the old config then we just growl and point -- people who didn't # fiddle with things deserve to have them still be working like they left them. if _GCBR="$(git config --get gitpkg.build-rootcmd)"; then [ -z "$BUILD_ROOTCMD" ] || sorry_dude BUILD_ROOTCMD build-rootcmd "$_GCBR" [ -z "$DEB_DIR" ] || sorry_dude DEB_DIR build-rootcmd "$_GCBR" [ -z "$HOOK_FILE" ] || sorry_dude HOOK_FILE build-rootcmd "$_GCBR" BUILD_ROOTCMD="$_GCBR" fi if _GCDD="$(git config --get gitpkg.deb-dir)"; then [ -z "$DEB_DIR" ] || sorry_dude DEB_DIR deb-dir "$_GCDD" [ -n "$_GCBR" ] \ || [ -z "$BUILD_ROOTCMD" ] || sorry_dude BUILD_ROOTCMD deb-dir "$_GCDD" [ -z "$HOOK_FILE" ] || sorry_dude HOOK_FILE deb-dir "$_GCDD" DEB_DIR="$_GCDD" fi if DEB_EXPORT_HOOK="$(git config --get gitpkg.deb-export-hook)"; then [ -z "$HOOK_FILE" ] || sorry_dude HOOK_FILE deb-export-hook "$DEB_EXPORT_HOOK" [ -n "$_GCBR" ] \ || [ -z "$BUILD_ROOTCMD" ] || sorry_dude BUILD_ROOTCMD deb-export-hook "$DEB_EXPORT_HOOK" [ -n "$_GCDD" ] \ || [ -z "$DEB_DIR" ] || sorry_dude DEB_DIR deb-export-hook "$DEB_EXPORT_HOOK" fi if ORIG_EXPORT_HOOK="$(git config --get gitpkg.orig-export-hook)"; then [ -z "$HOOK_FILE" ] || sorry_dude HOOK_FILE orig-export-hook "$ORIG_EXPORT_HOOK" [ -n "$_GCBR" ] \ || [ -z "$BUILD_ROOTCMD" ] || sorry_dude BUILD_ROOTCMD orig-export-hook "$ORIG_EXPORT_HOOK" [ -n "$_GCDD" ] \ || [ -z "$DEB_DIR" ] || sorry_dude DEB_DIR orig-export-hook "$ORIG_EXPORT_HOOK" fi # Really this should check against the treeish being exported, but this # first approximation should catch most affected people on the first pass. if [ -e .gitpkg_hook ] && [ "$HOOK_FILE" != ".gitpkg_hook" ] && [ "$DEB_EXPORT_HOOK" != ".gitpkg_hook" ] && [ "$ORIG_EXPORT_HOOK" != ".gitpkg_hook" ]; then cat 1>&2 <<-EOF Uh Oh. You're the one corner case I can't safely make life easy for. You have a .gitpkg_hook in the local repo but you never explicitly enabled it in your config. To enable it now you will need to do something like: \$ git config gitpkg.deb-export-hook '.gitpkg_hook' and/or \$ git config gitpkg.orig-export-hook '.gitpkg_hook' possibly in conjunction with a gitpkg.package-config-hook too. Please see gitpkg(1) for details of the new hook and config options. Since I can't tell this fine .gitpkg_hook of yours from a rogue power you found drifting about the nastyweb, I'm not going to give it a shell until you say that is OK with you, explicitly. And since your things probably need it, I should stop right here until you sort that out. Sorry. $(if [ -n "$EXIT_MSG" ]; then printf "\nTo migrate the rest of your existing config to use git-config(1)\n" printf "the following commands may be helpful too:\n\n" printf "$EXIT_MSG" printf " " fi) EOF exit 1 fi if [ -n "$HOOK_FILE" ]; then # This is just for compatibility with the original trivial hook, # not a recommendation of a particularly good idea in most cases. DEB_EXPORT_HOOK="$HOOK_FILE" ORIG_EXPORT_HOOK="$HOOK_FILE" fi # if the user is still using old config, prepare a gentle warning about that # to nag them with after all the action is over. It is expected this will # only be shown if subsequent operations succeed, in the event of some other # failure we can save the nagging until they are in a better mood for it. if [ -n "$EXIT_MSG" ]; then EXIT_MSG=$(cat <<-EOF OH HAI! gitpkg now uses git-config(1) for configuration data, and you have some options set in the old configuration files. They still worked ok this time, but you can use the following to migrate your existing config: $EXIT_MSG If you do nothing, things will continue to work as they do at present, and this message will continue to report the commands needed to migrate over to the standard git-config interface.\n\n EOF ) # I guess we _could_ add a "no really, just do it button here" ... fi # if all else fails, fit them up with some sensible shoes for the trek. : "${BUILD_ROOTCMD="fakeroot"}" : "${DEB_DIR="../deb-packages"}" # }}} # Ok you can open your eyes again now, this is where the script really starts. # All new config options should go below here, leave all that stuff above alone # until we can drop support for the old config files and just remove it again. # So... first we see what the local user left for us in git-config # Roughly in the order that they are used below: PACKAGE_CONFIG_HOOK="$(git config --get gitpkg.package-config-hook)" || true ADMIN_CONFIG_HOOK="$(git config --get gitpkg.admin-config-hook)" || true PRE_EXPORT_HOOK="$(git config --get gitpkg.pre-export-hook)" || true #DEB_EXPORT_HOOK="$(git config --get gitpkg.deb-export-hook)" || true PREBUILD_TARGET="$(git config --get gitpkg.prebuild-target)" || true EXPORT_SUBMODULES="$(git config --get --bool gitpkg.export-submodules)" || true CREATE_FAKE_ORIG="$(git config --get --bool gitpkg.create-fake-orig)" || true FORCE_OVERWRITE_ORIG="$(git config --get --bool gitpkg.force-overwrite-orig)" || true #ORIG_EXPORT_HOOK="$(git config --get gitpkg.orig-export-hook)" || true ORIG_COMPRESSOR="$(git config --get gitpkg.orig-compressor)" || ORIG_COMPRESSOR=gzip ORIG_COMPRESS_LEVEL="$(git config --get gitpkg.orig-compress-level)" || true DEB_COMPRESSOR="$(git config --get gitpkg.deb-compressor)" || true DEB_COMPRESS_LEVEL="$(git config --get gitpkg.deb-compress-level)" || true while read opt; do ORIG_GZ_OPTS+=("$opt") done < <(git config --get-all gitpkg.orig-gz-opts) # If ORIG_GZ_OPTS were not explicitly set, add -n to them here, so that we # default to creating a reproducible orig.tar.gz without a timestamp in it. [ ${#ORIG_GZ_OPTS[@]} -gt 0 ] || ORIG_GZ_OPTS=( "-n" ) while read opt; do ORIG_BZ2_OPTS+=("$opt") done < <(git config --get-all gitpkg.orig-bz2-opts) while read opt; do ORIG_XZ_OPTS+=("$opt") done < <(git config --get-all gitpkg.orig-xz-opts) while read opt; do DPKG_SOURCE_OPTS+=("$opt") done < <(git config --get-all gitpkg.dpkg-source) EXIT_HOOK="$(git config --get gitpkg.exit-hook)" || true KEEP_UNPACKED_SOURCE="$(git config --get gitpkg.keep-unpacked-source)" || true # XXX should the (an?) exit hook be run on failure too? # if we do that, we might also need to tell it how far we got # and why we croaked. Wait until someone needs that maybe. [ -z "$OVERRIDE_DEB_DIR" ] || DEB_DIR=$OVERRIDE_DEB_DIR [ -z "$OVERRIDE_ADMIN_CONFIG_HOOK" ] || ADMIN_CONFIG_HOOK=$OVERRIDE_ADMIN_CONFIG_HOOK [ -z "$OVERRIDE_EXIT_HOOK" ] || EXIT_HOOK=$OVERRIDE_EXIT_HOOK [ -z "$OVERRIDE_KEEP_UNPACKED_SOURCE" ] || KEEP_UNPACKED_SOURCE=$OVERRIDE_KEEP_UNPACKED_SOURCE usage() { #{{{ # We may not actually know the real final type yet here. case $ORIG_COMPRESSOR in gzip) OCEXT=".gz" ;; bzip2) OCEXT=".bz2" ;; xz) OCEXT=".xz" ;; *) OCEXT=".wtf" ;; esac cat 1>&2 <&2 echo " Are you from the ... future?" 1>&2 # If so, please add support for new formats here. # lzma is explicitly not supported since .xz already killed it. exit 1 ;; esac case $DEB_COMPRESSOR in gzip|bzip2|xz) DPKG_SOURCE_OPTS+=("-Z$DEB_COMPRESSOR") ;; '') ;; *) echo "gitpkg: Invalid deb-compressor '$DEB_COMPRESSOR' requested." 1>&2 echo " Are you from the ... future?" 1>&2 # If so, see above. exit 1 ;; esac [ -z "$DEB_COMPRESS_LEVEL" ] || DPKG_SOURCE_OPTS+=("-z$DEB_COMPRESS_LEVEL") ORIG_COMPRESS_OPTS+=( ${ORIG_COMPRESS_LEVEL:+-$ORIG_COMPRESS_LEVEL} ) get_deb_version() { #{{{ DEB_SOURCE="$(cd "$1" && dpkg-parsechangelog | awk '/Source:/ {print $2}')" DEB_VERSION="$(cd "$1" && dpkg-parsechangelog | sed -rne 's/^Version: ([^:]+:)?//p')" UPSTREAM_VERSION="${DEB_VERSION%-*}" DEB_PACKAGE="${DEB_SOURCE}-${UPSTREAM_VERSION}" DEB_DSC="${DEB_SOURCE}_${DEB_VERSION}.dsc" case $DEB_VERSION in *-*) DEB_ORIG="${DEB_SOURCE}_${UPSTREAM_VERSION}.orig.tar$OCEXT" ;; esac } #}}} # Fetch (just) the changelog, and loop out through another hook with the package # name and version information available too. It's too late to change anything # now, but not too late to check that it's all ok before getting started. if [ -n "$PRE_EXPORT_HOOK" ]; then mkdir -p "$DEB_DIR" git archive --format=tar --prefix="gitpkg-${GITPKG_TREEISH}/" \ "$GITPKG_TREEISH" debian/changelog | tar -C "$DEB_DIR" -xf - get_deb_version "$DEB_DIR/gitpkg-$GITPKG_TREEISH" rm -rf "$DEB_DIR/gitpkg-$GITPKG_TREEISH" if [ -z "$DEB_SOURCE" ] || [ -z "$DEB_VERSION" ]; then echo "ERROR: Failed to parse debian/changelog" 1>&2 exit 1 fi if ! ( . "$PRE_EXPORT_HOOK" ); then echo "ERROR: pre-export-hook '$PRE_EXPORT_HOOK' failed" 1>&2 exit 1 fi fi # get_submodules name/path-array treeish gitdir get_submodules() { #{{{ local -n mods=$1 local treeish=$2 gitdir=$3 k local -a conf_keys gitcmd=( 'git' ) if [ -n "$gitdir" ]; then git rev-parse --resolve-git-dir "$gitdir" > /dev/null 2>&1 || return 1 gitcmd+=( '--git-dir' "$gitdir" ) fi gitcmd+=( 'config' '--blob' "$treeish:.gitmodules" ) IFS= readarray -d '' conf_keys < \ <("${gitcmd[@]}" --name-only -z --get-regexp 'path$' 2>/dev/null) [ ${#conf_keys[@]} -gt 0 ] || return 1 for k in "${conf_keys[@]}"; do local _name=${k#submodule.} local name=${_name%.path} local path=$("${gitcmd[@]}" --get "$k") mods[$name]=$path done } #}}} # Return true if we need to export submodules, false if we don't, # and prompt if they exist but what to do with them is not already known. want_submodules() { #{{{ if [ "$EXPORT_SUBMODULES" = "false" ]; then echo "Ignoring submodules in '$1' because EXPORT_SUBMODULES is 'false'." return 1 fi local -A m get_submodules m "$1" || return 1 if [ "$EXPORT_SUBMODULES" = "true" ]; then echo "Exporting submodules of '$1' because EXPORT_SUBMODULES is 'true'." return 0 fi cat <<-EOF The '$1' revision of this repo contains one or more submodules. Historically gitpkg has silently ignored submodules because git-archive does not export them by default, but this version does support including them in the exported source package. If you always want to include them in future exports of this package then you can set: git config gitpkg.export-submodules 'true' in the superproject configuration. If you want to always ignore them (preserving the historical behaviour of gitpkg) then you can set: git config gitpkg.export-submodules 'false' in the superproject configuration. If that option is not set, then you will be prompted for each export of a treeish containing submodules about whether to include them or not. EOF printf "Export all submodules for this package (y/N)? " read -e yesno case $yesno in Y* | y*) cat <<-EOF Ok then. If you plan to make a habit of this you may wish to set: git config gitpkg.export-submodules 'true' in the superproject configuration, to avoid being asked about it again each time. EOF EXPORT_SUBMODULES="true" ;; *) cat <<-EOF Ignoring submodules. To avoid being asked about this again you can set git config gitpkg.export-submodules 'false' in the superproject configuration, and then all subprojects will be silently ignored as they are by git-archive. EOF EXPORT_SUBMODULES="false" return 1 ;; esac } #}}} export_submodules() { #{{{ local root_prefix=$1 treeish=$2 gitdir=$3 local -A m [ -n "$gitdir" ] || gitdir=$(git rev-parse --git-dir) if get_submodules m "$treeish" "$gitdir"; then local name for name in "${!m[@]}"; do local sm_path=${m[$name]} local sm_hash=$(git --git-dir "$gitdir" rev-parse "$treeish:$sm_path") local sm_gitdir="$gitdir/modules/$name" local prefix="$root_prefix$sm_path/" if ! git rev-parse --resolve-git-dir "$sm_gitdir" > /dev/null 2>&1; then cat <<-EOF Submodule '$name' git directory '$sm_gitdir' is not a git repository. This probably means that the submodule has not yet been initialised and cloned into the superproject working directory. Aborting the export so this can be resolved. EOF exit 1 fi echo "git archive exporting submodule $sm_gitdir:$sm_hash to $prefix" git --git-dir "$sm_gitdir" archive --format=tar --prefix="$prefix" "$sm_hash" | tar -C "$DEB_DIR" -xf - export_submodules "$prefix" "$sm_hash" "$sm_gitdir" done fi } #}}} export_debian_tree() { #{{{ # We do this before the initial export in case the user wants to bail out # at the prompt, so that we won't have junk from half an export to clean up. want_submodules "$1" || true echo "git archive exporting $1" git archive --format=tar --prefix="gitpkg-${1}/" "$1" | ( mkdir -p "$DEB_DIR" tar -C "$DEB_DIR" -xf - [ "$EXPORT_SUBMODULES" = "false" ] || export_submodules "gitpkg-${1}/" "$1" ) || exit 1 # We don't do this from the subshell so that it's still visible to EXIT_HOOK [ -n "$PRE_EXPORT_HOOK" ] || get_deb_version "$DEB_DIR/gitpkg-$1" if [ -z "$DEB_SOURCE" ] || [ -z "$DEB_VERSION" ]; then rm -rf "$DEB_DIR/gitpkg-$1" echo "ERROR: Failed to parse debian/changelog" 1>&2 exit 1 fi echo "preparing $DEB_DIR/$DEB_SOURCE/$DEB_PACKAGE" ( cd "$DEB_DIR" [ -e "$DEB_SOURCE/$DEB_PACKAGE" ] && rm -rf "$DEB_SOURCE/$DEB_PACKAGE" mkdir -p "$DEB_SOURCE" mv "gitpkg-$1" "$DEB_SOURCE/$DEB_PACKAGE" cd "$DEB_SOURCE/$DEB_PACKAGE" if [ -n "$DEB_EXPORT_HOOK" ] && ! ( . "$DEB_EXPORT_HOOK" ); then echo "ERROR: deb-export-hook '$DEB_EXPORT_HOOK' failed" 1>&2 echo " in: $DEB_DIR/$DEB_SOURCE/$DEB_PACKAGE" 1>&2 exit 1 fi if [ -n "$PREBUILD_TARGET" ]; then echo "$BUILD_ROOTCMD debian/rules $PREBUILD_TARGET" $BUILD_ROOTCMD debian/rules $PREBUILD_TARGET fi ) || exit 1 } #}}} format3_lameness() { #{{{ if [ "$ORIG_COMPRESSOR" != "gzip" ] || [ "${DEB_COMPRESSOR:-gzip}" != "gzip" ] || grep -q "^3\.0" "$DEB_PACKAGE/debian/source/format" 2>/dev/null; then echo "dpkg-source" "${DPKG_SOURCE_OPTS[@]}" "-b $DEB_PACKAGE" dpkg-source "${DPKG_SOURCE_OPTS[@]}" -b "$DEB_PACKAGE" || exit 1 else return 1 fi } #}}} build_with_existing_orig_tarball() { #{{{ if ! format3_lameness; then echo "dpkg-source" "${DPKG_SOURCE_OPTS[@]}" "-b -sp $DEB_PACKAGE" dpkg-source "${DPKG_SOURCE_OPTS[@]}" -b -sp "$DEB_PACKAGE" fi } #}}} build_native_package() { #{{{ if ! format3_lameness; then echo "dpkg-source" "${DPKG_SOURCE_OPTS[@]}" "-b -sn $DEB_PACKAGE" dpkg-source "${DPKG_SOURCE_OPTS[@]}" -b -sn "$DEB_PACKAGE" fi } #}}} build_with_exported_orig() { #{{{ # We build this ourselves and use -ss rather than -sR because dpkg-source # handles making tarballs badly anyhow and will leave the .orig suffix # in the path inside them. echo "tar cf - $DEB_PACKAGE(.orig) | $ORIG_COMPRESSOR" "${ORIG_COMPRESS_OPTS[@]}" "> $DEB_ORIG" tar --transform "s,^$DEB_PACKAGE.orig,$DEB_PACKAGE," \ -cf - "$DEB_PACKAGE.orig" | $ORIG_COMPRESSOR "${ORIG_COMPRESS_OPTS[@]}" > "$DEB_ORIG" if ! format3_lameness; then echo "dpkg-source" "${DPKG_SOURCE_OPTS[@]}" "-b -ss $DEB_PACKAGE" dpkg-source "${DPKG_SOURCE_OPTS[@]}" -b -ss "$DEB_PACKAGE" fi rm -rf "$DEB_PACKAGE.orig" } #}}} build_with_faked_orig() { #{{{ if [ "$CREATE_FAKE_ORIG" != "true" ]; then cat <<-EOF The package you are exporting has a Debian version, but there is no $DEB_ORIG already present and you did not provide a treeish to export one from. EOF if [ "$CREATE_FAKE_ORIG" = "false" ]; then rm -rf "$DEB_PACKAGE" exit 1 fi cat <<-EOF We can fake one up from everything but the debian/ directory if you would like, but this may not be what you had originally intended. You have exported '$GITPKG_TREEISH'. EOF printf "Fake a $DEB_ORIG from that (y/N)? " read -e yesno case $yesno in Y* | y*) cat <<-EOF Ok then. If you plan to make a habit of this you may wish to set: git config gitpkg.create-fake-orig 'true' To avoid being asked about it again each time. EOF ;; *) cat <<-EOF Yeah, good call. To avoid being asked about this again you can set git config gitpkg.create-fake-orig 'false' then in future this will simply print an error and fail. EOF rm -rf "$DEB_PACKAGE" exit 1 ;; esac fi [ -e "$DEB_PACKAGE.orig" ] && rm -rf "$DEB_PACKAGE.orig" cp -al "$DEB_PACKAGE" "$DEB_PACKAGE.orig" rm -rf "$DEB_PACKAGE.orig/debian" build_with_exported_orig } #}}} do_exit() { #{{{ if [ -n "$EXIT_HOOK" ] && ! ( cd "$DEB_DIR/$DEB_SOURCE" && . "$EXIT_HOOK" ); then echo "ERROR: gitpkg.exit-hook '$EXIT_HOOK' failed" 1>&2 exit 1 fi if [ "$1" == "0" ] && [ "$KEEP_UNPACKED_SOURCE" != "true" ]; then if [ -e "$DEB_DIR/$DEB_SOURCE/$DEB_PACKAGE/debian/control" ]; then echo "rm -rf $DEB_DIR/$DEB_SOURCE/$DEB_PACKAGE" rm -rf "$DEB_DIR/$DEB_SOURCE/$DEB_PACKAGE" fi fi printf "$EXIT_MSG" exit $1 } #}}} # Ok, if we're still here, let's reap what they've sown. if [ -z "$GITPKG_ORIG_TREEISH" ]; then export_debian_tree "$GITPKG_TREEISH" ( cd "$DEB_DIR/$DEB_SOURCE" case $DEB_VERSION in (*-*) if [ -e "$DEB_ORIG" ]; then build_with_existing_orig_tarball else build_with_faked_orig fi ;; (*) build_native_package ;; esac ) || exit 1 else export_debian_tree "$GITPKG_TREEISH" # Check that get_deb_version really did find a debian version number if [ -z "$DEB_ORIG" ]; then cat <<-EOF You have requested an orig tarball to be exported from '$GITPKG_ORIG_TREEISH', but the debian source from '$GITPKG_TREEISH' does not have a debian version in the changelog (version '$DEB_VERSION' was found). If this is really a native package, you probably want to call gitpkg with just a single treeish. If it is not, now might be a good time to fix the changelog entry to include a debian version part. Stopping here until that is sorted out. EOF exit 1 fi # Check for an existing orig.tar.gz and what to do if we have one ... if [ -e "$DEB_DIR/$DEB_SOURCE/$DEB_ORIG" ] then if [ "$FORCE_OVERWRITE_ORIG" = "true" ]; then echo "Overwriting existing $DEB_DIR/$DEB_SOURCE/$DEB_ORIG" else cat <<-EOF You have requested '$GITPKG_ORIG_TREEISH' be exported, but $DEB_ORIG is already present. EOF if [ "$FORCE_OVERWRITE_ORIG" = "false" ]; then rm -rf "$DEB_DIR/$DEB_SOURCE/$DEB_PACKAGE" exit 1 fi printf "Overwrite the existing orig with this repo export (y/N)? " read -e yesno case $yesno in Y* | y*) cat <<-EOF Ok then. If you plan to make a habit of this you may wish to set: git config gitpkg.force-overwrite-orig 'true' To avoid being asked about it again each time. EOF ;; *) printf "Using the existing $DEB_ORIG, that's probably smart.\n\n" ( cd "$DEB_DIR/$DEB_SOURCE" build_with_existing_orig_tarball ) || exit 1 # All done! do_exit 0 ;; esac fi fi # else check out the requested pristine upstream branch now too if want_submodules "$GITPKG_ORIG_TREEISH" || [ -n "$ORIG_EXPORT_HOOK" ]; then [ -e "$DEB_DIR/$DEB_SOURCE/$DEB_PACKAGE.orig" ] && rm -rf "$DEB_DIR/$DEB_SOURCE/$DEB_PACKAGE.orig" echo "git archive exporting $GITPKG_ORIG_TREEISH to $DEB_PACKAGE.orig/" git archive --format=tar --prefix="$DEB_SOURCE/$DEB_PACKAGE.orig/" "$GITPKG_ORIG_TREEISH" | ( tar -C "$DEB_DIR" -xf - [ "$EXPORT_SUBMODULES" = "false" ] || export_submodules "$DEB_SOURCE/$DEB_PACKAGE.orig/" "$GITPKG_ORIG_TREEISH" if [ -n "$ORIG_EXPORT_HOOK" ]; then ( cd "$DEB_DIR/$DEB_SOURCE/$DEB_PACKAGE.orig" if ! ( . "$ORIG_EXPORT_HOOK" ); then echo "ERROR: orig-export-hook '$ORIG_EXPORT_HOOK' failed" 1>&2 echo " in: $DEB_DIR/$DEB_SOURCE/$DEB_PACKAGE.orig" 1>&2 exit 1 fi ) || exit 1 fi cd "$DEB_DIR/$DEB_SOURCE" build_with_exported_orig ) || exit 1 else echo "git archive --prefix=$DEB_PACKAGE/ $GITPKG_ORIG_TREEISH" \ "| $ORIG_COMPRESSOR" "${ORIG_COMPRESS_OPTS[@]}" "> $DEB_ORIG" git archive --format=tar --prefix="$DEB_PACKAGE/" "$GITPKG_ORIG_TREEISH" | $ORIG_COMPRESSOR "${ORIG_COMPRESS_OPTS[@]}" > "$DEB_DIR/$DEB_SOURCE/$DEB_ORIG" ( cd "$DEB_DIR/$DEB_SOURCE" build_with_existing_orig_tarball ) || exit 1 fi fi do_exit 0 # vi:sts=4:sw=4:noet:foldmethod=marker gitpkg-0.31/gitpkg.10000644000000000000000000014125314505757621011201 0ustar .\" Hey, EMACS: -*- nroff -*- .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) .TH GITPKG 1 "September 29, 2023" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME gitpkg \- export a Debian source package from nominated git revisions .SH SYNOPSIS .B gitpkg .I branch .RI [ origbranch ] .SH DESCRIPTION If \fBgitpkg\fP is run in a \fBgit\fP(1) repo with a single 'branch' specified, then it will do a \fBgit\-archive\fP export of that branch to the \fBDEB_DIR\fP directory. If the package is Debian native it will simply create a source package from it. If the package has a Debian version, then an orig tarball will be expected to already exist for it. If an orig tarball does not already exist then what happens next depends on the value of the \%\fBgitpkg.create\-fake\-orig\fP configuration option (described below). If \fBgitpkg\fP is invoked with two branches specified, then the first branch will be exported as the unpacked complete source, while the second branch will be exported for the orig.tar.gz. This allows all local changes to the source to be recorded in the resulting diff.gz if a pristine upstream branch exists in the repository. If an orig tarball already exists for the version at 'branch' then what happens next depends on the value of the \%\fBgitpkg.force\-overwrite\-orig\fP configuration option (described below). The '\fIbranch\fP' should always have a \fIdebian\fP/ dir and may be any \fItree-ish\fP object that is accepted by \fBgit\-archive\fP(1). The '\fIorigbranch\fP', if supplied, should usually not have a \fIdebian\fP/ dir. .SH CONFIGURATION OPTIONS Almost all \fBgitpkg\fP configuration is handled using \fBgit\-config\fP(1) now. The following configuration options are supported: .TP .B gitpkg.deb\-dir May be set to override the default destination directory for exported packages. Default is '\fI../deb\-packages\fP'. Available to hook scripts as .nh .BR DEB_DIR . .hy This may be overridden on the command line with the .nh .BI \-\-deb\-dir= path .hy option. .TP .B gitpkg.build\-rootcmd May be set to override the default command used to get root for package build operations. Default is '\fIfakeroot\fP'. Available to hook scripts as .nh .BR BUILD_ROOTCMD . .hy .TP .B gitpkg.prebuild\-target May be set to a target or targets from \fIdebian/rules\fP which will be called after the debian source tree is exported, but before the source package is built. Some packages may use this to generate autoconf files or the like, which should generally not be in the repo, but which should be in the distributed package. The target is invoked using the BUILD_ROOTCMD. A common use for this hook would be to call the package's '\fIclean\fP' target. This hook is unset by default since gitpkg 0.18. Previous to that it defaulted to the clean target. Available to hook scripts as .nh .BR PREBUILD_TARGET . .hy .TP .B gitpkg.export\-submodules If a git repository contains submodules, then the submodule managed directories will not be automatically exported by \fBgit\-archive\fP(1), so if we want them in the exported source package then we need to jump through some extra hoops to export the source from each and every submodule too. Since this may not be the correct action for every "superproject" repository (especially since \fBgitpkg\fP has historically just ignored submodules prior to the 0.31 release) the option to export submodules must be explicitly enabled. If this option is set to 'true', then we will recursively export all submodules in the selected superproject revisions. If it is set to 'false', they will be treated as they were prior to \fBgitpkg\ 0.31\fP and silently ignored. If this option is not set and there are submodules present in the revisions being exported, then the user will be prompted for the correct action to take. At present this is an all or nothing selection, there is no way to selectively exclude only certain submodules from export, but if anyone ever has a real repo where that is the desired action then it should not be a difficult feature to add. As with everything git though, the range of possible use cases makes it folly to prematurely 'support' straw man use cases, and we should wait to see what other problems real use cases actually need solved. Note that in a repo with submodules \fBgitpkg\fP \fImust\fP be run from a directory that is directly managed by the superproject, not one that belongs to a submodule. Any \fBgit\fP commands run in directories that are managed by submodules will use the configuration for, and act on, only that submodule \- and it is almost impossible to know or be sure which (of possibly many) containing superproject is the one the user really wanted to export. See the details of the \fBgitpkg.allow\-subproject\-export\fP option below for more on this. Available to hook scripts as .nh .BR EXPORT_SUBMODULES . .hy .TP .B gitpkg.allow\-subproject\-export If \fBgitpkg\fP is invoked from a working directory that is managed by some submodule of a superproject then all \fBgit\fP commands will operate on the submodule, not on its containing superproject \- and it is almost impossible for us to know for sure whether the user has done this accidentally, intending to export the superproject, or deliberately, intending to export just the submodule package separately from the superproject it is a part of... So if we detect that \fBgitpkg\fP is invoked from a directory which is managed by a submodule then we need the user to tell us what they really wanted to do, and we can't rely on the treeish selected for export to be in any way persistently unique to just a single repo somewhere in the superproject tree. If this option is not set, the user will be prompted to confirm whether they really intended to export just the submodule, with the option to abort and instead run \fBgitpkg\fP from the desired superproject. If this option is set to 'true', then we will trust the user understands what they were doing, knows which subproject repo they invoked \fBgitpkg\fP in, and intends to export just that submodule (and possibly any other submodules that it in turn is a superproject for). And if they ever get that wrong, they get to keep all the pieces. If this option is set to 'false', then we will consider it to always be an error to try and directly export the submodule it is set for and immediately fail out. Note that it \fImust\fP be set in the submodule configuration, as the superproject configuration will not be read. In theory we could make this option indicate the root of the superproject that should be exported, but that just replaces an 'obvious' failure mode with a somewhat more insidious one that assumes an immutable relationship between them, with a silent awkward failure if that ever changes. If some subproject really can or should be exported as a package independently of the superproject it is a submodule of, then best practice is probably to be exporting it (and actively working on it) from its own independent working directory, with only selected versions checked out for read-only use as a submodule. Especially in the case of Debian packages, where managing them as a submodule of a superproject would mean that you have \fIdebian\fP directories and control files nested in the superproject source. Available to hook scripts as .nh .BR ALLOW_SUBPROJECT_EXPORT . .hy Though it's probably of little use to them, as it won't be set unless we are running in a submodule, and none of them will be run before the usual decision to abort execution. .TP .B gitpkg.orig\-compressor May be set to override the default compression for an exported package.orig.tar. Default is '\fIgzip\fP'. For format 3.0 packages, valid values also include \fIxz\fP and \fIbzip2\fP. Available to hook scripts as .nh .BR ORIG_COMPRESSOR . .hy .TP .B gitpkg.orig\-compress\-level An optional compression level to use with \fBgitpkg.orig\-compressor\fP. 1 is usually the fastest and 9 is usually the smallest, with the precise details of everything between being up to the chosen compressor. Default is unset (which will use whatever the compressor default is). Available to hook scripts as .nh .BR ORIG_COMPRESS_LEVEL . .hy .PP .B gitpkg.orig\-gz\-opts .br .B gitpkg.orig\-xz\-opts .br .B gitpkg.orig\-bz2\-opts .br .RS May be set to pass arbitrary options verbatim to \fIgzip\fP, \fIxz\fP or \fIbzip2\fP when compressing the orig tarball. If not specified explicitly, \%\fBgitpkg.orig\-gz\-opts\fP will default to include the \fB\-\-no\-name\fP option so that no timestamp is included in the resulting file, making the output reproducible. No default options are used for the other compressors. To pass multiple options to a compressor you must set this option for it multiple times (ie. using \fBgit\ config\ \-\-add\fP for each option to use). .RE .TP .B gitpkg.deb\-compressor May be set to override the default compression used by \%\fBdpkg\-source\fP(1) for exported packages. Default (if unset) is to use whatever \fBdpkg\-source\fP wants to use. For format 3.0 packages, valid values also include \fIxz\fP and \fIbzip2\fP. Available to hook scripts as .nh .BR DEB_COMPRESSOR . .hy .TP .B gitpkg.deb\-compress\-level An optional compression level to use with \fBgitpkg.deb\-compressor\fP. 1 is usually the fastest and 9 is usually the smallest, with the precise details of everything between being up to the chosen compressor. Default is unset (which will use whatever the \%\fBdpkg\-source\fP default is, currently '9'). Available to hook scripts as .nh .BR DEB_COMPRESS_LEVEL . .hy .TP .B gitpkg.dpkg\-source May be set to pass arbitrary options verbatim to \fBdpkg\-source\fP(1) when building the source package. Use with caution and at your own risk. To pass multiple options to \fBdpkg\-source\fP you must set this option multiple times (ie. using \fBgit\ config\ \-\-add\fP for each option) due to the otherwise amusing quoting requirements for options such as \%"\-\-format=3.0\ (native)". Default is empty. Available to hook scripts as the indexed array .nh .BR DPKG_SOURCE_OPTS . .hy Do not use this to set the \%\fBdpkg\-source\fP(1) \fB\-Z\fP or \fB\-z\fP options, they should instead be set using the \fBdeb\-compressor\fP and \%\fBdeb\-compress\-level\fP options respectively. This may be overridden on the command line with the .nh .BI \-\-dpkg\-source= arg .hy option, which likewise must be passed multiple times to set multiple options. .TP .B gitpkg.create\-fake\-orig Sometimes both upstream source and debian support really are intermingled into a single branch of the repo but you'd still like to make a 'non-native' package from it. \fBgitpkg\fP can fake an orig tarball from such a tree out of everything but the contents of the debian/ directory. Setting this option to 'true' makes that behaviour the default if a single treeish is passed to \fBgitpkg\fP and no corresponding orig tarball is found. Setting this option to 'false' will make \fBgitpkg\fP fail, reporting an error, if a single treeish is passed and no orig tarball with the correct version already exists for it (and none was retrieved by a hook script prior to it being needed). If this option is unset then the user will be prompted for the correct thing to do if this situation arises. Default is unset. Available to hook scripts as .nh .BR CREATE_FAKE_ORIG . .hy .TP .B gitpkg.force\-overwrite\-orig This option controls the behaviour of \fBgitpkg\fP if an 'origbranch' treeish is specified and the corresponding orig.tar for the 'branch' already exists. If this is set to 'true', then the orig.tar will be overwritten with the repo source (to reuse an existing orig.tar simply call \fBgitpkg\fP with only the single debian 'branch' treeish you wish to export). If this is set to 'false', then it is a hard error to attempt to export the upstream source again when the orig.tar already exists, and \fBgitpkg\fP will terminate and scold you if you try. If unset you will be prompted about whether to overwrite it or not, and the build will continue using whichever of the two you selected. Default is unset. Available to hook scripts as .nh .BR FORCE_OVERWRITE_ORIG . .hy .TP .B gitpkg.keep\-unpacked\-source This option controls whether or not the unpacked source directory is kept after the package export and exit hook have successfully completed. If this is set to 'true', the unpacked source will be retained. If set to 'false' or unset then that directory will be removed as the final operation before \fBgitpkg\fP exits if all prior operations completed successfully. Default is unset. Available to hook scripts as .nh .BR KEEP_UNPACKED_SOURCE . .hy This may be overridden on the command line with the .nh .BI \-\-keep\-unpacked\-source= bool .hy option (where 'no' or 'false' will not keep it, and any other value, including nothing, will). .SH SCRIPT HOOKS User defined scripts can be invoked from a number of points during the package build process. They are sourced into \fBgitpkg\fP as bash shell snippets, in most cases in a subshell, so they can read state variables and perform external actions, but cannot alter the running configuration once a build is in progress. If a hook returns with a non-zero status, then \fBgitpkg\fP will be terminated. (Hooks that do terminate gitpkg should take some care not to leave too much of a mess, but also should leave enough clues intact for the user to diagnose and fix whatever the problem was. Useful and informative error messages should be barked to stderr before exiting in this way.) Hook scripts may be installed on the host system outside of the repo tree, or sourced from version controlled files in the repo itself. Both methods have advantages and risks for different use cases. Hook scripts are activated by the local admin, by setting each relevant \fBgit\-config\fP(1) option with the path to the script to be executed. Paths may be absolute or relative to the directory which that hook is called from. If a hook is set, the script \fBmust\fP exist when it is called. Care should be taken to only enable them for use by trusted source trees when hooking into files in the repo itself. Usually you should enable them on a per-repo basis with \fBgit\-config\fP(1) rather than at a \fB\-\-global\fP or \fB\-\-system\fP level. .SS A brief admonition against getting hooked: You should avoid complicated in-package hook arrangements becoming essential for exporting your package source. If you need them to create a particular package correctly, and need strict version binding with the source being released, and they aren't useful to any other package at all ... then you're quite probably doing something, or several things, quite wrong. Else you're in such deep shit working around some broken build system that you don't need me to tell you about it. Either way, local admin has to enable your hooks before they can run, so if you want to be friendly to others (and yourself), then keep the 'normal' packaging work strictly inside the usual package building tools, and leave the gitpkg hooks free for other local admins to wrap whatever automation it is \fIthey\fP need around things. If a particular version of the package source needs some particular actions performed on it prior to the first source package build, then the .B PREBUILD_TARGET option from above is most probably what you want rather than one of these hooks. Other people can use that again later without needing to have gitpkg around. The aim is for this to Help You. For some values of All Of You. So do be careful to avoid letting it screw other people over if the hook isn't called, and/or let them know what they need to do instead if it isn't. Ok then, there's the barb to watch out for, so back to the point again: .SS Hook points The available hook points are listed below in roughly the order that they would usually be invoked: .TP .B gitpkg.package\-config\-hook This hook runs in the top level directory of the repo \fBgitpkg\fP was invoked in, prior to any operations taking place, with all \fBgit\-config\fP(1) sourced options available to it. No detailed information about the package itself is available in the hook environment yet, not even its name or version, only the tree-ish(es) that \fBgitpkg\fP was passed by the user, but the hook may run its own self-checks based on the current (possibly 'dirty') contents of the working tree that \fBgitpkg\fP was invoked in. This hook is able to modify the \fBgitpkg\fP configuration variables for subsequent operations. It can perform operations on the repo if needed, but since it needs to be committed to the repo before it will ever be called, that may not be so useful here in practice. Basically, it can do anything it pleases, it's just a shell script, nothing else has really begun yet, and it has been sourced into the topmost shell level of \fBgitpkg\fP. Its operation is different from the \fBadmin\-config\-hook\fP in only one respect, the path to this hook \fBmust\fP be relative to the TLD of the repo, and the revision of the file that will be sourced is checked out from the 'branch' tree-ish that \fBgitpkg\fP was requested to export. The file must exist in that version at the path given. Available to hook scripts as .nh .BR PACKAGE_CONFIG_HOOK . .hy .TP .B gitpkg.admin\-config\-hook This hook is run after the \fBpackage\-config\-hook\fP returns, and differs from it in operation only by reading a static file from the current filesystem rather than extracting a version controlled one from the repo being exported. This can be used by the local admin to override any package specific options, that may have been set by the \fBpackage\-config\-hook\fP, with site specific configuration. This is a policy control, not a security one. Security was all over when you let the \fBpackage\-config\-hook\fP run, this just lets you override it without having to fake up a new commit changing the package hook. This is the last hook to run that is able to modify the \fBgitpkg\fP configuration and set environment options that will be visible to later hooks. Available to hook scripts as .nh .BR ADMIN_CONFIG_HOOK . .hy This may be overridden on the command line with the .nh .BI \-\-admin\-config\-hook= path .hy option. .TP .B gitpkg.pre\-export\-hook This hook runs in the top level directory of the repo, after the package name and version have been determined, and with the final package configuration including any tweaking by the previous hooks. It cannot alter any configuration options, only act upon them or terminate \fBgitpkg\fP. This can be used to do things like invoke pristine\-tar or prefetch an existing orig tarball from some foreign source. It may perform operations on the repo if any such are desired, or any other last minute check that needs to be done before we actually get about the task of exporting the source we want packaged. Available to hook scripts as .nh .BR PRE_EXPORT_HOOK . .hy .TP .B gitpkg.deb\-export\-hook This hook runs in the top level directory of the exported debian source, immediately after the source has been exported from the requested \fItree-ish\fP, and immediately prior to the \fBPREBUILD_TARGET\fP being invoked (if provided). It cannot alter any configuration options, only act upon them or terminate \fBgitpkg\fP. If this hook terminates \fBgitpkg\fP, the exported source directory will be left on the system for the user to inspect. Subsequent invocations of \fBgitpkg\fP for the same release version will overwrite it though. Available to hook scripts as .nh .BR DEB_EXPORT_HOOK . .hy .TP .B gitpkg.orig\-export\-hook This hook runs in the top level directory of the exported 'upstream' source, immediately after the source has been exported from the provided \fItree-ish\fP, and prior to it being compressed into a tarball. It cannot alter any configuration options, only act upon them or terminate \fBgitpkg\fP. If this hook terminates \fBgitpkg\fP, the exported source directory will be left on the system for the user to inspect. Subsequent invocations of \fBgitpkg\fP for the same release version will overwrite it though. This hook is \fBonly\fP invoked if the upstream 'origbranch' actually is exported from the repository. If an existing orig.tar is found or has been created by some earlier hook (and it is not being overwritten, see \fBforce\-overwrite\-orig\fP above), then the operations this hook would perform are presumed to have already happened for this tarball and it is skipped. It is not safe to assume that this hook will be executed before or after \fBdeb\-export\-hook\fP, and it may in fact be run in parallel with it at some point in the future. They both will be entered after \fBpre\-export\-hook\fP returns, and \fBexit\-hook\fP will not begin until (at least) after both have returned. What else happens in the middle of all that we make no firm promises about at this stage. Available to hook scripts as .nh .BR ORIG_EXPORT_HOOK . .hy .TP .B gitpkg.exit\-hook This hook runs in the directory where the package \fI.dsc\fP was deposited by \fBdpkg\-source\fP(1), after all internal \fBgitpkg\fP operations have successfully completed. It's too late to alter any configuration options, or even to terminate \fBgitpkg\fP really. You can pretty much do what you like from this one, anything that goes wrong from here on is your own doing. Available to hook scripts as .nh .BR EXIT_HOOK . .hy This may be overridden on the command line with the .nh .BI \-\-exit\-hook= path .hy option. .SS Hook Environment The following variables are made available for hook scripts, in addition to those already listed as shadowing a \fBgit\-config\fP option from above. Not all of them are valid/useful at all hook points, see the hook documentation above for the exceptions applying to specific hooks. .TP 4 .B GITPKG_HOOK_API Permits hook scripts to query what interfaces are available to them. Has only two numeric components separated by a '.' of which the number to the right of point will get incremented every time we add some new variable a hook might access, or add some new knob it might tweak where existing interfaces have not have changed. If we do screw up and need to change some current interface, the number to the left will get bumped. The current API version is 0.3 .SS Available in API version 0.1 These variables have been available to hooks since gitpkg version 0.13 .TP 4 .B GITPKG_TREEISH The user-passed debian 'branch' tree-ish that gitpkg was invoked to export. .TP .B GITPKG_ORIG_TREEISH The 'origbranch' tree-ish that gitpkg was invoked with. This will be empty if only a single 'branch' tree-ish was specified. .TP .B DEB_SOURCE The name of the source package to create, without any versioning. As seen in the Source: field of \fBdpkg\-parsechangelog\fP(1). .TP .B DEB_VERSION The version of the source package to create, without any epoch. As seen in the name of the .diff.gz and .dsc files. .TP .B UPSTREAM_VERSION The version of the source package to create, without any debian version. As seen in the name of the orig tarball. For native packages this will be the same as \fBDEB_VERSION\fP. .TP .B DEB_ORIG The full versioned filename of the orig tarball to use or create. This variable is empty for native packages without a Debian version part. .TP .B DEB_DSC The full filename of the package \fI.dsc\fP that will be or has been created. .TP .B DEB_PACKAGE The directory name of the debianised source tree to pass to \fBdpkg\-source\fP(1). .TP .B REPO_DIR An absolute path to the top level directory of the git repo we are exporting from. Usually, if you need to look out of the tree that you were dropped in, you're probably doing something (at the) wrong (time), but there are exceptions, and being able to query \fBgit\-config\fP options is one of them. That's mostly what this one is for right now. See the \fBrepo\-config\-helper\fP documented below. Be careful if you do use it for much else. .SS Available in API version 0.2 These variables have been available to hooks since gitpkg version 0.24 .TP 4 .B GITPKG_AOPTS An associative array containing the command line options not parsed by \fBgitpkg\fP itself which can be used to override the behaviour of a hook. The array is keyed on the names of the options with the '\-\-' removed. If an option was passed multiple times, only the last value passed will be stored in this array. For example: .nh .nf $ gitpkg \-\-my\-option=foo \-\-option2 \-\-opt=oops \-\-opt='bar baz' Will give: ${GITPKG_AOPTS[my-option]} = 'foo' ${GITPKG_AOPTS[option2]} = '' ${GITPKG_AOPTS[opt]} = 'bar baz' .fi .hy .TP .B GITPKG_IOPTS An indexed array containing the command line options not parsed by \fBgitpkg\fP itself which can be used to override the behaviour of a hook. The array contains the literal option strings passed and so can be used to access options which are intended to be passed multiple times. For example: .nh .nf $ gitpkg \-\-my\-option=foo \-\-option2 \-\-opt=oops \-\-opt='bar baz' Will give: ${GITPKG_IOPTS[0]} = '\-\-my\-option=foo' ${GITPKG_IOPTS[1]} = '\-\-option2' ${GITPKG_IOPTS[2]} = '\-\-opt=oops' ${GITPKG_IOPTS[3]} = '\-\-opt=bar baz' .fi .hy There are convenience functions in \fBrepo\-config\-helper\fP (see below for details) which can be used to inspect this array and obtain all the value(s) for a specific option. .SS Available in API version 0.3 A range of new support functions were added to \fBrepo\-config\-helper\fP in gitpkg version 0.30 .RS 2 - require_bash_version() .br - trim_array() - have_commandline_option() .br - have_any_of_these_commandline_options() - extract_values_for() .br - extract_value_for() .br - extract_bool_for() - get_option_values() .br - get_option_value() .br - get_bool_value() .RE These are described in more detail in the \fBHook Library Helpers\fP section below. .SS Hook Library There are some canned hook scripts for various tasks available in .I /usr/share/gitpkg/hooks which currently include: .TP 4 .B cowpoke\-exit\-hook A simple exit hook which sends the exported package off for building using .BR cowpoke (1). To enable it: .nh .nf $ git config gitpkg.exit\-hook /usr/share/gitpkg/hooks/cowpoke\-exit\-hook .fi .hy Additional \fBgit\-config\fP(1) configuration options: .RS .TP 4 .B gitpkg\-cowpoke\-exit\-hook.ask\-first If 'true' and no cowpoke\-specific command line option was passed, then prompt for confirmation before calling \%\fBcowpoke\fP. Use of a cowpoke option on the command-line is an implicit acknowledgement that the caller knows and intends that the exported source package will be sent to cowpoke to be built, and so will skip this confirmation nagging. Default is to just go ahead and do it if this hook is set. .TP .B gitpkg\-cowpoke\-exit\-hook.options May include any other options that you wish to pass verbatim to \%\fBcowpoke\fP(1). To pass multiple options, set this multiple times, once for each option. This may be overridden on the command line with the .nh .BI \-\-cowpoke= arg .hy option, which likewise must be passed multiple times to set multiple options. You can use \fB\-\-cowpoke=\fP (or equivalently, either \%\fB\-\-cowpoke\fP or \%\fB\-\-no\-cowpoke\fP) to override and clear all configured \%\fB.options\fP without needing to pass some arbitrary new one. This will not override any other \%\fB\-\-cowpoke=\fIarg\fR options which are passed on the command line. As a multi-valued option, all empty values which are passed for it will simply be ignored aside from causing the configuration file defaults to be ignored. .TP .B gitpkg\-cowpoke\-exit\-hook.arch The default Debian architecture(s) to build for. Setting this option to is equivalent to using .nh .BI \-\-arch= .hy in \%\fB.options\fP above, except using \fB\-\-arch\fP on the command line will only override any architectures set with this option, and .nh .BI \-\-cowpoke=\-\-arch= .hy will not override architectures set with this option. To build for multiple architectures set this (or use \fB\-\-arch\fP on the command line) multiple times, once for each . If no arch is set or passed on the command line it will default to whatever is configured in \fBcowpoke.conf\fP, which in turn will default to what \%\fBdpkg\-architecture\fP(1) returns for \fBDEB_BUILD_ARCH\fP on the machine that is running \fBgitpkg\fP. .TP .B gitpkg\-cowpoke\-exit\-hook.dist The default Debian distribution(s) to build for. Setting this option to is equivalent to using .nh .BI \-\-dist= .hy in \%\fB.options\fP above, except using \fB\-\-dist\fP on the command line will only override any distributions set with this option, and .nh .BI \-\-cowpoke=\-\-dist= .hy will not override distributions set with this option. To build for multiple distributions set this (or use \fB\-\-dist\fP on the command line) multiple times, once for each . If no dist is set or passed on the command line it will default to whatever is configured in \fBcowpoke.conf\fP, and if not set there it will default to whatever cowbuilder is locally configured for on the remote machine. The name used here may also be a locally defined identifier for any specially configured cowpoke chroot that is available, such as those set up for building backports or using extra packages only available from a local repository. See the \fBcowpoke\fP(1) description of its \fB\-\-dist\fP option for details of that. .TP .B gitpkg\-cowpoke\-exit\-hook.dpkg\-bp Additional options for use by \fBdpkg\-buildpackage\fP(1). Setting this option is equivalent to using .nh .BI \-\-dpkg\-bp= option .hy in \fB.options\fP above, except using \fB\-\-dpkg\-bp\fP on the command line will only override the configuration that was set with this option, and .nh .BI \-\-cowpoke=\-\-dpkg\-bp= option .hy will not override the configuration that is set with this option. To pass multiple options to \%\fBdpkg\-buildpackage\fP set this (or use \fB\-\-dpkg\-bp\fP on the command line) multiple times, once for each \fIoption\fP. These options will be appended to any that are specified in \fBDEBBUILDOPTS\fP in the build host's \fIpbuilderrc\fP. To clear any already preset options, first pass it with an empty argument (i.e. .BI "\-\-dpkg\-bp=\ \-\-dpkg\-bp=" option "\fR\ ...)." .TP .B gitpkg\-cowpoke\-exit\-hook.source\-changes If set to '\fBtrue\fP', '\fByes\fP', '\fBsigned\fP', or set without a value (or to an empty string), then it is equivalent to adding the \%\fBcowpoke\fP(1) option \%\fB\-\-sign\-source\-changes\fP to \fB.options\fP above, except it is independent of the options that would be overridden by \fB\-\-cowpoke\fP on the command line. The value \fBsigned\fP has no additional special effect for this hook, it is supported for equivalence with the values accepted for \fB.source\-changes\fP in the .nh .BR dpkg\-buildpackage\-exit\-hook . .hy If set to '\fBfalse\fP' or '\fBno\fP', it is the equivalent of adding the \fBcowpoke\fP(1) option .nh .BR \-\-no\-sign\-source\-changes . .hy The default if this option is not set at all is defer to \fBSIGN_SOURCE_CHANGES\fP in the \fBcowpoke.conf\fP, or if it is not set to the \fBpbuilder\fP(8) configuration \fBSOURCE_ONLY_CHANGES\fP setting. All other values passed with this option are an error. This setting may be overridden on the command line with .nh .BR \-\-sign\-source\-changes [ =\fIarg ] .hy where legal values for \fIarg\fP and their actions are the same as described above. Using \fB\-\-no\-sign\-source\-changes\fP has the equivalent effect to using .nh .BR \-\-sign\-source\-changes=no . .hy .TP .B gitpkg\-cowpoke\-exit\-hook.sign\-key May be set to the fingerprint of the key to sign packages with. This will override the \fBSIGN_KEYID\fP specified for a chroot in the cowpoke configuration files. If you use different keys to sign packages built in different chroots, then you should probably configure the signing key ID in \fBcowpoke.conf\fP instead, but for individual builds you can override it on the command line with the .BI \-\-sign= keyid option. The \fB\-\-no\-sign\fP option will cancel the use of any keyid that was set with \fB.sign\-key\fP in the git config, or by a previous command-line option, but this just means \fBgitpkg\fP will not pass a keyid to \fBcowpoke\fP, it does not override cowpoke's own configuration which may still specify a default key to use for the given arch/dist. To also override any \fBSIGN_KEYID\fP that is set in \%\fBcowpoke.conf\fP you can instead use \fB\-\-sign=\fP (with an empty argument), which will be passed through to cowpoke and clear the signing keyid, preventing cowpoke from offering the option of signing the packages after they are built. .TP .B gitpkg\-cowpoke\-exit\-hook.upload\-to The \fBdput\fP(1) \fIHOSTNAME\fP to upload packages to. This will override the \fBUPLOAD_QUEUE\fP specified for a chroot in the cowpoke configuration files. If you use different upload queues for packages built in different chroots, then you should configure this in \fBcowpoke.conf\fP instead, but for individual builds you can override the upload queue on the command line with the .nh .BI \-\-upload= queue .hy option. The \fB\-\-no\-upload\fP option will cancel the use of any upload queue that was set with \fB.upload\-to\fP in the git config, or by a previous command-line option, but this just means \fBgitpkg\fP will not pass an upload queue to \fBcowpoke\fP, it does not override cowpoke's own configuration which may still specify a default queue to use for the given arch/dist. To also override any \fBUPLOAD_QUEUE\fP that is set in \fBcowpoke.conf\fP you can instead use \fB\-\-upload=\fP (with an empty argument), which will be passed through to cowpoke and clear the upload queue, preventing cowpoke from offering the option of uploading the packages after they are signed. .TP .B gitpkg\-cowpoke\-exit\-hook.return\-dir This may be set to a filesystem path on the local host (absolute or relative to the directory which \fBgitpkg\fP(1) was invoked from) where the packages built by cowpoke will be copied to once the build is completed. It may be specified on (or overridden by) the command line with the .nh .BR \-\-return [ =\fIpath ] .hy option. If no path is specified, the (\fBcowpoke\fP) default is the current directory. The \fB\-\-no\-return\fP option will cancel a \fB.return\-dir\fP set in the git config, or by a previous command-line option, but this just means \fBgitpkg\fP will not pass a return dir to \fBcowpoke\fP, it does not override cowpoke's own configuration which may still specify a \fBRETURN_DIR\fP. Because \fBcowpoke\fP recognises \fB\-\-return\fP (with no value assignment) as a discrete option, to override and clear \%\fBRETURN_DIR\fP that is set in \fBcowpoke.conf\fP from here you must pass the empty assignment verbatim in the \fB.options\fP configuration, or on the command line with \fB\-\-cowpoke=\-\-return=\fP which will bypass the normal \fBgitpkg\fP handling of the \fB\-\-return\fP option. .RE .TP .B dpkg\-buildpackage\-exit\-hook A simple exit hook to build binary packages locally with .nh .BR dpkg\-buildpackage (1). .hy To enable it: .nh .nf $ git config gitpkg.exit\-hook /usr/share/gitpkg/hooks/dpkg\-buildpackage\-exit\-hook .fi .hy Additional \fBgit\-config\fP(1) configuration options: .RS .TP 4 .B gitpkg\-dpkg\-buildpackage\-exit\-hook.ask\-first If 'true' and no dpkg\-buildpackage\-specific command line option was passed, then prompt for confirmation before calling \%\fBdpkg\-buildpackage\fP. Use of a dpkg\-buildpackage option on the command-line is an implicit acknowledgement that the caller knows and intends that the exported source package will be built with \fBdpkg\-buildpackage\fP(1) and so will skip this confirmation nagging. Default is to just do it if this hook is set. .TP .B gitpkg\-dpkg\-buildpackage\-exit\-hook.options May include any other options that you wish to pass verbatim to \%\fBdpkg\-buildpackage\fP. To pass multiple options, set this multiple times, once for each option. This may be overridden on the command line with the .nh .BI \-\-dpkg\-bp= arg .hy option, which likewise must be passed multiple times to set multiple options. You can use \fB\-\-dpkg\-bp=\fP (or equivalently, either \%\fB\-\-dpkg\-bp\fP or \%\fB\-\-no\-dpkg\-bp\fP) to override and clear all configured \%\fB.options\fP without needing to pass some arbitrary new one. This will not override any other \%\fB\-\-dpkg\-bp=\fIarg\fR options which are passed on the command line. As a multi-valued option, all empty values which are passed for it will simply be ignored aside from causing the configuration file defaults to be ignored. .TP .B gitpkg\-dpkg\-buildpackage\-exit\-hook.source\-changes If '\fBtrue\fP' or '\fByes\fP' then a \fI_source.changes\fP file, suitable for a "source only" upload, will be generated (independently of any changes file that \%\fBdpkg\-buildpackage\fP creates according to the options passed to it). If the \fB\-uc\fP or \%\fB\-\-unsigned\-changes\fP option was passed to \%\fBdpkg\-buildpackage\fP then this changes file will not be signed either. If set to the special value '\fBsigned\fP' then the \%\fI_source.changes\fP file, and any \fB.dsc\fP or \fB.buildinfo\fP files referenced by it, will be signed regardless of any .BR \-uc ", " \-us ", " \-ui options being used to suppress signing of the files created by \%\fBdpkg\-buildpackage\fP. This makes it possible to do a full binary build, creating source and \fB.deb\fP files for inspection and testing, but then sign only the files needed to do a source only upload to another build farm. If set without a value (or to an empty string), then the behaviour is the same as if it was set to '\fBsigned\fP' and .nh .BI \-\-dpkg\-bp= \-uc "\ \-\-dpkg-bp=" \-us .hy were passed. i.e. Only the \%\fI_source.changes\fP file (and the files referenced by it) will be signed, not the binary files created by the build. This is probably what most people want when exporting a package with the intent of doing a "source only" upload. The default if unset is the same as setting this option to '\fBfalse\fP' or '\fBno\fP', no \fI_source.changes\fP file will be created by this hook and the behaviour is simply what would be expected from \%\fBdpkg\-buildpackage\fP(1) with any otherwise configured options passed to it. All other values passed with this option are an error. This setting may be overridden on the command line with .nh .BR \-\-sign\-source\-changes [ =\fIarg ] .hy where legal values for \fIarg\fP and their actions are the same as described above. Using \%\fB\-\-no\-sign\-source\-changes\fP has the equivalent effect to using .nh .BR \-\-sign\-source\-changes=no . .hy .TP .B gitpkg\-dpkg\-buildpackage\-exit\-hook.sign\-key May be set to the fingerprint of the key to use for signing exported and built package files. If not set then the signing key derived by (or set in other configuration for) \%\fBdpkg\-buildpackage\fP(1) will be used when signing binary changes files, with the defaults for \fBdebsign\fP(1) being used in the case where a "source only upload" changes is being signed. Since those two tools don't use the same configuration, that may not be the same key for all users on all machines, but we do respect and use \fBDEB_SIGN_KEYID\fP from the environment (if it is set with no other overriding configuration), when calling \fBdebsign\fP, as it would otherwise ignore that configuration option from \fBdpkg\-buildpackage\fP. The usual debsign default is instead \fBDEBSIGN_KEYID\fP and set in the \%\fBdevscripts.conf\fP file. You can override the signing key on the command line with the .BI \-\-sign= keyid option. The \fB\-\-no\-sign\fP option will cancel the use of any keyid that was set with \fB.sign\-key\fP in the git config, or by a previous command-line option, but this just means \fBgitpkg\fP will not pass a keyid to \%\fBdpkg\-buildpackage\fP(1) and it will revert to its own determination of what key should be used for signing. To actually not sign a package you'll want to use something like .nh .BI \-\-dpkg-bp= -uc " \-\-dpkg-bp=" -us \fR .hy to explicitly disable signing. .TP .B gitpkg\-dpkg\-buildpackage\-exit\-hook.build\-log If set 'false' don't save a log of the build process, the default is to record one. This may be overridden on the command line with the .BR \-\-build\-log [ =\fIbool-value "] or " \-\-no\-build\-log option. .RE .TP .B pristine\-tar\-pre\-export\-hook A hook to extract an orig tarball using pristine\-tar. Which orig to extract is determined by the package version of the 'branch' tree-ish. To enable it: .nh .nf $ git config gitpkg.pre\-export\-hook /usr/share/gitpkg/hooks/pristine\-tar\-pre\-export\-hook .fi .hy If a pristine\-tar branch is not found in the repo, then gitpkg will be terminated. .TP .B quilt\-patches\-deb\-export\-hook This hook reads a list of revision ranges suitable for \fBgit\-format\-patch\fP(1) from the file \fIdebian/source/git\-patches\fP, one per line, and exports them to the \fIdebian/patches\fP directory in a form suitable for (format 3.0) quilt packages. It is not required for creating such packages, but permits you to separate out individual patches however you please from the default single patch that is otherwise created by \fBdpkg\-source\fP. To enable it: .nh .nf $ git config gitpkg.deb\-export\-hook /usr/share/gitpkg/hooks/quilt\-patches\-deb\-export\-hook .fi .hy The contents of \fIdebian/source/git\-patches\fP may include comments (on any line beginning with a #), empty lines, and expressions of a range of commits. The revision ranges may include \fB$DEB_VERSION\fP, \fB$UPSTREAM_VERSION\fP, \fB$DEB_REF\fP or \fB$UPSTREAM_REF\fP. The first pair will be substituted with the version of the package being exported, the second pair with those version strings after mangling by \fBsanitise_git_ref\fP to remap them to a legal git \fIrefname\fP. Using the sanitised versions is to be preferred in most cases. For example: .nh .nf # Export all commits between these two treeishes, # based on the version of the package being exported. upstream/$UPSTREAM_REF..patches/$DEB_REF .fi .hy .TP .B debcherry\-deb\-export\-hook This hook invokes \fBgit\-debcherry\fP(1) to find and export patches to the upstream source in a form suitable for use with (format 3.0) quilt packages. It allows for a more natural (and automatic) workflow than the quilt\-patches hook above by searching for patches made to the packaging branch that have not yet been applied upstream. To enable it: .nh .nf $ git config gitpkg.deb\-export\-hook /usr/share/gitpkg/hooks/debcherry\-deb\-export\-hook .fi .hy In order to use this hook, a \fB${DEB_ORIG}.commit\fP file must be created which contains the treeish of the exported upstream source in the repository. This will be created automatically (if this hook is enabled) when you export an upstream tarball by passing both \fIbranch\fP and \fIorigbranch\fP to \fBgitpkg\fP, or if you use the \fBpristine\-tar\-pre\-export\-hook\fP, which determines an appropriate commit corresponding to the tarball. If your upstream tarball is created using some other mechanism you will need to ensure that file is created yourself. If using this hook, you may wish to document that in your repository with something similar to the text in \%\fI/usr/share/doc/\:gitpkg/\:examples/\:README.debcherry\-export\fP as a convenience to other users. Your package will still be exportable without this hook enabled, it just won't have the upstream patches individually separated out into a quilt series. .SS Hook Library Helpers These are additional shell code snippet files which are also found in \%\fI/usr/share/\:gitpkg/hooks\fP, for operations which may usefully be shared by several hook scripts. Usually these would be sourced by other scripts rather than being hooked to directly. .TP 4 .B repo\-config\-helper This file provides functions for querying configuration options which may be set in the project \fBgit\-config\fP, or overridden by command line arguments. .RS .TP 4 .B repo_config() Provides a simple wrapper around `\fBgit config\fP`, which ensures it is called from the repo tree where any repo-specific config options may be stored. Useful to scripts which aren't called from inside the repo tree, but which do have \fBgit\-config\fP(1) options of their own to query. .TP .B sanitise_git_ref() Remaps character strings that are illegal to use in a git refname. .TP .B require_bash_version() Allows a hook script to assert a minimum bash version needed to provide all the functionality its implementation requires. .TP .B trim_array() Removes all empty elements from an array. This can be useful for, among other things, filtering option values where an empty value should not propagate as an argument word. .TP .B have_commandline_option() A Simple true or false test of whether some \fB\-\-\fIoption\fR or its counterpart \%\fB\-\-no\-\fIoption\fR were passed on the command line, which evaluates to \fBfalse\fP if neither of them were. .TP .B have_any_of_these_commandline_options() Convenience function to call \fBhave_commandline_option\fP for multiple options, returning \fBtrue\fP if any of them were passed, or \fBfalse\fP if none of them were. .TP .B extract_values_for() This is a refinement of the older (and now deprecated) \%\fBextract_values_for_option()\fP function which is much cleaner to use, but depends on functionality that was introduced in \fBbash\fP version 4.3 (which has been available since Jessie, so it shouldn't practically limit backports of this \fBgitpkg\fP release). It is designed to query multi-valued command line options, filling an array with all of the values passed to \fBgitpkg\fP for some option which were recorded in \fBGITPKG_IOPTS\fP (or any similar array). .TP .B extract_value_for() More suited for single-valued options, this sets a variable to the value of the final overriding instance of a command line option. .TP .B extract_bool_for() Like \fBextract_value_for()\fP, but intended for options where all values are expected to be either true or false. .TP .B get_option_values() Fill a multi-valued array with optional hard-coded default values, overriding those defaults with a (multi-valued) configuration option from git-config, and overriding both of those if any values were passed for it on the command line. .TP .B get_option_value() Assign a single-valued variable with an optional hard-coded default value, overriding that default with a configuration option from git-config, and overriding both of those if a value was passed on the command line. .TP .B get_bool_value() Like \fBget_option_value()\fP except all values set are either true or false. .PP See the content of that file itself for more detailed documentation on these functions, their operation, and calling conventions. .RE .SH INTERACTIVIY If you intend to call \fBgitpkg\fP from your own scripts, then you should note that there are two situations when it may prompt interactively by default. There is no One True Sane Default for these cases, so it's better to just ask the user and continue than to make them start the whole process again in the likely case where they have called \%\fBgitpkg\fP directly. For details, see the \%\fBgitpkg.force\-overwrite\-orig\fP and \%\fBgitpkg.create\-fake\-orig\fP config options above. You should set both explicitly to the behaviour that you desire from them if \%\fBgitpkg\fP should never become interactive. .SH WORKFLOW Though \fBgitpkg\fP explicitly does not try to force any particular workflow procedure upon you in order to make full use of it, it probably is worth making quick mention of at least one simple way to manage Debian packages in git. One common repo structure is to keep pristine upstream source on one branch, which is updated either directly from an upstream repo or by importing tar archives to it periodically, with the Debian patched source on another branch. In this situation the task of preparing a new upstream release from a tarball might look a bit like this: Check out the upstream branch $ cd myrepo $ git checkout upstream Remove all old upstream files from the repo $ rm \-rf $(all_files_except .git) Unpack the new tarball in their place $ tar zxf $new_upstream.tar.gz Let git figure out what is renamed/new/gone by itself. Make sure you don't have things like vim .swp files lurking in the tree still at this point. $ git add . $ git commit \-a $ git tag v$upstream_version Prepare the Debian branch $ git checkout debian $ git merge upstream $ $(update changelog and other debian patches etc.) $ git commit \-a $ git tag v${upstream_version}\-$debian_version Make a release $ gitpkg v${upstream_version}\-$debian_version v$upstream_version $ cd ../deb\-packages/mypackage && dpkg\-buildpackage ... .SH SEE ALSO .nh .BR git\-debimport (1), .BR git\-debcherry (1), .BR git (1), .BR git\-archive (1), .BR git\-config (1), .BR git\-format\-patch (1), .BR gitattributes (5), .BR dpkg\-source (1), .BR cowpoke (1). .hy .SH AUTHOR .B gitpkg was written by Ron . gitpkg-0.31/gitpkg.bash_completion0000644000000000000000000000306114505757621014201 0ustar # -*- shell-script -*- # # Bash tab auto-completion rules for gitpkg # # Copyright © 2012 Stig Sandbeck Mathisen # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. _gitpkg() { if [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true" ]; then return 0 fi local cur options names COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" options='--help --version --deb-dir --admin-config-hook --exit-hook --keep-unpacked-source --dpkg-source --cowpoke --dpkg-bp' if [[ "${cur}" == -* ]]; then COMPREPLY=( $( compgen -W "${options}" -- "${cur}" ) ) else names=$( { git for-each-ref --format='%(refname:short)' refs/heads git for-each-ref --format='%(refname:short)' refs/tags } | sort -u ) COMPREPLY=( $( compgen -W "${names}" -- "${cur}" ) ) fi } && complete -F _gitpkg gitpkg gitpkg-0.31/hooks/0002755000000000000000000000000014505757621010751 5ustar gitpkg-0.31/hooks/cowpoke-exit-hook0000644000000000000000000000712614505757621014254 0ustar # gitpkg hook script to push the exported package off for building via cowpoke # # To enable this hook, use: # git config gitpkg.exit-hook /usr/share/gitpkg/hooks/cowpoke-exit-hook # We're out of the repo tree, but want to check git-config . /usr/share/gitpkg/hooks/repo-config-helper # We need bash 4.4 or later for the ${var@Q} parameter transformation, so check # and bail out here with a friendly warning instead of crashing obscurely later. require_bash_version 4.4 # The --sign-source-changes option is a bit special, as --no-sign-source-changes # is not just "don't pass this option", it's "pass a different option instead" # equivalent in this case to --sign-source-changes=no. get_option_value 'COWPOKE_SSC' 'sign-source-changes' \ 'gitpkg-cowpoke-exit-hook.source-changes' 'notset' EXTRA_COWPOKE_OPTS=() case ${COWPOKE_SSC-unset} in ""|true|yes|signed) EXTRA_COWPOKE_OPTS+=( '--sign-source-changes' ) ;; unset|false|no) EXTRA_COWPOKE_OPTS+=( '--no-sign-source-changes' ) ;; notset) ;; *) echo "Unknown option value for --sign-source-changes '$COWPOKE_SSC'. Stopping." exit 1 ;; esac # --cowpoke command line options override the git config .options settings. # Any cowpoke(1) option can be passed via --cowpoke or .options, but we have # these specialised config options as well so that it is easy to override # (and make overridable) a subset them without having to manually re-enter # all of what would otherwise be the default configuration. # # Multi-value options: get_option_values 'COWPOKE_OPTS' 'cowpoke' 'gitpkg-cowpoke-exit-hook.options' get_option_values 'COWPOKE_ARCH' 'arch' 'gitpkg-cowpoke-exit-hook.arch' get_option_values 'COWPOKE_DIST' 'dist' 'gitpkg-cowpoke-exit-hook.dist' get_option_values 'COWPOKE_DPKG_BP' 'dpkg-bp' 'gitpkg-cowpoke-exit-hook.dpkg-bp' # Single-value options: get_option_value 'COWPOKE_SIGN' 'sign' 'gitpkg-cowpoke-exit-hook.sign-key' get_option_value 'COWPOKE_UPLOAD' 'upload' 'gitpkg-cowpoke-exit-hook.upload-to' get_option_value 'COWPOKE_RETURN' 'return' 'gitpkg-cowpoke-exit-hook.return-dir' # Remove empty elements from this one so we can use --no-cowpoke to override config # default settings and pass no options without having a stray "" as an option word. trim_array 'COWPOKE_OPTS' # And from these, as it never makes sense to pass an empty arch or dist. trim_array 'COWPOKE_ARCH' trim_array 'COWPOKE_DIST' COWPOKE_OPTS+=( "${COWPOKE_ARCH[@]/#/--arch=}" "${COWPOKE_DIST[@]/#/--dist=}" "${COWPOKE_DPKG_BP[@]/#/--dpkg-bp=}" ${COWPOKE_SIGN+"--sign=${COWPOKE_SIGN}"} ${COWPOKE_UPLOAD+"--upload=${COWPOKE_UPLOAD}"} ${COWPOKE_RETURN+"--return${COWPOKE_RETURN:+=$COWPOKE_RETURN}"} "${EXTRA_COWPOKE_OPTS[@]}" ) # The option of a veto is a handy safety catch for running an unexpected hook, # but if the user has explicitly passed a cowpoke-specific command line option # then we'll take that as an implicit assent, and expressed intent, to proceed. ASK_YES_OPTS=( 'cowpoke' 'arch' 'dist' 'upload' 'return' ) if [ "$(repo_config --get --bool gitpkg-cowpoke-exit-hook.ask-first)" = 'true' ] && ! have_any_of_these_commandline_options "${ASK_YES_OPTS[@]}" then printf "Send $DEB_DSC off to cowpoke now (Y/n)? " read -e yesno case $yesno in N* | n*) echo "Ok, you're the boss. If you change your mind, just run:" echo "cowpoke" "${COWPOKE_OPTS[@]@Q}" "$DEB_DSC" echo exit 0 ;; "") echo "Yes" # read doesn't echo a line feed if the user just hit ;; *) ;; esac fi echo "cowpoke" "${COWPOKE_OPTS[@]@Q}" "$DEB_DSC" cowpoke "${COWPOKE_OPTS[@]}" "$DEB_DSC" # vi:sts=4:sw=4:noet:foldmethod=marker gitpkg-0.31/hooks/debcherry-deb-export-hook0000644000000000000000000000127414505757621015652 0ustar # To enable this hook, use: # git config gitpkg.deb-export-hook /usr/share/gitpkg/hooks/debcherry-deb-export-hook if [ -z "$REPO_DIR" -o -z "$GITPKG_TREEISH" ]; then echo "internal error: please define REPO_DIR and GITPKG_TREEISH" >&2 exit 1 fi orig_treeish="$GITPKG_ORIG_TREEISH" commit_file="../$DEB_ORIG".commit if [ -z "$orig_treeish" ]; then if [ ! -r "$commit_file" ]; then echo "No origbranch specified and no $commit_file" >&2 echo "Cannot export patches" >&2 exit 1 else orig_treeish=$(cat $commit_file) fi else echo "$orig_treeish" > "$commit_file" fi git --git-dir="$REPO_DIR/.git" debcherry -o debian/patches $orig_treeish $GITPKG_TREEISH gitpkg-0.31/hooks/dpkg-buildpackage-exit-hook0000644000000000000000000001403114505757621016134 0ustar # gitpkg hook script to build packages locally after export # # To enable this hook, use: # git config gitpkg.exit-hook /usr/share/gitpkg/hooks/dpkg-buildpackage-exit-hook # We're out of the repo tree, but want to check git-config . /usr/share/gitpkg/hooks/repo-config-helper # We need bash 4.4 or later for the ${var@Q} parameter transformation, so check # and bail out here with a friendly warning instead of crashing obscurely later. require_bash_version 4.4 # The --sign-source-changes option is a bit special, some of its values effect # both what we do here, and the options that we pass to other tools. get_option_value 'DPKG_BP_SSC' 'sign-source-changes' \ 'gitpkg-dpkg-buildpackage-exit-hook.source-changes' SOURCE_CHANGES= EXTRA_DPKG_BP_OPTS=() case ${DPKG_BP_SSC-unset} in "") EXTRA_DPKG_BP_OPTS+=( '-uc' '-us' ) ;& true|yes|signed) SOURCE_CHANGES=${DPKG_BP_SSC:-signed} ;; unset|false|no) ;; *) echo "Unknown option value for --sign-source-changes '$DPKG_BP_SSC'. Stopping." exit 1 ;; esac # --dpkg-bp command line options override the git config .options settings. # Any dpkg-buildpackage(1) option can be passed via --dpkg-bp or .options. # The more specialised config options exist so that it is easy to override # (and make overridable) just a subset them, without requiring the user to # manually re-enter all of the otherwise unchanged default configuration. # # Multi-value options: get_option_values 'DPKG_BP_OPTS' 'dpkg-bp' 'gitpkg-dpkg-buildpackage-exit-hook.options' # Single-value options: get_option_value 'DPKG_BP_SIGN' 'sign' 'gitpkg-dpkg-buildpackage-exit-hook.sign-key' get_bool_value 'DPKG_BP_BUILDLOG' 'build-log' 'gitpkg-dpkg-buildpackage-exit-hook.build-log' # Remove empty elements so that --dpkg-bp= can be used to override config # default settings to pass no options without passing "" as an option word. trim_array 'DPKG_BP_OPTS' DPKG_BP_OPTS+=( "${DPKG_BP_SIGN[@]/#/-k}" "${EXTRA_DPKG_BP_OPTS[@]}" ) # The option of a veto is a handy safety catch for running an unexpected hook, # but if the user has explicitly passed a dpkg-bp-specific command line option # then we'll take that as an implicit assent, and expressed intent, to proceed. ASK_YES_OPTS=( 'dpkg-bp' ) if [ "$(repo_config --get --bool gitpkg-dpkg-buildpackage-exit-hook.ask-first)" = 'true' ] && ! have_any_of_these_commandline_options "${ASK_YES_OPTS[@]}" then printf "Build binary packages from $DEB_DSC now (Y/n)? " read -e yesno case $yesno in N* | n*) echo "Ok, you're the boss. If you change your mind, just run:" echo "cd $DEB_DIR/$DEB_SOURCE/$DEB_PACKAGE &&" \ "dpkg-buildpackage" "${DPKG_BP_OPTS[@]@Q}" echo exit 0 ;; "") echo "Yes" # read doesn't echo a line feed if the user just hit ;; *) ;; esac fi do_build() { echo "cd $DEB_PACKAGE && dpkg-buildpackage" "${DPKG_BP_OPTS[@]@Q}" ( cd "$DEB_PACKAGE" && dpkg-buildpackage "${DPKG_BP_OPTS[@]}" ) || exit 1 # If source-changes = true, we respect -uc if passed and generate a # _source.changes file but do not sign it. # # If source-changes = signed, we consider -uc (if passed) to only apply # to the _.changes, and sign the source-only changes file. # The -us option is ignored in this case, as debsign will also sign all # .dsc and .buildinfo files referenced by the .changes it is signing. case $SOURCE_CHANGES in true|yes) SIGN_SOURCE_CHANGES= ;; signed) SIGN_SOURCE_CHANGES="yes" ;; *) return 0 ;; esac # Keep using the dpkg-buildpackage options which apply to dpkg-genchanges # and debsign when creating a _source.changes for the package. DPKG_GENCHANGES_OPTS=( "-S" ) DEBSIGN_OPTS=() # We use DEB_SIGN_KEYID from the environment, if set, as dpkg-buildpackage # does. But ignore DEBSIGN_KEYID here which is specific to debsign and is # not an environment variable. It can only be set in devscripts.conf and # will still be used by debsign (overriding -m or -e) if we do not choose # a key explicitly with -k. SIGNING_KEY=$DEB_SIGN_KEYID for opt in "${DPKG_BP_OPTS[@]}"; do case $opt in -s[iad]|-v*|-C*) DPKG_GENCHANGES_OPTS+=( "$opt" ) ;; --changes-option=*) DPKG_GENCHANGES_OPTS+=( "${opt#--changes-option=}" ) ;; # dpkg-buildpackage added long forms of these options, but didn't # add those to any of the tools it passes them through to, so we # need to fuck around here fixing that up. -m*|-e*) DPKG_GENCHANGES_OPTS+=( "$opt" ) DEBSIGN_OPTS+=( "$opt" ) ;; --release-by=*) DPKG_GENCHANGES_OPTS+=( "-m${opt#--release-by=}" ) DEBSIGN_OPTS+=( "-m${opt#--release-by=}" ) ;; --build-by=*) DPKG_GENCHANGES_OPTS+=( "-e${opt#--build-by=}" ) DEBSIGN_OPTS+=( "-e${opt#--build-by=}" ) ;; -k*) SIGNING_KEY=${opt#-k} ;; --sign-key=*) SIGNING_KEY=${opt#--sign-key=} ;; -uc|--unsigned-changes|--no-sign) SIGN_SOURCE_CHANGES=${SIGN_SOURCE_CHANGES:-"no"} ;; esac done # debsign will fall back to DEBSIGN_KEYID from devscripts.conf if it is set # and no -k override is passed, regardless of -m or -e - which is different # to the key dpkg-buildpackage would select [ -z "$SIGNING_KEY" ] || DEBSIGN_OPTS+=( "-k$SIGNING_KEY" ) SOURCE_CHANGES_FILE="${DEB_SOURCE}_${UPSTREAM_VERSION}_source.changes" echo "cd $DEB_PACKAGE && dpkg-genchanges" "${DPKG_GENCHANGES_OPTS[@]@Q}" \ "> ../$SOURCE_CHANGES_FILE" ( cd "$DEB_PACKAGE" && dpkg-genchanges "${DPKG_GENCHANGES_OPTS[@]}" \ > "../$SOURCE_CHANGES_FILE" ) || exit 1 [ "$SIGN_SOURCE_CHANGES" != 'no' ] || return 0 echo "debsign" "${DEBSIGN_OPTS[@]@Q}" "$SOURCE_CHANGES_FILE" debsign "${DEBSIGN_OPTS[@]}" "$SOURCE_CHANGES_FILE" } if [ "$DPKG_BP_BUILDLOG" = 'false' ] then do_build else DATE="$(date +%Y%m%d+%H.%M 2>/dev/null)" BUILD_LOGFILE="build-${DEB_SOURCE}_${DEB_VERSION}_${DATE}.log" echo "Recording build log in $BUILD_LOGFILE" do_build 2>&1 | tee "$BUILD_LOGFILE" fi # vi:sts=4:sw=4:noet:foldmethod=marker gitpkg-0.31/hooks/pristine-tar-pre-export-hook0000644000000000000000000000303514505757621016355 0ustar # gitpkg hook script to extract an .orig.tar.gz using pristine-tar. # Originally from David Bremner. # # To enable this hook, use: # git config gitpkg.pre-export-hook /usr/share/gitpkg/hooks/pristine-tar-pre-export-hook pt_hook_fail() { cat 1>&2 <<-EOF pristine-tar-pre-export-hook: $* Use: git config gitpkg.pre-export-hook '' to disable this hook for this repo, else fix the real problem and try again EOF exit 1 } if [ -n "$DEB_ORIG" ]; then pt_ref=$(git show-ref pristine-tar | cut -f1 -d' ') if [ -z "$pt_ref" ]; then pt_hook_fail "No pristine-tar branch found in this repo." fi # try the local branch first pt_tree=$(git show pristine-tar:"$DEB_ORIG".id) if [ -z "$pt_tree" ]; then pt_tree=$(git show $pt_ref:"$DEB_ORIG".id) fi if [ -z "$pt_tree" ]; then pt_hook_fail "Unable to find pristine-tar data for $DEB_ORIG" fi commit="" while read -r hash tree; do if [ "$tree" == "$pt_tree" ]; then if [ "$hash" == "commit" ]; then # pre-1.22 pristine-tar used commits in id files commit=$tree else commit=$hash fi continue fi done < <(git rev-list --pretty="%H %T" $GITPKG_TREEISH --) mkdir -p "$DEB_DIR/$DEB_SOURCE" if [ -n "$commit" ]; then echo "$commit" > "$DEB_DIR/$DEB_SOURCE/$DEB_ORIG".commit else echo "pristine-tar-pre-export-hook: " 1>&2 echo " Warning: Unable to find original commit for $DEB_ORIG" 1>&2 fi echo "pristine-tar checkout $DEB_DIR/$DEB_SOURCE/$DEB_ORIG" pristine-tar checkout "$DEB_DIR/$DEB_SOURCE/$DEB_ORIG" fi gitpkg-0.31/hooks/quilt-patches-deb-export-hook0000644000000000000000000000727214505757621016472 0ustar # This script reads a list of revision ranges suitable for git format-patch # from the $patch_list file, one per line, and exports them to the $patch_dir # directory in a form suitable for (format 3.0) quilt packages. # It is not required for creating such packages, but permits you to separate # out individual patches however you please from the default single patch # that is otherwise created by dpkg-source. # The revision ranges may include $DEB_REF and/or $UPSTREAM_REF, which # will be substituted according to the version of the package being # exported. These variables are derived from $DEB_VERSION and # $UPSTREAM_VERSION by applying sanitise_git_ref (see gitpkg(1) for # more on these three things). You can also use DEB_VERSION and # UPSTREAM_VERSION directly, but this is discouraged, and might go # away in a future version. # To enable this hook, use: # git config gitpkg.deb-export-hook /usr/share/gitpkg/hooks/quilt-patches-deb-export-hook # # # It can also be invoked independently of gitpkg, such as from within your # project makefile or debian/rules, with something like: # # PATCH_EXPORT_SCRIPT=/usr/share/gitpkg/hooks/quilt-patches-deb-export-hook # export-patches: # [ ! -r debian/patches ] || \ # grep "^\#.*$(notdir $(PATCH_EXPORT_SCRIPT))" debian/patches/series # rm -rf debian/patches # bash $(PATCH_EXPORT_SCRIPT) # Import the sanitise_git_ref function . /usr/share/gitpkg/hooks/repo-config-helper patch_list=debian/source/git-patches patch_dir=debian/patches if [ ! -r "$patch_list" ]; then echo "No $patch_list file, I guess you've pushed them all upstream." echo "Good Work!" exit 0 fi if [ -e "$patch_dir" ]; then echo "Uh oh. You already have a $patch_dir here." echo "You probably don't want us to scribble on that without asking." exit 1 fi if [ -z "$REPO_DIR" ]; then # support running as a free-standing script, without gitpkg DEB_VERSION="$(dpkg-parsechangelog | sed -rne 's/^Version: ([^:]+:)?//p')" UPSTREAM_VERSION="${DEB_VERSION%-*}" REPO_DIR=. fi; DEB_REF=$(sanitise_git_ref $DEB_VERSION) UPSTREAM_REF="${DEB_REF%-*}" do_patches (){ while read -r line do [ -n "$line" ] || continue case $line in \#*) ;; *) count=$(wc -l "$patch_dir/series" | cut -f1 -d' ') if PATCHES="$(git --git-dir "$REPO_DIR/.git" format-patch --no-signature --start-number $count -N -o "$patch_dir" "$line")"; then if [ -n "$PATCHES" ]; then echo "$PATCHES" | sed -e "s,$patch_dir/,,g" -e 's, ,\n,g' >> "$patch_dir/series" else echo "Warning: no patches from $line" fi else echo "git --git-dir '$REPO_DIR/.git' format-patch --no-signature --start-number $count -N -o '$patch_dir' '$line'" echo "failed." exit 1 fi esac done } mkdir -p "$patch_dir" || exit 1 echo "# $patch_list exported from git by quilt-patches-deb-export-hook" > "$patch_dir/series" (sed -e "s/\$DEB_VERSION/$DEB_VERSION/g" \ -e "s/\${DEB_VERSION}/$DEB_VERSION/g" \ -e "s/\$UPSTREAM_VERSION/$UPSTREAM_VERSION/g" \ -e "s/\${UPSTREAM_VERSION}/$UPSTREAM_VERSION/g" \ -e "s/\$DEB_REF/$DEB_REF/g" \ -e "s/\${DEB_REF}/$DEB_REF/g" \ -e "s/\$UPSTREAM_REF/$UPSTREAM_REF/g" \ -e "s/\${UPSTREAM_REF}/$UPSTREAM_REF/g" \ < "$patch_list" ; echo ) | do_patches || exit 1 count=$(wc -l "$patch_dir/series" | cut -f1 -d' ') # We remove the patch_list file if no patches were actually exported, # to avoid triggering the lintian check about them not being exported. # This might happen if people list a wildcard revision that doesn't # have any changes outstanding for a particular release version. if [ $count -eq 1 ]; then echo "No patches generated from $patch_list" rm -rf "$patch_dir" rm "$patch_list" fi gitpkg-0.31/hooks/repo-config-helper0000644000000000000000000004227614505757621014372 0ustar # gitpkg hook script helper to query git-config when out of the repo tree # # To use it, simply source it from your own hook with: # . /usr/share/gitpkg/hooks/repo-config-helper # then just call repo_config like you'd call 'git config'. # # It just passes any arguments verbatim to git-config, but in the right dir # for getting correct answers for this particular package. repo_config() { ( cd "$REPO_DIR" && git config "$@" ) } # sanitise_git_ref # {{{ # This function replaces all consecutive illegal constructs in a git refname # with a single '_'. The rules for git refnames are described in the manual # page for git-check-ref-format(1). Since they've been known to change from # release to release, including being renumbered, the version implemented is # described explicitly here too now. As of git version 2.1.0: # # Git imposes the following rules on how references are named: # # 1. They can include slash / for hierarchical (directory) grouping, but # no slash-separated component can begin with a dot . or end with # the sequence .lock. # # 2. They must contain at least one /. This enforces the presence of a # category like heads/, tags/ etc. but the actual names are not # restricted. If the --allow-onelevel option is used, this rule is # waived. # # 3. They cannot have two consecutive dots .. anywhere. # # 4. They cannot have ASCII control characters (i.e. bytes whose values # are lower than \040, or \177 DEL), space, tilde ~, caret ^, or # colon : anywhere. # # 5. They cannot have question-mark ?, asterisk *, or open bracket [ # anywhere. See the --refspec-pattern option below for an exception # to this rule. # # 6. They cannot begin or end with a slash / or contain multiple # consecutive slashes (see the --normalize option below for an # exception to this rule) # # 7. They cannot end with a dot .. # # 8. They cannot contain a sequence @{. # # 9. They cannot be the single character @. # # 10. They cannot contain a \. # # We don't enforce rule 9 here, you're probably just as doomed with a ref that # is just a single _ too, so you're on your own with the mess you made there. # }}} sanitise_git_ref() { ( shopt -s extglob ref=${1//\/.//_} # rule 1. # must have at least 1 '/' # rule 2 is NFU. ref=${ref//../_} # rule 3. ref=${ref//[[:cntrl:][:space:]:~^?*[]/_} # rule 4 & 5. ref=${ref##+(/)} # rule 6. ref=${ref//+(\/)\//_} # rule 6. ref=${ref%%+(/|.)} # rule 6 & 7. ref=${ref/%.lock/.loc} # rule 1 (was rule 6). ref=${ref//@{/_} # rule 8. # must not be a single @ # rule 9 is NFU. ref=${ref//\\\\/_} # rule 10. ref=${ref//+(_)_/_} echo "$ref" ) } # require_bash_version # {{{ # Assert we have a recent enough version of bash to support required features. # Bash 4.3 or later is needed for nameref and ${!var} indirection support. # Bash 4.4 or later is needed for the ${var@Q} parameter transformation. # # For lists of what features were added when, see: # https://mywiki.wooledge.org/BashFAQ/061 # https://wiki.bash-hackers.org/scripting/bashchanges # }}} require_bash_version() { local -a ver=( ${1//./ } ) local n=${#ver[@]} local i # If you need a finer grain version requirement than major.minor.patchlevel # then you're probably doing something terribly wrong. if [[ $n -gt 3 ]]; then n=3 printf "\n NOTE: require_bash_version($1) is silly, only checking >= " printf "%s." "${ver[@]:0:$n}" printf "\n\n" fi for (( i=0; i # Remove any empty elements from the indexed array NAME. # It does not remove elements which contain only whitespace or IFS characters. trim_array() { local -n ref=$1 local -a res=() local v for v in "${ref[@]}"; do [ -z "$v" ] || res+=( "$v" ) done ref=( "${res[@]}" ) } # have_commandline_option [ALL-OPTIONS] # # Simple true or false test of whether either --option-name or --no-option-name # were passed on the command line, evaluates to false if neither were. have_commandline_option() { local -n all_options=${2:-GITPKG_AOPTS} [[ ${all_options[$1]+set} || ${all_options[no-$1]+set} ]] } # have_any_of_these_commandline_options # # For each option-name check whether either --option-name or --no-option-name # were passed on the command line, evaluates to false if neither were for any # of the list of options. have_any_of_these_commandline_options() { local opt for opt; do ! have_commandline_option "$opt" || return 0 done return 1 } # extract_values_for [ALL-OPTIONS] # {{{ # This is a refinement of the extract_values_for_option function that requires # the bash 4.3 nameref functionality. It fills a caller-selected array with # all of the values passed for directly, and defaults to sourcing # the values from GITPKG_IOPTS unless an alternative array is provided. # # The treatment of command line arguments by this function is designed to suit # multi-valued options, where repeated use is normally additive and preserving # order may be important. It supports collecting options for tools where # passing an empty value is handled specially (to signal a default value, or # overriding previously set values etc.) # # It will interpret the alias --no-option as if a bare --option or --option='' # were used, adding an empty element to DEST-ARRAY. If option-name was not # passed on the command line (or rather if it does not appear in the array of # ALL-OPTIONS), then the prior content of DEST-ARRAY is not changed. # # For example: # # extract_values_for MY_OPTS my-option # # Will set MY_OPTS[] to ( 'foo' '' 'bar baz' '' ) if the command line was # gitpkg --my-option=foo --my-option --my-option='bar baz' --no-my-option # }}} extract_values_for() { local -n ref=$1 local -n option_array=${3:-GITPKG_IOPTS} local option_name=$2 local opt for opt in "${option_array[@]}"; do case $opt in --$option_name=*) ref+=( "${opt#*=}" ) ;; --$option_name|--no-$option_name) ref+=( "" ) ;; esac done; } # extract_value_for [ALL-OPTIONS] # {{{ # This function is specialised for the case of a single-value option, which may # still be passed multiple times, but each new value will strictly override the # last, they are not additive. # # If --option-name= is passed, DEST-VAR is set to . # If --option-name is passed, DEST-VAR is set to an empty string. # If --no-option-name is passed, DEST-VAR is unset. # # If option-name was not passed on the command line (or rather if it does not # appear in the array of ALL-OPTIONS), then the prior content of DEST-VAR is # not changed. # }}} extract_value_for() { local -n ref=$1 local -n option_array=${3:-GITPKG_IOPTS} local option_name=$2 local opt # Since we aren't looking for multiple values, only the last one set, # we could just look at GITPKG_AOPTS here, but that doesn't give us # an ordering between --option and --no-option if both were used ... for opt in "${option_array[@]}"; do case $opt in --$option_name=*) ref=${opt#*=} ;; --$option_name) ref= ;; --no-$option_name) unset ref ;; esac done } # extract_bool_for [ALL-OPTIONS] # {{{ # This function is specialised for the case of a single-value boolean option, # which may still be passed multiple times, but each new value will strictly # override the last, they are not additive, and there is little nuance to the # range of values, the option is essentially an on/off switch. # # It is in fact slightly more nuanced than that, DEST-VAR is a quad-state # variable which may be true, false, empty, or unset. # # Passing --option-name sets it true, --no-option-name sets it false, # and --option-name= sets it according to . # # Valid values for are in line with what git-config accepts: # yes, on, 1, or true, will all set DEST-VAR=true # no, off, 0, or false, will all set DEST-VAR=false # # As a special case, passing --option='' will set DEST-VAR to an empty string. # This may be interpreted specially by the caller (for example to ignore any # prior configuration and restore some default), or it may simply be treated # as an alias for either true or false as appropiate to the use case. # # Any other passed will emit a warning, but will otherwise be ignored. # # If option-name was not passed on the command line (or rather if it does not # appear in the array of ALL-OPTIONS), then the prior content of DEST-VAR is # not changed. # }}} extract_bool_for() { local -n ref=$1 local -n option_array=${3:-GITPKG_IOPTS} local option_name=$2 local opt for opt in "${option_array[@]}"; do case $opt in --$option_name=*) case ${opt#*=} in yes|on|true|1) ref='true' ;; no|off|false|0) ref='false' ;; "") ref='' ;; *) printf "\n WARNING: unexpected value '${opt#*=}'" printf " ignored for bool option '$option_name'\n\n" ;; esac ;; --$option_name) ref='true' ;; --no-$option_name) ref='false' ;; esac done } # get_option_values [] [default ...] # {{{ # Fill DEST-ARRAY with all the values passed to --cmdline-option, or if it was # not passed, all the values returned by `git config --get-all ` # finally falling back to the (optional) set of values if neither # of those had set any values for this option. # # The argument --no-cmdline-option will also be accepted and interpreted as if # --cmdline-option='' were passed, adding an empty element to DEST-ARRAY. The # order in which values were set is preserved in the elements of DEST-ARRAY. # # This function is best suited to handling multi-valued options, where repeated # use is normally additive and preserving order may be important. It supports # collecting options for tools where passing an empty value is somehow special # (to signal a default value, or overriding previously set values etc.) # # Any prior content of DEST-ARRAY will be erased when this function is called. # # The DEST_ARRAY values can be expanded again to form the command line for some # other tool with something like (note the containing double quotes): # # "${DEST_ARRAY[@]/#/--cmdline-option=}" # # which expands to nothing (an implicit null argument) if DEST_ARRAY is empty, # or --cmdline-option=value as a single word (even if the value itself contains # whitespace) for each value in the array. To expand the DEST_ARRAY as pairs # of words (e.g. --cmdline-option 'some value') or the like, you will need to # loop over the values and create a new array with alternating option and value # elements in it. # }}} get_option_values() { local -n ref=$1 local opt ref=() extract_values_for "$1" "$2" [ ${#ref[@]} -gt 0 ] || [ -z "$3" ] || while read opt; do ref+=("$opt") done < <(repo_config --get-all "$3") [ ${#ref[@]} -gt 0 ] || ref+=( "${@:4}" ) } # get_option_value [] [] # {{{ # Set DEST-VAR to the single, last-passed, value that is obtained after any # values that are set override the (if set), and are # in turn overridden by --cmdline-option if it is passed. # # If --cmdline-option= is passed, DEST-VAR is set to . # If --cmdline-option is passed, DEST-VAR is set to an empty string. # If --no-cmdline-option is passed, DEST-VAR is unset. # # If the option is not set by any of these sources then DEST-VAR will be unset # (not just empty) when this function returns. # # # The DEST_VAR values can be expanded again to form the command line for some # other tool with something like (note this one has no outer quoting): # # ${DEST_VAR+"--option${DEST_VAR:+=$DEST_VAR}"} # # which expands to nothing (an implicit null argument) or one single word: # # nothing if DEST_VAR is unset. # '--option' if it is set but empty, # '--option=safely quoted value' if set with a (non-empty) value. # # # Or for options which must always have some explicit value (even if empty). # # ${DEST_VAR+"--option=${DEST_VAR}"} # # which expands to nothing (an implicit null argument) or one single word: # # nothing if DEST_VAR is unset. # '--option=' if it is set but empty, # '--option=safely quoted value' if set with a (non-empty) value. # # # To expand DEST_VAR as pairs of option/value words, you can use something # like (again note no outer quoting for this case): # # ${DEST_VAR+'--option' "$DEST_VAR"} # # which expands to nothing (an implicit null argument), one, or two, words: # # nothing if DEST_VAR is unset. # '--option' if it is set but empty, # '--option' 'safely quoted value' if set with a value. # # Other variations on that theme are left as an exercise for the reader. # }}} get_option_value() { local -n ref=$1 local val # We need to walk through these from the lowest precedence to highest # as a command-line --no-option override may intentionally unset it, # which if we applied them in the opposite order is indistinguishable # from there being no command line option used. unset ref [ -z "${4+set}" ] || ref=$4 # Caller's default [ -z "$3" ] || ! val=$(repo_config --get "$3") || ref=$val # git config value extract_value_for "$1" "$2" # command line overrides } # get_bool_value [] [] # {{{ # Set DEST-VAR to the value set by --cmdline-option (or --no-cmdline-option) # or if that option was not passed on the command line, to the value that is # returned by `git config --get --bool `, or the if no value is # set there, to the value (if one was set by the caller). # # Passing --cmdline-option sets it true, --no-cmdline-option sets it false, # and --cmdline-option= sets it according to . # # Valid values for are in line with what git-config accepts: # yes, on, 1, or true, will all set DEST-VAR=true # no, off, 0, or false, will all set DEST-VAR=false # # As a special case, passing --option='' will set DEST-VAR to an empty string. # This may be interpreted specially by the caller (for example to ignore any # prior configuration and restore some default), or it may simply be treated # as an alias for either true or false as appropiate to the use case. # # Any other passed will emit a warning, but will otherwise be ignored. # # Values set for should be either 'true' or 'false' (or unset # where a tri-state value is desired when the option was not set at all). # # If the option is not set by any of these sources then DEST-VAR will be unset # (not just empty) when this function returns. # # DEST-VAR can be expanded back into a command line option again using any of # the methods described above for get_option_values(), or of course in any # other way that is appropriate for the caller. # }}} get_bool_value() { local -n ref=$1 local val unset ref extract_bool_for "$1" "$2" [ -n "${ref+set}" ] || [ -z "$3" ] || ! val=$(repo_config --get --bool "$3") || ref=$val [ -n "${ref+set}" ] || [ -z "${4+set}" ] || ref=$4 } # vi:sts=4:sw=4:noet:foldmethod=marker