summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-07-08 15:28:21 +0200
committerGuido Günther <agx@sigxcpu.org>2016-07-08 15:33:18 +0200
commit95c8c53a8f4d2f8c1df7c94526141fbfdcc0340a (patch)
treee2467d76a995e55221eb0db606691c2a7c7963af
parent0ec3a4023afd77a658bbe47a014c22928c0543ec (diff)
clone: add postclone hook
Closes: #812816, #812815
-rw-r--r--docs/manpages/gbp-clone.sgml27
-rw-r--r--gbp/config.py1
-rwxr-xr-xgbp/scripts/clone.py15
-rw-r--r--tests/component/deb/test_clone.py75
4 files changed, 117 insertions, 1 deletions
diff --git a/docs/manpages/gbp-clone.sgml b/docs/manpages/gbp-clone.sgml
index 4ef7f24e..7b5a8ba1 100644
--- a/docs/manpages/gbp-clone.sgml
+++ b/docs/manpages/gbp-clone.sgml
@@ -28,6 +28,8 @@
<arg><option>--upstream-branch=</option><replaceable>branch_name</replaceable></arg>
<arg><option>--depth=</option><replaceable>depth</replaceable></arg>
<arg><option>--reference=</option><replaceable>repository</replaceable></arg>
+ <arg><option>--git-postclone=</option><replaceable>COMMAND</replaceable></arg>
+ <arg><option>--git-[no-]hooks</option></arg>
<arg choice="plain"><replaceable>remote_uri</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
@@ -92,6 +94,31 @@
</listitem>
</varlistentry>
</variablelist>
+ <variablelist>
+ <varlistentry>
+ <term><option>--git-[no-]hooks</option></term>
+ <listitem>
+ <para>
+ Enable running hooks.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ <variablelist>
+ <varlistentry>
+ <term><option>--git-postclone=</option><replaceable>COMMAND</replaceable></term>
+ <listitem>
+ <para>
+ Execute <replaceable>COMMAND</replaceable> after cloning the source
+ from the remote.
+ </para>
+ <para>
+ Exported environment variables are: <envar>GBP_GIT_DIR</envar> (the
+ repository the package is being built from).
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
</refsect1>
<refsect1>
<title>EXAMPLES</title>
diff --git a/gbp/config.py b/gbp/config.py
index a079447e..575a6b1d 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -110,6 +110,7 @@ class GbpOptionParser(OptionParser):
'posttag' : '',
'postbuild' : '',
'prebuild' : '',
+ 'postclone' : '',
'postexport' : '',
'postimport' : '',
'hooks' : 'True',
diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py
index 4464350d..57752f24 100755
--- a/gbp/scripts/clone.py
+++ b/gbp/scripts/clone.py
@@ -26,6 +26,7 @@ from gbp.deb.git import DebianGitRepository
from gbp.git import (GitRepository, GitRepositoryError)
from gbp.errors import GbpError
from gbp.scripts.common import ExitCodes
+from gbp.scripts.common.hook import Hook
import gbp.log
@@ -38,7 +39,9 @@ def build_parser(name):
return None
branch_group = GbpOptionGroup(parser, "branch options", "branch tracking and layout options")
+ cmd_group = GbpOptionGroup(parser, "external command options", "how and when to invoke hooks")
parser.add_option_group(branch_group)
+ parser.add_option_group(cmd_group)
branch_group.add_option("--all", action="store_true", dest="all", default=False,
help="track all branches, not only debian and upstream")
@@ -49,6 +52,9 @@ def build_parser(name):
help="git history depth (for creating shallow clones)")
branch_group.add_option("--reference", action="store", dest="reference", default=None,
help="git reference repository (use local copies where possible)")
+ cmd_group.add_config_file_option(option_name="postclone", dest="postclone",
+ help="hook to run after cloning the source tree, default is '%(postclone)s'")
+ cmd_group.add_boolean_config_file_option(option_name="hooks", dest="hooks")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
help="verbose command execution")
@@ -96,7 +102,8 @@ def main(argv):
os.chdir(repo.path)
# Reparse the config files of the cloned repository so we pick up the
- # branch information from there:
+ # branch information from there but don't overwrite hooks:
+ postclone = options.postclone
(options, args) = parse_args(argv)
# Track all branches:
@@ -119,6 +126,12 @@ def main(argv):
repo.create_branch(branch, remote)
repo.set_branch(options.debian_branch)
+
+ if postclone:
+ Hook('Postclone', options.postclone,
+ extra_env={'GBP_GIT_DIR': repo.git_dir},
+ )()
+
except KeyboardInterrupt:
retval = 1
gbp.log.err("Interrupted. Aborting.")
diff --git a/tests/component/deb/test_clone.py b/tests/component/deb/test_clone.py
new file mode 100644
index 00000000..dc7418ba
--- /dev/null
+++ b/tests/component/deb/test_clone.py
@@ -0,0 +1,75 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2016 Guido Günther <agx@sigxcpu.org>
+#
+# 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, please see
+# <http://www.gnu.org/licenses/>
+
+import os
+
+from tests.component import (ComponentTestBase,
+ ComponentTestGitRepository)
+from tests.component.deb import DEB_TEST_DATA_DIR
+
+from nose.tools import ok_, eq_
+
+from gbp.scripts.import_dsc import main as import_dsc
+from gbp.scripts.clone import main as clone
+
+
+class TestClone(ComponentTestBase):
+ """Test cloning from a remote"""
+
+ def test_clone_nonempty(self):
+ """Test that cloning into an existing dir fails"""
+ def _dsc(version):
+ return os.path.join(DEB_TEST_DATA_DIR,
+ 'dsc-native',
+ 'git-buildpackage_%s.dsc' % version)
+
+ # Build up somethng we can clone from
+ dsc = _dsc('0.4.14')
+ assert import_dsc(['arg0', dsc]) == 0
+ repo = ComponentTestGitRepository('git-buildpackage')
+ self._check_repo_state(repo, 'master', ['master'])
+ assert len(repo.get_commits()) == 1
+
+ ok_(clone(['arg0', repo.path]) == 1,
+ "Cloning did no fail as expected")
+ self._check_log(-2, "gbp:error: Git command failed: Error running git clone: fatal: destination path 'git-buildpackage' already exists and is not an empty directory.")
+
+ def test_clone_native(self):
+ """Test that cloning of debian native packages works"""
+ def _dsc(version):
+ return os.path.join(DEB_TEST_DATA_DIR,
+ 'dsc-native',
+ 'git-buildpackage_%s.dsc' % version)
+
+ # Build up somethng we can clone from
+ dsc = _dsc('0.4.14')
+ assert import_dsc(['arg0', dsc]) == 0
+ repo = ComponentTestGitRepository('git-buildpackage')
+ self._check_repo_state(repo, 'master', ['master'])
+ assert len(repo.get_commits()) == 1
+
+ dest = os.path.join(self._tmpdir,
+ 'cloned_repo')
+ clone(['arg0',
+ '--postclone=printenv > postclone.out',
+ repo.path, dest])
+ cloned = ComponentTestGitRepository(dest)
+ self._check_repo_state(cloned, 'master', ['master'])
+ assert len(cloned.get_commits()) == 1
+ self.check_hook_vars('postclone', ["GBP_GIT_DIR"])
+