aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2014-04-04 10:05:25 +0200
committerGuido Günther <agx@sigxcpu.org>2014-04-04 10:05:25 +0200
commit738b3ca112979f6e95a6efaab0611df0c16ec135 (patch)
tree06475e2fdbb1a9bea53a3acb03c78ba3ca831783
parent59b7c1ea8c99fc25e2390cee6c1558a689402ad6 (diff)
parent7c415f8b75964423ec980e9ff3ada15896206356 (diff)
Merge tag 'debian/0.6.13' into bpo/wheezy
git-buildpackage Debian release 0.6.13
-rw-r--r--.gitignore2
-rw-r--r--debian/bug-presubj3
-rw-r--r--debian/changelog81
-rw-r--r--docs/Makefile16
-rw-r--r--docs/chapters/import.sgml1
-rw-r--r--docs/common.ent1
-rw-r--r--docs/copyright.sgml2
-rw-r--r--docs/man.gbp-config.sgml11
-rw-r--r--docs/manpages/gbp-config.sgml119
-rw-r--r--docs/manpages/gbp-import-dsc.sgml28
-rw-r--r--docs/manpages/gbp.conf.sgml14
-rw-r--r--docs/manpages/manpages.ent1
-rw-r--r--docs/manual.sgml1
-rw-r--r--gbp/config.py75
-rw-r--r--gbp/git/repository.py3
-rwxr-xr-xgbp/scripts/buildpackage.py29
-rwxr-xr-xgbp/scripts/clone.py14
-rw-r--r--gbp/scripts/common/pq.py2
-rwxr-xr-xgbp/scripts/config.py129
-rw-r--r--gbp/scripts/create_remote_repo.py61
-rw-r--r--gbp/scripts/dch.py35
-rw-r--r--gbp/scripts/import_dsc.py18
-rw-r--r--gbp/scripts/import_orig.py13
-rwxr-xr-xgbp/scripts/pq.py13
-rwxr-xr-xgbp/scripts/pull.py14
-rw-r--r--gbp/scripts/supercommand.py6
-rw-r--r--setup.cfg3
-rw-r--r--tests/01_test_help.py1
-rw-r--r--tests/18_test_Config.py87
-rw-r--r--tests/19_test_gbp_scripts_config.py86
-rw-r--r--tests/component/__init__.py7
m---------tests/component/deb/data0
-rw-r--r--tests/component/deb/test_import_dsc.py34
-rw-r--r--tests/data/gbp_config.conf4
-rw-r--r--tests/data/test1.conf35
-rw-r--r--tests/test_Config.py25
-rw-r--r--tests/testutils.py26
37 files changed, 845 insertions, 155 deletions
diff --git a/.gitignore b/.gitignore
index 6b5f0b7c..afc87fff 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,8 @@ gbp/version.py
build/
gbp.egg-info/
nosetests.xml
+*~
+*.sw?
docs/*.1
docs/*.5
diff --git a/debian/bug-presubj b/debian/bug-presubj
new file mode 100644
index 00000000..b000c9d9
--- /dev/null
+++ b/debian/bug-presubj
@@ -0,0 +1,3 @@
+When reporting issues regarding git-buildpackage please run the failing command
+with --git-verbose (gbp buildpackage) or --verbose (all other commands) and
+provide the full output.
diff --git a/debian/changelog b/debian/changelog
index 168e4145..08f3f4f4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,84 @@
+git-buildpackage (0.6.13) unstable; urgency=medium
+
+ [ Guido Günther ]
+ * [14f6ded] Test option parser fallbacks more thoroughly
+ revealing another bug where we overwrote parsed values with defaults
+ (Closes: #733759)
+ * [03ada72] .gitignore: ignore editor backup files
+ * [4c6b067] Add minimal 'config' command. This only allows to print single
+ config values so far. (Closes: #733470)
+ * [b393080] Import command not module. This matches the function name.
+ * [459d9bf] config: add decorator to add_option_* functions.
+ This allows us to build an internal list of valid options and print
+ these.
+
+ [ Markus Lehtonen ]
+ * [a8cfd88] Revert "GitRepository/add_remote_repo: fix the 'tags' argument"
+ Which caused an unwanted behavior of not fetching refs/heads at all --
+ only tags were fetched.
+ This reverts commit 5dd598fb8f2a9109189fad6cf631811f12ce2130
+ * [4131b90] docs: re-enable missing manpage
+
+ -- Guido Günther <agx@sigxcpu.org> Thu, 03 Apr 2014 21:31:38 +0200
+
+git-buildpackage (0.6.12) unstable; urgency=medium
+
+ * [89f3005] Use a much simpler version to fix the command name in --help
+ mostly reverting e1780f0. (Closes: #742907)
+
+ -- Guido Günther <agx@sigxcpu.org> Sat, 29 Mar 2014 00:17:59 +0100
+
+git-buildpackage (0.6.11) unstable; urgency=medium
+
+ [ Guido Günther ]
+ * [38cfa6c] Request verbose output on bug reports
+ * [d000b0c] Remove incorrect docs about multiple filter options
+ (Closes: #718536)
+ * [fd440e2] Use a temporary directory. This avoids file name collisions and
+ weired files in the working copy.
+ * [e1780f0] Fix command output.
+ The first line lacked the subcommand like:
+ $ gbp pull --help
+ Usage: gbp [options] - safely update a repository from remote
+ instead of
+ $ gbp pull --help
+ Usage: gbp pull [options] - safely update a repository from remote
+ ^^^^
+
+ [ Mario Lang ]
+ * [077dc35] Fix config file name
+
+ [ Markus Lehtonen ]
+ * [3808523] docs: add some missing sgml closing tags
+ * [d8f55da] GitRepository/get_commit_info: correctly handle file
+ renames/copies. Use the '--no-renames' git command line option in order
+ to prevent two filenames per entry.
+ * [5dd598f] GitRepository/add_remote_repo: fix the 'tags' argument.
+ Explicitly use --tags in git arguments - otherwise tags might not be
+ fetched.
+ * [15d87fb] tests: more robust check for the default urgency level of dch.
+ The dch tool might not report it's version if it is incorrectly compiled.
+ Create a dummy changelog and parse it "manually" to determine the default
+ urgency level.
+ * [7774375] pq: minor log message typo fix
+ * [bbf21bf] ComponentTestBase: use regex matching in log checking
+
+ -- Guido Günther <agx@sigxcpu.org> Thu, 27 Mar 2014 22:27:38 +0100
+
+git-buildpackage (0.6.10) unstable; urgency=medium
+
+ * [f1bc542,1b0b17c] config: Don't pull in config defaults twice.
+ This would otherwise overwrite values set in the legacy config sections.
+ (Closes: #733759)
+ * [7e26f91] Remove cover-min-percentage. It makes running single tests
+ harder than necessary since it requires the percentage also when using
+ "nose <testname>".
+ * [d533e0f] import_dsc: Create missing debian branch with
+ --create-missing-branches (Closes: #739888)
+ * [df32264] git-import-dsc: Document --create-missing-branches
+
+ -- Guido Günther <agx@sigxcpu.org> Sun, 23 Feb 2014 17:56:47 +0100
+
git-buildpackage (0.6.9) unstable; urgency=medium
[ Guido Günther ]
diff --git a/docs/Makefile b/docs/Makefile
index 93dd1352..594126a6 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -1,15 +1,19 @@
#!/usr/bin/make
-MAN1S = gbp-buildpackage \
+MAN1S = \
+ gbp \
+ gbp-buildpackage \
+ gbp-clone \
+ gbp-config \
+ gbp-create-remote-repo \
+ gbp-dch \
gbp-import-dsc \
gbp-import-dscs \
gbp-import-orig \
- gbp-dch \
- gbp \
- gbp-pull \
- gbp-clone \
gbp-pq \
- gbp-create-remote-repo
+ gbp-pull \
+ $(NULL)
+
MAN5S = gbp.conf
MANUAL=manual-html
diff --git a/docs/chapters/import.sgml b/docs/chapters/import.sgml
index 2c05e5dd..446b1212 100644
--- a/docs/chapters/import.sgml
+++ b/docs/chapters/import.sgml
@@ -256,6 +256,7 @@ upstream-tag = v%(version)s
gbp buildpackage --git-upstream-tag='v%(version)s' --git-debian-branch=debian/sid
</screen>
If you want to share you're repository with others you can use &gbp-create-remote-repo; and &gbp-pull; as usual.
+ </para>
</sect3>
</sect2>
diff --git a/docs/common.ent b/docs/common.ent
index 58472f40..005d6746 100644
--- a/docs/common.ent
+++ b/docs/common.ent
@@ -8,6 +8,7 @@
<!ENTITY gbp-import-orig "<command>gbp import-orig</command>">
<!ENTITY gbp-import-dsc "<command>gbp import-dsc</command>">
<!ENTITY gbp-import-dscs "<command>gbp import-dscs</command>">
+ <!ENTITY gbp-config "<command>gbp config</command>">
<!ENTITY gbp-dch "<command>gbp dch</command>">
<!ENTITY gbp "<command>gbp</command>">
<!ENTITY gbp-pull "<command>gbp pull</command>">
diff --git a/docs/copyright.sgml b/docs/copyright.sgml
index 66609da8..f2a9148c 100644
--- a/docs/copyright.sgml
+++ b/docs/copyright.sgml
@@ -1,6 +1,6 @@
<para>
git-buildpackage, all associated scripts and programs, this manual,
- and all build scripts are Copyright &copy; 2006,2007 Guido Guenther.
+ and all build scripts are Copyright &copy; 2006-2014 Guido Guenther.
</para>
<para>
This program is free software; you can redistribute it and/or modify
diff --git a/docs/man.gbp-config.sgml b/docs/man.gbp-config.sgml
new file mode 100644
index 00000000..b0076e8e
--- /dev/null
+++ b/docs/man.gbp-config.sgml
@@ -0,0 +1,11 @@
+<!DOCTYPE reference PUBLIC "-//OASIS//DTD DocBook V4.1//EN" [
+ <!ENTITY % COMMON SYSTEM "common.ent">
+ %COMMON;
+ <!ENTITY % MANPAGES SYSTEM "manpages/manpages.ent">
+ %MANPAGES;
+]>
+
+<reference>
+<title>git-buildpackage Manual</title>
+&man.gbp.config;
+</reference>
diff --git a/docs/manpages/gbp-config.sgml b/docs/manpages/gbp-config.sgml
new file mode 100644
index 00000000..d68ac643
--- /dev/null
+++ b/docs/manpages/gbp-config.sgml
@@ -0,0 +1,119 @@
+<refentry id="man.gbp.config">
+ <refentryinfo>
+ <address>
+ &dhemail;
+ </address>
+ <author>
+ &dhfirstname;
+ &dhsurname;
+ </author>
+ </refentryinfo>
+ <refmeta>
+ <refentrytitle>gbp-config</refentrytitle>
+ &dhsection;
+ </refmeta>
+ <refnamediv>
+ <refname>gbp-config</refname>
+
+ <refpurpose>Query configuration values</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ &gbp-config;
+
+ <arg><option>--verbose</option></arg>
+ <arg><option>--color=</option><replaceable>[auto|on|off]</replaceable></arg>
+ <group choice='req'>
+ <arg choice="plain"><replaceable>command.option</replaceable></arg>
+ <arg choice="plain"><replaceable>command</replaceable></arg>
+ </group>
+ </cmdsynopsis>
+ </refsynopsisdiv>
+ <refsect1>
+ <title>DESCRIPTION</title>
+ <para>
+ &gbp-config; prints values from the configuration files. It interpolates the
+ value for <replaceable>option</replaceable> of
+ <replaceable>command</replaceable>.
+ </para>
+ </refsect1>
+ <refsect1>
+ <title>OPTIONS</title>
+ <variablelist>
+ <varlistentry>
+ <term><option>--verbose</option></term>
+ <term><option>-v</option></term>
+ <listitem>
+ <para>verbose execution</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--color=</option><replaceable>[auto|on|off]</replaceable>
+ </term>
+ <listitem>
+ <para>Whether to use colored output.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+ <refsect1>
+ <title>EXIT CODES</title>
+ <para>
+ When &gbp-config finishes it indicates success or failure with its exit code:
+ </para>
+ <variablelist>
+ <varlistentry>
+ <term><option>0</option></term>
+ <listitem>
+ <para>Success.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>1</option></term>
+ <listitem>
+ <para>Failed to parse command line</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>2</option></term>
+ <listitem>
+ <para>The value did not exist</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+ <refsect1>
+ <title>EXAMPLES</title>
+ <para>Print the value <option>upstream-branch</option> that &gbp-buildpackage;
+ would use:</para>
+ <screen>
+ $ gbp config buildpackage.upstream-branch
+ buildpackage.upstream-branch=upstream
+ </screen>
+ <para>Print the values of all of &gbp-buildpackage;s options</para>
+ <screen>
+ $ gbp config buildpackage
+ buildpackage.upstream-branch=upstream
+ buildpackage.debian-branch=master
+ ...
+ </screen>
+ </refsect1>
+ <refsect1>
+ &man.gbp.config-files;
+ </refsect1>
+ <refsect1>
+ <title>SEE ALSO</title>
+ <para>
+ <citerefentry>
+ <refentrytitle>gbp.conf</refentrytitle>
+ &dhconfsection;
+ </citerefentry>
+ </para>
+ </refsect1>
+ <refsect1>
+ <title>AUTHOR</title>
+
+ <para>&dhusername; &dhemail;</para>
+
+ </refsect1>
+</refentry>
diff --git a/docs/manpages/gbp-import-dsc.sgml b/docs/manpages/gbp-import-dsc.sgml
index bc2211c0..98f70e72 100644
--- a/docs/manpages/gbp-import-dsc.sgml
+++ b/docs/manpages/gbp-import-dsc.sgml
@@ -21,20 +21,21 @@
<cmdsynopsis>
&gbp-import-dsc;
- <arg><option>--verbose</option></arg>
- <arg><option>--upstream-branch=</option><replaceable>branch_name</replaceable></arg>
+ <arg><option>--allow-same-versions</option></arg>
+ <arg><option>--author-date-is-committer-date</option></arg>
+ <arg><option>--author-is-committer</option></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>--debian-tag=</option><replaceable>tag-format</replaceable></arg>
- <arg><option>--upstream-tag=</option><replaceable>tag-format</replaceable></arg>
- <arg><option>--skip-debian-tag=</option></arg>
+ <arg><option>--download</option></arg>
<arg><option>--filter=</option><replaceable>pattern</replaceable></arg>
+ <arg><option>--keyid=</option><replaceable>gpg-keyid</replaceable></arg>
+ <arg><option>--[no-]create-missing-branches</option></arg>
<arg><option>--[no-]pristine-tar</option></arg>
- <arg><option>--download</option></arg>
- <arg><option>--allow-same-versions</option></arg>
- <arg><option>--author-is-committer</option></arg>
- <arg><option>--author-date-is-committer-date</option></arg>
+ <arg><option>--[no-]sign-tags</option></arg>
+ <arg><option>--skip-debian-tag=</option></arg>
+ <arg><option>--upstream-branch=</option><replaceable>branch_name</replaceable></arg>
+ <arg><option>--upstream-tag=</option><replaceable>tag-format</replaceable></arg>
+ <arg><option>--verbose</option></arg>
<arg choice="plain"><replaceable>debian-source.dsc</replaceable></arg>
</cmdsynopsis>
<cmdsynopsis>
@@ -181,6 +182,13 @@
its parents.</para></warning></para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--[no-]create-missing-branches</option>
+ </term>
+ <listitem>
+ <para>Create missing upstream and debian branch if missing.</para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect1>
<refsect1>
diff --git a/docs/manpages/gbp.conf.sgml b/docs/manpages/gbp.conf.sgml
index 5bed99d5..a580220a 100644
--- a/docs/manpages/gbp.conf.sgml
+++ b/docs/manpages/gbp.conf.sgml
@@ -84,7 +84,7 @@ option which can be turned into configuration file setting by dropping the
</programlisting>
<para>
-Notice that some option are actually repeatable, or take Python lists.
+Notice that some option can take Python like lists.
For example the <xref linkend="man.gbp.import.orig"> commmand has the
<option>--filter</option>=<parameter>pattern</parameter> option which can
be truned into a configuration file option like this:
@@ -92,16 +92,6 @@ be truned into a configuration file option like this:
<programlisting>
[import-orig]
- filter = .svn
- filter = .hg
-</programlisting>
-
-<para>
-An alternative way is to write it using Python list syntax:
-</para>
-
-<programlisting>
- [import-orig]
filter = [ '.svn', '.hg' ]
</programlisting>
@@ -170,7 +160,7 @@ An example set up for packaging work:
</para>
<programlisting>
- # $HOME/gbp.conf
+ # $HOME/.gbp.conf
[DEFAULT]
pristine-tar = True
diff --git a/docs/manpages/manpages.ent b/docs/manpages/manpages.ent
index 3aee1def..d5882548 100644
--- a/docs/manpages/manpages.ent
+++ b/docs/manpages/manpages.ent
@@ -2,6 +2,7 @@
<!ENTITY man.gbp.importdsc SYSTEM "gbp-import-dsc.sgml">
<!ENTITY man.gbp.importdscs SYSTEM "gbp-import-dscs.sgml">
<!ENTITY man.gbp.buildpackage SYSTEM "gbp-buildpackage.sgml">
+<!ENTITY man.gbp.config SYSTEM "gbp-config.sgml">
<!ENTITY man.gbp.dch SYSTEM "gbp-dch.sgml">
<!ENTITY man.gbp SYSTEM "gbp.sgml">
<!ENTITY man.gbp.pull SYSTEM "gbp-pull.sgml">
diff --git a/docs/manual.sgml b/docs/manual.sgml
index 529f8109..af5e12fd 100644
--- a/docs/manual.sgml
+++ b/docs/manual.sgml
@@ -34,6 +34,7 @@
&man.gbp.importorig;
&man.gbp.dch;
&man.gbp.clone;
+ &man.gbp.config;
&man.gbp.pull;
&man.gbp.pq;
&man.gbp.create.remote.repo;
diff --git a/gbp/config.py b/gbp/config.py
index e465cede..fc31076e 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -45,6 +45,27 @@ def check_tristate(option, opt, value):
else:
return val
+
+def safe_option(f):
+ def _decorator(self, *args, **kwargs):
+ obj = self
+ option_name = kwargs.get('option_name')
+ if not option_name and len(args):
+ option_name = args[0]
+
+ # We're decorating GbpOption not GbpOptionParser
+ if not hasattr(obj, 'valid_options'):
+ if not hasattr(obj, 'parser'):
+ raise ValueError("Can only decorete GbpOptionParser and GbpOptionGroup not %s" % obj)
+ else:
+ obj = obj.parser
+
+ if option_name and not option_name.startswith('no-'):
+ obj.valid_options.append(option_name)
+ return f(self, *args, **kwargs)
+ return _decorator
+
+
class GbpOption(Option):
TYPES = Option.TYPES + ('path', 'tristate')
TYPE_CHECKER = copy(Option.TYPE_CHECKER)
@@ -305,7 +326,7 @@ class GbpOptionParser(OptionParser):
files = envvar.split(':') if envvar else klass.def_config_files
return [ os.path.expanduser(f) for f in files ]
- def _parse_config_files(self):
+ def parse_config_files(self):
"""
Parse the possible config files and set appropriate values
default values
@@ -335,11 +356,13 @@ class GbpOptionParser(OptionParser):
# Update with command specific settings
if parser.has_section(cmd):
- self.config.update(dict(parser.items(cmd, raw=True)))
+ # Don't use items() until we got rid of the compat sections
+ # since this pulls in the defaults again
+ self.config.update(dict(parser._sections[cmd].items()))
for section in self.sections:
if parser.has_section(section):
- self.config.update(dict(parser.items(section, raw=True)))
+ self.config.update(dict(parser._sections[section].items()))
else:
raise NoSectionError("Mandatory section [%s] does not exist."
% section)
@@ -370,8 +393,15 @@ class GbpOptionParser(OptionParser):
self.prefix = prefix
self.config = {}
self.config_files = self.get_config_files()
- self._parse_config_files()
+ self.parse_config_files()
+ self.valid_options = []
+
+ if self.command.startswith('git-') or self.command.startswith('gbp-'):
+ prog = self.command
+ else:
+ prog = "gbp %s" % self.command
OptionParser.__init__(self, option_class=GbpOption,
+ prog=prog,
usage=usage, version='%s %s' % (self.command,
gbp_version))
@@ -418,15 +448,16 @@ class GbpOptionParser(OptionParser):
default = self.config[option_name]
return default
+ @safe_option
def add_config_file_option(self, option_name, dest, help=None, **kwargs):
"""
set a option for the command line parser, the default is read from the config file
- @param option_name: name of the option
- @type option_name: string
- @param dest: where to store this option
- @type dest: string
- @param help: help text
- @type help: string
+ param option_name: name of the option
+ type option_name: string
+ param dest: where to store this option
+ type dest: string
+ param help: help text
+ type help: string
"""
if not help:
help = self.help[option_name]
@@ -439,17 +470,29 @@ class GbpOptionParser(OptionParser):
neg_help = "negates '--%s%s'" % (self.prefix, option_name)
self.add_config_file_option(option_name="no-%s" % option_name, dest=dest, help=neg_help, action="store_false")
+ def get_config_file_value(self, option_name):
+ """
+ Query a single interpolated config file value.
+
+ @param option_name: the config file option to look up
+ @type option_name: string
+ @returns: The config file option value or C{None} if it doesn't exist
+ @rtype: C{str} or C{None}
+ """
+ return self.config.get(option_name)
+
class GbpOptionGroup(OptionGroup):
+ @safe_option
def add_config_file_option(self, option_name, dest, help=None, **kwargs):
"""
set a option for the command line parser, the default is read from the config file
- @param option_name: name of the option
- @type option_name: string
- @param dest: where to store this option
- @type dest: string
- @param help: help text
- @type help: string
+ param option_name: name of the option
+ type option_name: string
+ param dest: where to store this option
+ type dest: string
+ param help: help text
+ type help: string
"""
if not help:
help = self.parser.help[option_name]
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 7e0b3299..10b90308 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -1529,7 +1529,8 @@ class GitRepository(object):
"""
commit_sha1 = self.rev_parse("%s^0" % commitish)
args = GitArgs('--pretty=format:%an%x00%ae%x00%ad%x00%cn%x00%ce%x00%cd%x00%s%x00%f%x00%b%x00',
- '-z', '--date=raw', '--name-status', commit_sha1)
+ '-z', '--date=raw', '--no-renames', '--name-status',
+ commit_sha1)
out, err, ret = self._git_inout('show', args.args)
if ret:
raise GitRepositoryError("Unable to retrieve commit info for %s"
diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py
index 753ad64a..c077b9e6 100755
--- a/gbp/scripts/buildpackage.py
+++ b/gbp/scripts/buildpackage.py
@@ -365,20 +365,12 @@ def changes_file_suffix(dpkg_args):
return os.getenv('ARCH', None) or du.get_arch()
-def parse_args(argv, prefix):
- args = [ arg for arg in argv[1:] if arg.find('--%s' % prefix) == 0 ]
- dpkg_args = [ arg for arg in argv[1:] if arg.find('--%s' % prefix) == -1 ]
-
- # We handle these although they don't have a --git- prefix
- for arg in [ "--help", "-h", "--version" ]:
- if arg in dpkg_args:
- args.append(arg)
-
+def build_parser(name, prefix=None):
try:
- parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix=prefix)
+ parser = GbpOptionParserDebian(command=os.path.basename(name), prefix=prefix)
except ConfigParser.ParsingError as err:
gbp.log.err(err)
- return None, None, None
+ return None
tag_group = GbpOptionGroup(parser, "tag options", "options related to git tag creation")
branch_group = GbpOptionGroup(parser, "branch options", "branch layout options")
@@ -453,6 +445,21 @@ def parse_args(argv, prefix):
export_group.add_option("--git-dont-purge", action="store_true", dest="dont_purge", default=False,
help="deprecated, use --git-no-purge instead")
export_group.add_boolean_config_file_option(option_name="overlay", dest="overlay")
+ return parser
+
+
+def parse_args(argv, prefix):
+ args = [ arg for arg in argv[1:] if arg.find('--%s' % prefix) == 0 ]
+ dpkg_args = [ arg for arg in argv[1:] if arg.find('--%s' % prefix) == -1 ]
+
+ # We handle these although they don't have a --git- prefix
+ for arg in [ "--help", "-h", "--version" ]:
+ if arg in dpkg_args:
+ args.append(arg)
+
+ parser = build_parser(argv[0], prefix=prefix)
+ if not parser:
+ return None, None, None
options, args = parser.parse_args(args)
gbp.log.setup(options.color, options.verbose, options.color_scheme)
diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py
index 251cef21..62d0dcc2 100755
--- a/gbp/scripts/clone.py
+++ b/gbp/scripts/clone.py
@@ -29,13 +29,13 @@ from gbp.errors import GbpError
import gbp.log
-def parse_args (argv):
+def build_parser(name):
try:
- parser = GbpOptionParser(command=os.path.basename(argv[0]), prefix='',
+ parser = GbpOptionParser(command=os.path.basename(name), prefix='',
usage='%prog [options] repository - clone a remote repository')
except ConfigParser.ParsingError as err:
gbp.log.err(err)
- return None, None
+ return None
branch_group = GbpOptionGroup(parser, "branch options", "branch tracking and layout options")
parser.add_option_group(branch_group)
@@ -53,10 +53,16 @@ def parse_args (argv):
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):
+ parser = build_parser(argv[0])
+ if not parser:
+ return None, None
(options, args) = parser.parse_args(argv)
gbp.log.setup(options.color, options.verbose, options.color_scheme)
-
return (options, args)
diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py
index 8e41d4ae..d3c07d17 100644
--- a/gbp/scripts/common/pq.py
+++ b/gbp/scripts/common/pq.py
@@ -89,7 +89,7 @@ def parse_gbp_commands(info, cmd_tag, noarg_cmds, arg_cmds):
elif noarg_cmds and cmd in noarg_cmds:
commands[cmd] = match.group('args')
else:
- gbp.log.warn("Ignoring unknow gbp-command '%s' in commit %s"
+ gbp.log.warn("Ignoring unknown gbp-command '%s' in commit %s"
% (line, info['id']))
return commands
diff --git a/gbp/scripts/config.py b/gbp/scripts/config.py
new file mode 100755
index 00000000..0ebca130
--- /dev/null
+++ b/gbp/scripts/config.py
@@ -0,0 +1,129 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2014 Guido Guenther <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, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+"""Query and display config file values"""
+
+import ConfigParser
+import sys
+import os, os.path
+from gbp.config import (GbpOptionParser, GbpOptionGroup)
+from gbp.errors import GbpError
+from gbp.scripts.supercommand import import_command
+import gbp.log
+
+
+def build_parser(name):
+ try:
+ parser = GbpOptionParser(command=os.path.basename(name), prefix='',
+ usage='%prog [options] - display configuration settings')
+ except ConfigParser.ParsingError as err:
+ gbp.log.err(err)
+ return None
+
+ 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):
+ parser = build_parser(argv[0])
+ if not parser:
+ return None, None
+ return parser.parse_args(argv)
+
+
+def parse_cmd_config(command):
+ """Make a command parse it's config files"""
+ parser = GbpOptionParser(command)
+ parser.parse_config_files()
+ return parser
+
+
+def print_cmd_single_value(query, printer):
+ """Print a single configuration value of a command
+
+ @param query: the cmd to print the value for
+ @param printer: the printer to output the value
+ """
+ try:
+ cmd, option = query.split('.')
+ except ValueError:
+ return 2
+
+ parser = parse_cmd_config(cmd)
+ value = parser.get_config_file_value(option)
+ printer("%s=%s" % (query, value))
+ return 0 if value else 1
+
+
+def print_cmd_all_values(cmd, printer):
+ """
+ Print all configuration values of a command
+
+ @param cmd: the cmd to print the values for
+ @param printer: the printer to output the values
+ """
+ if not cmd:
+ return 2
+ try:
+ # Populae the parset to get a list of
+ # valid options
+ module = import_command(cmd)
+ parser = module.build_parser(cmd)
+ except (AttributeError, ImportError):
+ return 2
+
+ for option in parser.valid_options:
+ value = parser.get_config_file_value(option)
+ if value != '':
+ printer("%s.%s=%s" % (cmd, option, value))
+ return 0
+
+
+def value_printer(value):
+ if (value):
+ print(value)
+
+
+def main(argv):
+ retval = 1
+
+ (options, args) = parse_args(argv)
+ gbp.log.setup(options.color, options.verbose, options.color_scheme)
+
+ if not args:
+ gbp.log.error("No command given")
+ return 2
+ elif len(args) != 2:
+ gbp.log.error("Can only take a single argument")
+ return 2
+ else:
+ query = args[1]
+
+ if '.' in query:
+ retval = print_cmd_single_value(query, value_printer)
+ else:
+ retval = print_cmd_all_values(query, value_printer)
+ return retval
+
+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/gbp/scripts/create_remote_repo.py b/gbp/scripts/create_remote_repo.py
index c8c4a36a..f0e680b4 100644
--- a/gbp/scripts/create_remote_repo.py
+++ b/gbp/scripts/create_remote_repo.py
@@ -18,6 +18,7 @@
# Based on the aa-create-git-repo and dom-new-git-repo shell scripts
"""Create a remote repo based on the current one"""
+import ConfigParser
import sys
import os, os.path
import urlparse
@@ -225,30 +226,16 @@ def push_branches(remote, branches):
gitPush([remote['url'], '--tags'])
-def parse_args(argv, sections=[]):
- """
- Parse the command line arguments and config files.
-
- @param argv: the command line arguments
- @type argv: C{list} of C{str}
- @param sections: additional sections to add to the config file parser
- besides the command name
- @type sections: C{list} of C{str}
- """
-
- # We simpley handle the template section as an additional config file
- # section to parse, this makes e.g. --help work as expected:
- for arg in argv:
- if arg.startswith('--remote-config='):
- sections = ['remote-config %s' % arg.split('=',1)[1]]
- break
- else:
- sections = []
+def build_parser(name, sections=[]):
+ try:
+ parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='',
+ usage='%prog [options] - '
+ 'create a remote repository',
+ sections=sections)
+ except ConfigParser.ParsingError as err:
+ gbp.log.err(err)
+ return None
- parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='',
- usage='%prog [options] - '
- 'create a remote repository',
- sections=sections)
branch_group = GbpOptionGroup(parser,
"branch options",
"branch layout and tracking options")
@@ -281,10 +268,34 @@ def parse_args(argv, sections=[]):
dest="template_dir")
parser.add_config_file_option(option_name="remote-config",
dest="remote_config")
+ return parser
+
+
+def parse_args(argv, sections=[]):
+ """
+ Parse the command line arguments and config files.
+
+ @param argv: the command line arguments
+ @type argv: C{list} of C{str}
+ @param sections: additional sections to add to the config file parser
+ besides the command name
+ @type sections: C{list} of C{str}
+ """
+
+ # We simpley handle the template section as an additional config file
+ # section to parse, this makes e.g. --help work as expected:
+ for arg in argv:
+ if arg.startswith('--remote-config='):
+ sections = ['remote-config %s' % arg.split('=',1)[1]]
+ break
+ else:
+ sections = []
- (options, args) = parser.parse_args(argv)
+ parser = build_parser(argv[0], sections)
+ if not parser:
+ return None, None
- return options, args
+ return parser.parse_args(argv)
def main(argv):
diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py
index a848d6d2..f36f2877 100644
--- a/gbp/scripts/dch.py
+++ b/gbp/scripts/dch.py
@@ -283,20 +283,14 @@ def changelog_commit_msg(options, version):
return options.commit_msg % dict(version=version)
-def main(argv):
- ret = 0
- changelog = 'debian/changelog'
- until = 'HEAD'
- found_snapshot_banner = False
- version_change = {}
- branch = None
-
+def build_parser(name):
try:
- parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='',
+ parser = GbpOptionParserDebian(command=os.path.basename(name),
usage='%prog [options] paths')
except ConfigParser.ParsingError as err:
gbp.log.err(err)
- return 1
+ return None
+
range_group = GbpOptionGroup(parser, "commit range options",
"which commits to add to the changelog")
version_group = GbpOptionGroup(parser, "release & version number options",
@@ -374,10 +368,31 @@ def main(argv):
dest="customization_file",
help=help_msg)
+
+ return parser
+
+
+def parse_args(argv):
+ 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)
dch_options = process_options(options, parser)
editor_cmd = process_editor_option(options)
+ return options, args, dch_options, editor_cmd
+
+def main(argv):
+ ret = 0
+ changelog = 'debian/changelog'
+ until = 'HEAD'
+ found_snapshot_banner = False
+ version_change = {}
+ branch = None
+
+
+ options, args, dch_options, editor_cmd = parse_args(argv)
try:
try:
diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py
index d60e0d16..600b394d 100644
--- a/gbp/scripts/import_dsc.py
+++ b/gbp/scripts/import_dsc.py
@@ -204,14 +204,13 @@ def set_bare_repo_options(options):
% (["", " '--no-pristine-tar'"][options.pristine_tar], ))
options.pristine_tar = False
-
-def parse_args(argv):
+def build_parser(name):
try:
- parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='',
+ parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='',
usage='%prog [options] /path/to/package.dsc')
except ConfigParser.ParsingError as err:
gbp.log.err(err)
- return None, None
+ return None
import_group = GbpOptionGroup(parser, "import options",
"pristine-tar and filtering")
@@ -263,9 +262,15 @@ def parse_args(argv):
dest="author_committer_date")
import_group.add_boolean_config_file_option(option_name="allow-unauthenticated",
dest="allow_unauthenticated")
+ return parser
+
+
+def parse_args(argv):
+ 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)
gbp.log.setup(options.color, options.verbose, options.color_scheme)
return options, args
@@ -377,7 +382,8 @@ def main(argv):
repo.create_branch(options.upstream_branch, commit)
if options.pristine_tar:
repo.pristine_tar.commit(src.tgz, options.upstream_branch)
- if is_empty and not repo.has_branch(options.debian_branch):
+ if (not repo.has_branch(options.debian_branch)
+ and (is_empty or options.create_missing_branches)):
repo.create_branch(options.debian_branch, commit)
if not src.native:
if src.diff or src.deb_tgz:
diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py
index aae93fab..542896ef 100644
--- a/gbp/scripts/import_orig.py
+++ b/gbp/scripts/import_orig.py
@@ -181,13 +181,13 @@ def set_bare_repo_options(options):
options.merge = False
-def parse_args(argv):
+def build_parser(name):
try:
- parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='',
+ parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='',
usage='%prog [options] /path/to/upstream-version.tar.gz | --uscan')
except ConfigParser.ParsingError as err:
gbp.log.err(err)
- return None, None
+ return None
import_group = GbpOptionGroup(parser, "import options",
"pristine-tar and filtering")
@@ -241,6 +241,13 @@ def parse_args(argv):
default=False, help="deprecated - don't use.")
parser.add_option("--uscan", dest='uscan', action="store_true",
default=False, help="use uscan(1) to download the new tarball.")
+ return parser
+
+
+def parse_args(argv):
+ 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)
diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py
index 41d3ddf8..fc205bf2 100755
--- a/gbp/scripts/pq.py
+++ b/gbp/scripts/pq.py
@@ -210,9 +210,9 @@ def switch_pq(repo, current):
switch_to_pq_branch(repo, current)
-def parse_args(argv):
+def build_parser(name):
try:
- parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='',
+ parser = GbpOptionParserDebian(command=os.path.basename(name),
usage="%prog [options] action - maintain patches on a patch queue branch\n"
"Actions:\n"
" export export the patch queue associated to the current branch\n"
@@ -226,7 +226,7 @@ def parse_args(argv):
" switch switch to patch-queue branch and vice versa")
except ConfigParser.ParsingError as err:
gbp.log.err(err)
- return None, None
+ return None
parser.add_boolean_config_file_option(option_name="patch-numbers", dest="patch_numbers")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
@@ -238,6 +238,13 @@ def parse_args(argv):
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):
+ parser = build_parser(argv[0])
+ if not parser:
+ return None, None
return parser.parse_args(argv)
diff --git a/gbp/scripts/pull.py b/gbp/scripts/pull.py
index 03be9fc7..fb0d8271 100755
--- a/gbp/scripts/pull.py
+++ b/gbp/scripts/pull.py
@@ -68,13 +68,14 @@ def fast_forward_branch(branch, repo, options):
msg="gbp: forward %s to %s" % (branch, remote))
return update
-def parse_args(argv):
+
+def build_parser(name):
try:
- parser = GbpOptionParser(command=os.path.basename(argv[0]), prefix='',
+ parser = GbpOptionParser(command=os.path.basename(name), prefix='',
usage='%prog [options] - safely update a repository from remote')
except ConfigParser.ParsingError as err:
gbp.log.err(err)
- return None, None
+ return None
branch_group = GbpOptionGroup(parser, "branch options", "branch update and layout options")
parser.add_option_group(branch_group)
@@ -93,6 +94,13 @@ def parse_args(argv):
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):
+ parser = build_parser(argv[0])
+ if not parser:
+ return None, None
return parser.parse_args(argv)
diff --git a/gbp/scripts/supercommand.py b/gbp/scripts/supercommand.py
index 4f2721f3..2eb64de2 100644
--- a/gbp/scripts/supercommand.py
+++ b/gbp/scripts/supercommand.py
@@ -44,10 +44,11 @@ The most commonly used commands are:
import-dscs - import multiple Debian source packages
"""
-def import_command(modulename):
+def import_command(cmd):
"""
Import the module that implements the given command
"""
+ modulename = sanitize(cmd)
if (not re.match(r'[a-z][a-z0-9_]', modulename) or
modulename in invalid_modules):
raise ImportError('Illegal module name %s' % modulename)
@@ -69,9 +70,8 @@ def supercommand(argv=None):
usage()
return 0
- modulename = sanitize(cmd)
try:
- module = import_command(modulename)
+ module = import_command(cmd)
except ImportError as e:
print >>sys.stderr, "'%s' is not a valid command." % cmd
usage()
diff --git a/setup.cfg b/setup.cfg
index da16b162..82471592 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -5,9 +5,6 @@ with-xunit=1
cover-package=gbp
cover-erase=1
exe=1
-#cover-html=1
-#cover-html-dir=build/cover/
-cover-min-percentage=68
[epydoc]
name = git-buildpackage
diff --git a/tests/01_test_help.py b/tests/01_test_help.py
index 0e4cf1d2..673d8708 100644
--- a/tests/01_test_help.py
+++ b/tests/01_test_help.py
@@ -12,6 +12,7 @@ class TestHelp(unittest.TestCase):
def testHelp(self):
for script in ['buildpackage',
'clone',
+ 'config',
'create_remote_repo',
'dch',
'import_orig',
diff --git a/tests/18_test_Config.py b/tests/18_test_Config.py
new file mode 100644
index 00000000..f7ba8c9c
--- /dev/null
+++ b/tests/18_test_Config.py
@@ -0,0 +1,87 @@
+# vim: set fileencoding=utf-8 :
+
+import os
+import unittest
+from gbp.config import GbpOptionParser, GbpOptionGroup
+from . import context
+
+class TestConfigParser(unittest.TestCase):
+ def setUp(self):
+ self.conffiles_save = os.environ.get('GBP_CONF_FILES')
+ self.confname = 'tests/data/test1.conf'
+ self.assertTrue(os.stat(self.confname))
+ os.environ['GBP_CONF_FILES'] = self.confname
+
+ def tearDown(self):
+ if self.conffiles_save:
+ os.environ['GBP_CONF_FILES'] = self.conffiles_save
+
+ def test_default(self):
+ """
+ A value only in the default section should be available in all commands
+ """
+ for n in range(1,5):
+ for prefix in [ '', 'git-', 'gbp-' ]:
+ parser = GbpOptionParser('cmd%d' % n)
+ self.assertEqual(parser.config['default_option'], 'default_default1')
+
+ def test_single_override(self):
+ """
+ A value in any command section should override the default
+ """
+ for prefix in [ '', 'git-', 'gbp-' ]:
+ parser = GbpOptionParser('%scmd1' % prefix)
+ self.assertEqual(parser.config['single_override_option1'], 'single_override_value1')
+
+ def test_single_git_override(self):
+ """
+ A value in any git-command section should override the default
+ """
+ for prefix in [ '', 'git-' ]:
+ parser = GbpOptionParser('%scmd2' % prefix)
+ self.assertEqual(parser.config['single_git_override_option1'], 'single_git_override_value1')
+
+ def test_single_gbp_override(self):
+ """
+ A value in any gbp-command section should override the default
+ """
+ for prefix in [ '', 'gbp-' ]:
+ parser = GbpOptionParser('%scmd3' % prefix)
+ self.assertEqual(parser.config['single_gbp_override_option1'], 'single_gbp_override_value1')
+ # FIXME: for all prefixes
+
+ def test_new_overrides_git(self):
+ """
+ A value in the cmd section should override the old git-cmd section independent from
+ how we're invoked
+ """
+ for n in range(4, 6):
+ for prefix in [ '', 'git-']:
+ cmd = '%scmd%d' % (prefix, n)
+ parser = GbpOptionParser(cmd)
+ actual = parser.config['new_overrides_git_option1']
+ expected = 'new_overrides_git_value1'
+ self.assertEqual(actual, expected, "%s != %s for %s" % (actual, expected, cmd))
+
+ def test_get_config_file_value(self):
+ """
+ Read a single value from the parse config
+ """
+ parser = GbpOptionParser('cmd4')
+ self.assertEqual(parser.get_config_file_value('new_overrides_git_option1'),
+ 'new_overrides_git_value1')
+ self.assertEqual(parser.get_config_file_value('doesnotexist'), None)
+
+ def test_param_list(self):
+ parser = GbpOptionParser('cmd4')
+
+ branch_group = GbpOptionGroup(parser, "branch options", "branch update and layout options")
+ parser.add_option_group(branch_group)
+ branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch")
+ branch_group.add_config_file_option("debian-branch", dest="upstream_branch")
+ parser.add_config_file_option(option_name="color", dest="color", type='tristate')
+
+ params = parser.valid_options
+ self.assertTrue('upstream-branch' in params)
+ self.assertTrue('debian-branch' in params)
+ self.assertTrue('color' in params)
diff --git a/tests/19_test_gbp_scripts_config.py b/tests/19_test_gbp_scripts_config.py
new file mode 100644
index 00000000..f503ef54
--- /dev/null
+++ b/tests/19_test_gbp_scripts_config.py
@@ -0,0 +1,86 @@
+# vim: set fileencoding=utf-8 :
+# (C) 2014 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""Test L{gbp} config"""
+
+import os
+import sys
+import unittest
+import gbp.scripts.config
+
+class TestGbpConfigCommand(unittest.TestCase):
+ class SingleValuePrintStub(object):
+ def __init__(self):
+ self.result = None
+
+ def __call__(self, arg):
+ self.result = arg
+
+ class AllValuesPrintStub(object):
+ def __init__(self, cmd):
+ self.cmd = cmd
+ self.result = {}
+
+ def __call__(self, arg):
+ k, v = arg.split('=', 1)
+ self.result[k] = v
+
+ def setUp(self):
+ self.conffiles_save = os.environ.get('GBP_CONF_FILES')
+ self.confname = 'tests/data/gbp_config.conf'
+ self.assertTrue(os.stat(self.confname))
+ os.environ['GBP_CONF_FILES'] = self.confname
+
+ def test_invocation_single_value(self):
+ """Can invoke it for a sngle value without error"""
+ ret = gbp.scripts.config.main(['doesnotmatter', 'coolcommand.branchname'])
+ self.assertEqual(ret, 0)
+
+ def test_invocation_missing_value(self):
+ """Can we detect a missing value"""
+ ret = gbp.scripts.config.main(['doesnotmatter', 'coolcommand.doesnotexist'])
+ self.assertEqual(ret, 1)
+
+ def test_print_cmd_single_value(self):
+ """Can we fetch a single configuration value"""
+ printstub = self.SingleValuePrintStub()
+ query = 'coolcommand.branchname'
+ ret = gbp.scripts.config.print_cmd_single_value(query, printstub)
+ self.assertEqual(printstub.result, '%s=abranch' % query)
+ self.assertEqual(ret, 0)
+
+ def test_print_cmd_all_values(self):
+ """Can we fetch the configuration for all commands"""
+ for cmd in [ 'buildpackage',
+ 'clone',
+ 'config',
+ 'create_remote_repo',
+ 'dch',
+ 'import_dsc',
+ 'import_orig',
+ 'pq',
+ 'pull' ]:
+ printstub = self.AllValuesPrintStub(cmd)
+ ret = gbp.scripts.config.print_cmd_all_values(cmd, printstub)
+ self.assertTrue('%s.color' % cmd in printstub.result.keys())
+ self.assertEqual(ret, 0)
+
+ def test_invalid_cms(self):
+ """Invalid commands or those not using the config should rerturn an error code"""
+ for cmd in [ "import_dscs", "supercommand" ]:
+ printstub = self.AllValuesPrintStub(cmd)
+ ret = gbp.scripts.config.print_cmd_all_values(cmd, printstub)
+ self.assertEqual(ret, 2)
+
diff --git a/tests/component/__init__.py b/tests/component/__init__.py
index 240b721d..4ef22563 100644
--- a/tests/component/__init__.py
+++ b/tests/component/__init__.py
@@ -21,6 +21,7 @@ Module for testing individual command line tools of the git-buildpackage suite
"""
import os
+import re
import shutil
import tempfile
from StringIO import StringIO
@@ -165,13 +166,13 @@ class ComponentTestBase(object):
self._log.seek(0)
return self._log.readlines()
- def _check_log(self, linenum, string):
+ def _check_log(self, linenum, regex):
"""Check that the specified line on log matches expectations"""
if self._log is None:
raise Exception("BUG in unittests: no log captured!")
output = self._get_log()[linenum].strip()
- ok_(output.startswith(string), ("Expected: '%s...' Got: '%s'" %
- (string, output)))
+ ok_(re.match(regex, output),
+ "Log entry '%s' doesn't match '%s'" % (output, regex))
def _clear_log(self):
"""Clear the mock strerr"""
diff --git a/tests/component/deb/data b/tests/component/deb/data
-Subproject fce347ecd0739fe29776a761775a92456a362af
+Subproject a06e148c09b6f9c9057ecdcabcbeed7d71ba0a1
diff --git a/tests/component/deb/test_import_dsc.py b/tests/component/deb/test_import_dsc.py
index bccdb077..da166152 100644
--- a/tests/component/deb/test_import_dsc.py
+++ b/tests/component/deb/test_import_dsc.py
@@ -1,6 +1,6 @@
# vim: set fileencoding=utf-8 :
#
-# (C) 2013 Guido Günther <agx@sigxcpu.org>
+# (C) 2013,2014 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
@@ -22,10 +22,12 @@ from tests.component import (ComponentTestBase,
ComponentTestGitRepository)
from tests.component.deb import DEB_TEST_DATA_DIR
+from nose.tools import ok_
+
from gbp.scripts.import_dsc import main as import_dsc
class TestImportDsc(ComponentTestBase):
- """Test importing of src.rpm files"""
+ """Test importing of debian source packages"""
def test_debian_import(self):
"""Test that importing of debian native packages works"""
@@ -50,3 +52,31 @@ class TestImportDsc(ComponentTestBase):
assert import_dsc(['arg0', dsc]) == 0
self._check_repo_state(repo, 'master', ['master'])
assert len(repo.get_commits()) == 3
+
+ def test_create_branches(self):
+ """Test if creating missing branches works"""
+ def _dsc(version):
+ return os.path.join(DEB_TEST_DATA_DIR,
+ 'dsc-3.0',
+ 'hello-debhelper_%s.dsc' % version)
+
+ dsc = _dsc('2.6-2')
+ assert import_dsc(['arg0',
+ '--pristine-tar',
+ '--debian-branch=master',
+ '--upstream-branch=upstream',
+ dsc]) == 0
+ repo = ComponentTestGitRepository('hello-debhelper')
+ os.chdir('hello-debhelper')
+ assert len(repo.get_commits()) == 2
+ self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream'])
+ dsc = _dsc('2.8-1')
+ assert import_dsc(['arg0',
+ '--pristine-tar',
+ '--debian-branch=foo',
+ '--upstream-branch=bar',
+ '--create-missing-branches',
+ dsc]) == 0
+ self._check_repo_state(repo, 'master', ['bar', 'foo', 'master', 'pristine-tar', 'upstream'])
+ commits, expected = len(repo.get_commits()), 2
+ ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))
diff --git a/tests/data/gbp_config.conf b/tests/data/gbp_config.conf
new file mode 100644
index 00000000..468e0ba4
--- /dev/null
+++ b/tests/data/gbp_config.conf
@@ -0,0 +1,4 @@
+# Data for TestGbpConfig
+
+[coolcommand]
+branchname = abranch \ No newline at end of file
diff --git a/tests/data/test1.conf b/tests/data/test1.conf
new file mode 100644
index 00000000..e7ffeb4f
--- /dev/null
+++ b/tests/data/test1.conf
@@ -0,0 +1,35 @@
+# Data for TestConfigParser
+
+[DEFAULT]
+default_option = default_default1
+single_override_option1 = single_override_default1
+single_git_override_option1 = single_git_override_default1
+single_gbp_override_option1 = single_gbp_override_default1
+new_overrides_git_option1 = new_overrides_git_default1
+
+# These commands only have a single section overriding defaults.
+# There are no alterntive old or new names
+[cmd1]
+single_override_option1 = single_override_value1
+
+[git-cmd2]
+single_git_override_option1 = single_git_override_value1
+
+[gbp-cmd3]
+single_gbp_override_option1 = single_gbp_override_value1
+
+# This commands have a new name overriding the old git- section
+# The order of the sections differs though
+[git-cmd4]
+new_overrides_git_option1 = new_overrides_git_overridden1
+
+[cmd4]
+new_overrides_git_option1 = new_overrides_git_value1
+
+[cmd5]
+new_overrides_git_option1 = new_overrides_git_value1
+
+[git-cmd5]
+new_overrides_git_option1 = new_overrides_git_overridden1
+
+
diff --git a/tests/test_Config.py b/tests/test_Config.py
index 9a68f8cc..046af278 100644
--- a/tests/test_Config.py
+++ b/tests/test_Config.py
@@ -60,27 +60,6 @@ def test_tristate():
auto
"""
-def test_parser_fallback():
- """
- Make sure we also parse git-<subcommands> sections if
- gbp <subcommand> was used.
-
- >>> import os
- >>> from gbp.config import GbpOptionParser
- >>> parser = GbpOptionParser('foo')
- >>> tmpdir = str(context.new_tmpdir('foo'))
- >>> confname = os.path.join(tmpdir, 'gbp.conf')
- >>> parser.config_files = [confname]
- >>> f = open(confname, 'w')
- >>> f.write('[foo]\\nthere = is\\n[git-foo]\\nno = truth\\n')
- >>> f.close()
- >>> parser._parse_config_files()
- >>> parser.config['there']
- 'is'
- >>> parser.config['no']
- 'truth'
- """
-
def test_filter():
"""
The filter option should always parse as a list
@@ -93,13 +72,13 @@ def test_filter():
>>> f = open(confname, 'w')
>>> f.write('[bar]\\nfilter = asdf\\n')
>>> f.close()
- >>> parser._parse_config_files()
+ >>> parser.parse_config_files()
>>> parser.config['filter']
['asdf']
>>> f = open(confname, 'w')
>>> f.write("[bar]\\nfilter = ['this', 'is', 'a', 'list']\\n")
>>> f.close()
- >>> parser._parse_config_files()
+ >>> parser.parse_config_files()
>>> parser.config['filter']
['this', 'is', 'a', 'list']
"""
diff --git a/tests/testutils.py b/tests/testutils.py
index 0b935b7c..e161dbe5 100644
--- a/tests/testutils.py
+++ b/tests/testutils.py
@@ -3,7 +3,9 @@
from . import context
import os
+import shutil
import subprocess
+import tempfile
import unittest
import gbp.log
@@ -91,17 +93,23 @@ class MockedChangeLog(ChangeLog):
def get_dch_default_urgency():
"""Determine the default urgency level used by dch"""
+ urgency = 'medium'
+ tempdir = tempfile.mkdtemp()
+ tmp_dch_name = os.path.join(tempdir, 'changelog')
try:
- popen = subprocess.Popen(['dch', '--version'], stdout=subprocess.PIPE)
- out, _err = popen.communicate()
+ dch_cmd = ['dch', '--create', '--empty', '--changelog', tmp_dch_name,
+ '--package=foo', '--newversion=1',
+ '--distribution=UNRELEASED']
+ ret = subprocess.Popen(dch_cmd).wait()
except OSError:
- urgency='medium'
+ pass
else:
- verstr = out.splitlines()[0].split()[-1]
- major, minor = verstr.split('.')[0:2]
- if int(major) <= 2 and int(minor) <= 12:
- urgency = 'low'
- else:
- urgency = 'medium'
+ if ret == 0:
+ with open(tmp_dch_name) as dchfile:
+ header = dchfile.readline().strip()
+ urgency = header.split()[-1].replace('urgency=', '')
+ finally:
+ if os.path.isdir(tempdir):
+ shutil.rmtree(tempdir)
return urgency