aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2018-05-24 15:15:29 +0200
committerGuido Günther <agx@sigxcpu.org>2018-05-24 15:32:38 +0200
commit1592882c38fcbb107332d9a0a63b8da4e0bf8a48 (patch)
tree9ef0c19712cbef98f0836a581c46f4c4f3eec226
parenta287bf6155747ce8fc17580c11547f6ecc4e7aea (diff)
gbp import-ref: New command to merge in changes from a upstream using git
-rw-r--r--debian/git-buildpackage.install1
-rw-r--r--debian/git-buildpackage.manpages1
-rw-r--r--docs/Makefile1
-rw-r--r--docs/common.ent1
-rw-r--r--docs/man.gbp.xml1
-rw-r--r--docs/manpages/gbp-import-ref.xml256
-rw-r--r--docs/manpages/manpages.ent1
-rw-r--r--docs/manual.xml1
-rw-r--r--gbp/config.py1
-rw-r--r--gbp/scripts/import_ref.py207
-rw-r--r--packaging/git-buildpackage.spec2
-rw-r--r--tests/01_test_help.py4
-rw-r--r--tests/component/deb/test_import_ref.py87
13 files changed, 562 insertions, 2 deletions
diff --git a/debian/git-buildpackage.install b/debian/git-buildpackage.install
index 4ed4cc74..ebc1d8e7 100644
--- a/debian/git-buildpackage.install
+++ b/debian/git-buildpackage.install
@@ -23,6 +23,7 @@ usr/lib/python3.?/dist-packages/gbp/scripts/dch.py usr/lib/python3/dist-packages
usr/lib/python3.?/dist-packages/gbp/scripts/import_dsc.py usr/lib/python3/dist-packages/gbp/scripts/
usr/lib/python3.?/dist-packages/gbp/scripts/import_dscs.py usr/lib/python3/dist-packages/gbp/scripts/
usr/lib/python3.?/dist-packages/gbp/scripts/import_orig.py usr/lib/python3/dist-packages/gbp/scripts/
+usr/lib/python3.?/dist-packages/gbp/scripts/import_ref.py usr/lib/python3/dist-packages/gbp/scripts/
usr/lib/python3.?/dist-packages/gbp/scripts/export_orig.py usr/lib/python3/dist-packages/gbp/scripts/
usr/lib/python3.?/dist-packages/gbp/scripts/__init__.py usr/lib/python3/dist-packages/gbp/scripts/
usr/lib/python3.?/dist-packages/gbp/scripts/pq.py usr/lib/python3/dist-packages/gbp/scripts/
diff --git a/debian/git-buildpackage.manpages b/debian/git-buildpackage.manpages
index 60f37624..11398c13 100644
--- a/debian/git-buildpackage.manpages
+++ b/debian/git-buildpackage.manpages
@@ -9,6 +9,7 @@ docs/gbp-export-orig.1
docs/gbp-import-dsc.1
docs/gbp-import-dscs.1
docs/gbp-import-orig.1
+docs/gbp-export-ref.1
docs/gbp-pq.1
docs/gbp-pristine-tar.1
docs/gbp-pull.1
diff --git a/docs/Makefile b/docs/Makefile
index b7258a47..d1567e5e 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -11,6 +11,7 @@ MAN1S = \
gbp-import-dsc \
gbp-import-dscs \
gbp-import-orig \
+ gbp-import-ref \
gbp-pq \
gbp-pristine-tar \
gbp-pull \
diff --git a/docs/common.ent b/docs/common.ent
index 7f180064..d15440fd 100644
--- a/docs/common.ent
+++ b/docs/common.ent
@@ -25,6 +25,7 @@
<!ENTITY gbp-import-dsc "<command>gbp&nbsp;import-dsc</command>">
<!ENTITY gbp-import-dscs "<command>gbp&nbsp;import-dscs</command>">
<!ENTITY gbp-import-orig "<command>gbp&nbsp;import-orig</command>">
+ <!ENTITY gbp-import-ref "<command>gbp&nbsp;import-ref</command>">
<!ENTITY gbp-import-srpm "<command>gbp&nbsp;import-srpm</command>">
<!ENTITY gbp-pq "<command>gbp&nbsp;pq</command>">
<!ENTITY gbp-pq-export "<command>gbp&nbsp;pq&nbsp;<option>export</option></command>">
diff --git a/docs/man.gbp.xml b/docs/man.gbp.xml
index f77a1333..8d044a81 100644
--- a/docs/man.gbp.xml
+++ b/docs/man.gbp.xml
@@ -22,6 +22,7 @@
&man.gbp.importdsc;
&man.gbp.importdscs;
&man.gbp.importorig;
+&man.gbp.importref;
&man.gbp.import.srpm;
&man.gbp.pq;
&man.gbp.pq.rpm;
diff --git a/docs/manpages/gbp-import-ref.xml b/docs/manpages/gbp-import-ref.xml
new file mode 100644
index 00000000..77f7447f
--- /dev/null
+++ b/docs/manpages/gbp-import-ref.xml
@@ -0,0 +1,256 @@
+<refentry id="man.gbp.import.ref">
+ <refentryinfo>
+ <address>
+ &dhemail;
+ </address>
+ <author>
+ &dhfirstname;
+ &dhsurname;
+ </author>
+ </refentryinfo>
+ <refmeta>
+ <refentrytitle>gbp-import-ref</refentrytitle>
+ &dhsection;
+ </refmeta>
+ <refnamediv>
+ <refname>gbp-import-ref</refname>
+ <refpurpose>Update upstream sources when using &git; only</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ &gbp-import-ref;
+
+ &man.common.options.synopsis;
+ <arg><option>--upstream-version=</option><replaceable>version</replaceable></arg>
+ <arg><option>--merge-mode=</option><replaceable>[auto|merge|replace]</replaceable></arg>
+ <arg><option>--upstream-branch=</option><replaceable>branch_name</replaceable></arg>
+ <arg><option>--upstream-tag=</option><replaceable>tag_format</replaceable></arg>
+ <arg><option>--upstream-tree=</option><replaceable>[BRANCH|VERSION|commit-id]</replaceable></arg>
+ <arg><option>--debian-branch=</option><replaceable>branch_name</replaceable></arg>
+ <arg><option>--[no-]sign-tags</option></arg>
+ <arg><option>--keyid=</option><replaceable>gpg-keyid</replaceable></arg>
+ <arg><option>--postimport=cmd</option></arg>
+ <arg><option>--[no-]rollback</option></arg>
+ </cmdsynopsis>
+ </refsynopsisdiv>
+ <refsect1>
+ <title>DESCRIPTION</title>
+ <para>
+ &gbp-import-ref; merges upstream git commits onto your &debian-branch;
+ You can either specifiy a branch to merge, give an upstream
+ version or specify the commit id directly. If no tag exists for the imported
+ commit it will be automatically created.
+ </para>
+ </refsect1>
+ <refsect1>
+ <title>OPTIONS</title>
+ <variablelist>
+ &man.common.options.description;
+
+ <varlistentry>
+ <term><option>--upstream-version</option>=<replaceable>version</replaceable></term>
+ <term><option>-u</option><replaceable>version</replaceable></term>
+ <listitem>
+ <para>
+ The upstream version to merge. The upstream tag to use will be determined via
+ the <option>--upstream-tag</option>.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--merge-mode=</option><replaceable>[auto|merge|replace]</replaceable></term>
+ <listitem>
+ <para>
+ How to fold the upstream commits onto the
+ &debian; packaging branch.
+ </para>
+ <para>
+ <replaceable>merge</replaceable> does a
+ &git; <command>merge</command> leaving you on your own in
+ case of merge conflict resolution.
+ </para>
+ <para>
+ <replaceable>replace</replaceable> mode on the
+ other hand makes the head of the &debian; packaging branch
+ identical to the newly imported tree but preserves the
+ content of the <filename>debian/</filename> directory
+ while keeping the current head as well as the newly
+ imported tree as parents of the generated commit. This is
+ similar to a <option>theirs</option> merge strategy while
+ preserving <filename>debian/</filename>.
+ </para>
+ <para>
+ The default is <replaceable>auto</replaceable> which
+ uses <replaceable>replace</replaceable> for 3.0 (quilt) packages
+ and <replaceable>merge</replaceable> otherwise.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--upstream-branch</option>=<replaceable>branch_name</replaceable>
+ </term>
+ <listitem>
+ <para>
+ The branch in the &git; repository the upstream sources are
+ on. Default is <replaceable>upstream</replaceable>.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--upstream-tag=</option><replaceable>tag-format</replaceable>
+ </term>
+ <listitem>
+ <para>
+ Use this tag format when looking up upstream tags,
+ default is <replaceable>upstream/%(version)s</replaceable>.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--upstream-tree=</option><replaceable>[BRANCH|VERSION|commit-id]</replaceable>
+ </term>
+ <listitem>
+ <para>
+ What to merge into the &debian-branch;.
+ <replaceable>BRANCH</replaceable> (the default) merges from the upstream branch.
+ <replaceable>VERSION</replaceable> looks for a tag determined from the given
+ upstream version number via the <option>--upstream-version</option> option.
+ </para>
+ <para>
+ Other values are interpreted as git commit id to merge from.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--debian-branch</option>=<replaceable>branch_name</replaceable>
+ </term>
+ <listitem>
+ <para>
+ The branch in the &git; repository the &debian; package is being
+ developed on, default is <replaceable>master</replaceable>.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--[no-]sign-tags</option>
+ </term>
+ <listitem>
+ <para>
+ GPG sign all created tags.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--keyid=</option><replaceable>gpg-keyid</replaceable>
+ </term>
+ <listitem>
+ <para>
+ Use this <option><replaceable>keyid</replaceable></option>
+ for gpg signing tags.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--import-msg=</option><replaceable>msg-format</replaceable>
+ </term>
+ <listitem>
+ <para>
+ Use this format string for the commit message when importing upstream
+ versions, default is
+ <replaceable>New upstream version %(version)s</replaceable>.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--postimport=<replaceable>cmd</replaceable></option></term>
+ <listitem>
+ <para>
+ Run <replaceable>cmd</replaceable> after the import. The
+ hook gets the following environment variables passed:
+ <variablelist>
+ <varlistentry>
+ <term><envar>GBP_BRANCH</envar></term>
+ <listitem><para>
+ The name of the Debian packaging branch
+ </para></listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><envar>GBP_TAG</envar></term>
+ <listitem><para>
+ The name of the just created upstream tag
+ </para></listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><envar>GBP_UPSTREAM_VERSION</envar></term>
+ <listitem><para>
+ The just imported upstream version
+ </para></listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><envar>GBP_DEBIAN_VERSION</envar></term>
+ <listitem><para>
+ The Debian version of the package with a Debian
+ revision of '-1'
+ </para></listitem>
+ </varlistentry>
+ </variablelist>
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--[no-]rollback</option></term>
+ <listitem>
+ <para>
+ Rollback changes in case of an error.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+ <refsect1>
+ <title>EXAMPLES</title>
+ <para>
+ Merge commits from the &upstream-branch; into the &debian-branch;
+ creating a tag for the version <replaceable>0.0~git20180524</replaceable>:
+ </para>
+ <screen>
+ &gbp-import-ref; --upstream-tree=BRANCH -u0.0~git20180524</screen>
+ <para>
+ Merge commits from the the tag corresponding to version <replaceable>1.0</replaceable>:
+ </para>
+ <screen>
+ &gbp-import-ref; --upstream-tree=VERSION -u1.0</screen>
+ <para>
+ Merge commits given by a SHA1 creating a tag for the version
+ <replaceable>0.0~git20180524</replaceable>
+ </para>
+ <screen>
+ &gbp-import-ref; --upstream-tree=c4398912c -u0.0~git20180524</screen>
+ </refsect1>
+ <refsect1>
+ &man.gbp.config-files;
+ </refsect1>
+ <refsect1>
+ <title>SEE ALSO</title>
+ <para>
+ <xref linkend="man.gbp.buildpackage"/>,
+ <xref linkend="man.gbp.import.dsc"/>,
+ <xref linkend="man.gbp.import.dscs"/>,
+ <xref linkend="man.gbp.dch"/>,
+ <xref linkend="man.gbp.conf"/>,
+ <citerefentry>
+ <refentrytitle>uscan</refentrytitle>
+ <manvolnum>1</manvolnum>
+ </citerefentry>,
+ &man.seealso.common;
+ </para>
+ </refsect1>
+ <refsect1>
+ <title>AUTHOR</title>
+ <para>
+ &dhusername; &dhemail;
+ </para>
+ </refsect1>
+</refentry>
+<!-- LocalWords: xz lzma bzip gzip tarball
+-->
diff --git a/docs/manpages/manpages.ent b/docs/manpages/manpages.ent
index 452f83a5..b53ff4e4 100644
--- a/docs/manpages/manpages.ent
+++ b/docs/manpages/manpages.ent
@@ -12,6 +12,7 @@
<!ENTITY man.gbp.importdsc SYSTEM "gbp-import-dsc.xml">
<!ENTITY man.gbp.importdscs SYSTEM "gbp-import-dscs.xml">
<!ENTITY man.gbp.importorig SYSTEM "gbp-import-orig.xml">
+<!ENTITY man.gbp.importref SYSTEM "gbp-import-ref.xml">
<!ENTITY man.gbp.pq SYSTEM "gbp-pq.xml">
<!ENTITY man.gbp.pq.rpm SYSTEM "gbp-pq-rpm.xml">
<!ENTITY man.gbp.pristine.tar SYSTEM "gbp-pristine-tar.xml">
diff --git a/docs/manual.xml b/docs/manual.xml
index 35a4e417..09a7a1fb 100644
--- a/docs/manual.xml
+++ b/docs/manual.xml
@@ -39,6 +39,7 @@
&man.gbp.importdsc;
&man.gbp.importdscs;
&man.gbp.importorig;
+ &man.gbp.importref;
&man.gbp.pq;
&man.gbp.pristine.tar;
&man.gbp.pull;
diff --git a/gbp/config.py b/gbp/config.py
index e1b2328d..2226e629 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -131,6 +131,7 @@ class GbpOptionParser(OptionParser):
'full': 'False',
'git-author': 'False',
'git-log': '--no-merges',
+ 'git-ref': 'upstream/latest',
'hooks': 'True',
'id-length': '0',
'ignore-branch': 'False',
diff --git a/gbp/scripts/import_ref.py b/gbp/scripts/import_ref.py
new file mode 100644
index 00000000..e1177a10
--- /dev/null
+++ b/gbp/scripts/import_ref.py
@@ -0,0 +1,207 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2018 Michael Stapelberg <stapelberg@debian.org>
+# 2018 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 a new upstream version from a git branch onto the Debian branch"""
+
+import os
+import sys
+import gbp.command_wrappers as gbpc
+from gbp.deb.git import GitRepositoryError
+from gbp.config import GbpOptionParserDebian, GbpOptionGroup
+from gbp.errors import GbpError
+import gbp.log
+from gbp.scripts.common import ExitCodes
+from gbp.deb.rollbackgit import RollbackDebianGitRepository
+
+from gbp.scripts.import_orig import (debian_branch_merge,
+ postimport_hook,
+ set_bare_repo_options,
+ rollback)
+
+
+def get_commit_and_version_to_merge(repo, options):
+ """
+ Get the commit and version we want to merge based on the
+ --upstream-tag setting
+ """
+ version = options.version
+ if options.upstream_tree.upper() == 'VERSION':
+ # Determine tag name from given version
+ if not options.version:
+ raise GbpError("No upstream version given, try -u<version>")
+ commit = repo.version_to_tag(options.upstream_tag, options.version)
+ elif options.upstream_tree.upper() == 'BRANCH':
+ # Use head of upstrem branch
+ if not repo.has_branch(options.upstream_branch):
+ raise GbpError("%s is not a valid branch" % options.upstream_branch)
+ commit = options.upstream_branch
+ else:
+ # Use whatever is passed in as commitish
+ commit = "%s^{commit}" % options.upstream_tree
+ return commit, version
+
+
+def build_parser(name):
+ try:
+ parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='',
+ usage='%prog [options] /path/to/upstream-version.tar.gz | --uscan')
+ except GbpError as err:
+ gbp.log.err(err)
+ return None
+
+ import_group = GbpOptionGroup(parser, "import options",
+ "import related options")
+ tag_group = GbpOptionGroup(parser, "tag options",
+ "tag related options ")
+ branch_group = GbpOptionGroup(parser, "version and branch naming options",
+ "version number and branch layout options")
+ cmd_group = GbpOptionGroup(parser, "external command options",
+ "how and when to invoke external commands and hooks")
+ for group in [import_group, branch_group, tag_group, cmd_group]:
+ parser.add_option_group(group)
+
+ branch_group.add_option("-u", "--upstream-version", dest="version",
+ help="The version number to use for the new version, "
+ "default is ''", default='')
+ branch_group.add_config_file_option(option_name="debian-branch",
+ dest="debian_branch")
+ branch_group.add_config_file_option(option_name="upstream-branch",
+ dest="upstream_branch")
+ branch_group.add_config_file_option(option_name="upstream-tree",
+ dest="upstream_tree",
+ help="Where to merge the upstream changes from.",
+ default="VERSION")
+ branch_group.add_config_file_option(option_name="merge-mode", dest="merge_mode")
+
+ tag_group.add_boolean_config_file_option(option_name="sign-tags",
+ dest="sign_tags")
+ tag_group.add_config_file_option(option_name="keyid",
+ dest="keyid")
+ tag_group.add_config_file_option(option_name="upstream-tag",
+ dest="upstream_tag")
+ import_group.add_config_file_option(option_name="import-msg",
+ dest="import_msg")
+ cmd_group.add_config_file_option(option_name="postimport", dest="postimport")
+
+ parser.add_boolean_config_file_option(option_name="rollback",
+ dest="rollback")
+ parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
+ help="verbose command execution")
+ parser.add_config_file_option(option_name="color", dest="color", type='tristate')
+ parser.add_config_file_option(option_name="color-scheme",
+ dest="color_scheme")
+ return parser
+
+
+def parse_args(argv):
+ """Parse the command line arguments
+ @return: options and arguments
+ """
+
+ parser = build_parser(argv[0])
+ if not parser:
+ return None, None
+
+ (options, args) = parser.parse_args(argv[1:])
+ gbp.log.setup(options.color, options.verbose, options.color_scheme)
+
+ return options, args
+
+
+def main(argv):
+ ret = 0
+ repo = None
+
+ (options, args) = parse_args(argv)
+ if not options:
+ return ExitCodes.parse_error
+
+ # TODO: honor --filter option
+ # TODO: add --filter-with-copyright which takes d/copyright into account
+ # TODO: handle automatic versions based on timestamp + sha1
+ # TODO: handle updating of upstream branch from remote
+ try:
+ try:
+ repo = RollbackDebianGitRepository('.')
+ except GitRepositoryError:
+ raise GbpError("%s is not a git repository" % (os.path.abspath('.')))
+
+ commit, version = get_commit_and_version_to_merge(repo, options)
+
+ is_empty = repo.is_empty()
+
+ (clean, out) = repo.is_clean()
+ if not clean and not is_empty:
+ gbp.log.err("Repository has uncommitted changes, commit these first: ")
+ raise GbpError(out)
+
+ if repo.bare:
+ set_bare_repo_options(options)
+
+ try:
+ tag = repo.version_to_tag(options.upstream_tag, version)
+ if not repo.has_tag(tag):
+ gbp.log.info("Upstream tag '%s' not found. Creating it for you." % tag)
+ repo.create_tag(name=tag,
+ msg="Upstream version %s" % version,
+ commit="%s^0" % commit,
+ sign=options.sign_tags,
+ keyid=options.keyid)
+
+ if is_empty:
+ repo.create_branch(branch=options.debian_branch, rev=commit)
+ repo.force_head(options.debian_branch, hard=True)
+ # In an empty repo avoid master branch defaulted to by
+ # git and check out debian branch instead.
+ if not repo.bare:
+ cur = repo.branch
+ if cur != options.debian_branch:
+ repo.set_branch(options.debian_branch)
+ repo.delete_branch(cur)
+ else:
+ repo.rrr_branch(options.debian_branch)
+ debian_branch_merge(repo, tag, version, options)
+
+ # Update working copy and index if we've possibly updated the
+ # checked out branch
+ current_branch = repo.get_branch()
+ if current_branch in [options.upstream_branch,
+ repo.pristine_tar_branch]:
+ repo.force_head(current_branch, hard=True)
+
+ postimport_hook(repo, tag, version, options)
+ except (gbpc.CommandExecFailed, GitRepositoryError) as err:
+ msg = str(err) or 'Unknown error, please report a bug'
+ raise GbpError("Import of %s failed: %s" % (commit, msg))
+ except KeyboardInterrupt:
+ raise GbpError("Import of %s failed: aborted by user" % (options.git_ref))
+ except GbpError as err:
+ if str(err):
+ gbp.log.err(err)
+ ret = 1
+ rollback(repo, options)
+
+ if not ret:
+ gbp.log.info("Successfully imported version %s" % (version))
+ return ret
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))
+
+# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
diff --git a/packaging/git-buildpackage.spec b/packaging/git-buildpackage.spec
index 3d4d29de..21378242 100644
--- a/packaging/git-buildpackage.spec
+++ b/packaging/git-buildpackage.spec
@@ -178,6 +178,7 @@ cat > files.list << EOF
%{python_sitelib}/gbp/scripts/buildpackage.py*
%{python_sitelib}/gbp/scripts/dch.py*
%{python_sitelib}/gbp/scripts/export_orig.py*
+%{python_sitelib}/gbp/scripts/export_ref.py*
%{python_sitelib}/gbp/scripts/import_dsc.py*
%{python_sitelib}/gbp/scripts/import_dscs.py*
%{python_sitelib}/gbp/scripts/import_orig.py*
@@ -193,6 +194,7 @@ cat >> files.list << EOF
%{_mandir}/man1/gbp-import-dsc.1*
%{_mandir}/man1/gbp-import-dscs.1*
%{_mandir}/man1/gbp-import-orig.1*
+%{_mandir}/man1/gbp-import-ref.1*
%{_mandir}/man1/gbp-pq.1*
%{_mandir}/man1/git-pbuilder.1*
EOF
diff --git a/tests/01_test_help.py b/tests/01_test_help.py
index de930137..25c36fb0 100644
--- a/tests/01_test_help.py
+++ b/tests/01_test_help.py
@@ -15,13 +15,13 @@ class TestHelp(TestCaseWithData):
'create_remote_repo',
'dch',
'import_orig',
+ 'import_ref',
'import_dsc',
'pristine_tar',
'pull',
'push',
'pq',
- 'tag',
- ]
+ 'tag']
rpm_cmds = ['buildpackage_rpm',
'import_srpm',
diff --git a/tests/component/deb/test_import_ref.py b/tests/component/deb/test_import_ref.py
new file mode 100644
index 00000000..260a8be1
--- /dev/null
+++ b/tests/component/deb/test_import_ref.py
@@ -0,0 +1,87 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2015,2017 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
+from tests.component.deb import DEB_TEST_DATA_DIR
+from tests.component.deb.fixtures import RepoFixtures
+
+from gbp.scripts.import_ref import main as import_ref
+
+from nose.tools import ok_, eq_
+
+
+def _dsc_file(pkg, version, dir='dsc-3.0'):
+ return os.path.join(DEB_TEST_DATA_DIR, dir, '%s_%s.dsc' % (pkg, version))
+
+
+DEFAULT_DSC = _dsc_file('hello-debhelper', '2.6-2')
+
+
+class TestImportRef(ComponentTestBase):
+ """Test importing of new upstream versions"""
+ pkg = "hello-debhelper"
+ def_branches = ['master', 'upstream', 'pristine-tar']
+
+ def _orig(self, version, dir='dsc-3.0'):
+ return os.path.join(DEB_TEST_DATA_DIR,
+ dir,
+ '%s_%s.orig.tar.gz' % (self.pkg, version))
+
+ @RepoFixtures.quilt30(DEFAULT_DSC, opts=['--pristine-tar'])
+ def test_from_branch(self, repo):
+ """
+ Test that importing a upstream git from a branch works
+ """
+ eq_(len(repo.get_commits()), 2)
+ ok_(import_ref(['arg0',
+ '--upstream-tree=BRANCH',
+ '--upstream-tag=theupstream/%(version)s',
+ '-uaversion']) == 0)
+ self._check_repo_state(repo, 'master', self.def_branches,
+ tags=['debian/2.6-2', 'theupstream/aversion', 'upstream/2.6'])
+ eq_(len(repo.get_commits()), 3)
+
+ @RepoFixtures.quilt30(DEFAULT_DSC, opts=['--pristine-tar'])
+ def test_from_version(self, repo):
+ """
+ Test that importing a upstream git from a given version works
+ """
+ eq_(len(repo.get_commits()), 2)
+ ok_(import_ref(['arg0',
+ '--upstream-tree=VERSION',
+ '--upstream-tag=upstream/%(version)s',
+ '-u2.6']) == 0)
+ self._check_repo_state(repo, 'master', self.def_branches,
+ tags=['debian/2.6-2', 'upstream/2.6'])
+ eq_(len(repo.get_commits()), 3)
+
+ @RepoFixtures.quilt30(DEFAULT_DSC, opts=['--pristine-tar'])
+ def test_from_committish(self, repo):
+ """
+ Test that importing a upstream git from another commit works
+ """
+ eq_(len(repo.get_commits()), 2)
+ ok_(import_ref(['arg0',
+ '--upstream-tree=upstream',
+ '--upstream-tag=upstream/%(version)s',
+ '-u2.6']) == 0)
+ self._check_repo_state(repo, 'master', self.def_branches,
+ tags=['debian/2.6-2', 'upstream/2.6'])
+ eq_(len(repo.get_commits()), 3)