From cc442c4f0e10cf503918319a005855f3f06a1bf0 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Sat, 22 Nov 2008 14:00:45 -0500 Subject: Allowing configuring a default product and component Allowing specifying bz-tracker..default-product and bz-tracker..default-component. This is useful when done in the per-repository config. Add a "Per-repository configuration" section in the docs with examples. --- TODO | 6 ------ git-bz | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/TODO b/TODO index 7f9c501..edb9cb5 100644 --- a/TODO +++ b/TODO @@ -37,12 +37,6 @@ Allow editing comment used for attachments That you could uncomment to obsolete old patches. -Allow specifying a default product/component for 'git bz file' - - Specifying the product/component in the global git config would - be a bit silly/dangerous, but doing it locally in the git config - for a single repo would be quit useful. - Use XML-RPC when available. Maybe use python-bugzilla: http://fedorahosted.org/python-bugzilla/ diff --git a/git-bz b/git-bz index 747bd37..cea4984 100755 --- a/git-bz +++ b/git-bz @@ -77,12 +77,13 @@ # # to include the bug URL. (See 'git bz add-url') # git bz attach -u bugzilla.gnome.org:1234 b50ea9bd -1 # -# git bz file [-] [options] / [ | ] +# git bz file [-] [options] [[]/] [ | ] # # Like 'attach', but files a new bug. Opens an editor for the user to # enter the summary and description for the bug. If only a single commit # is named summary defaults to the subject of the commit, and the description -# to the body of the bug +# to the body of the bug. The product and component must be specified unless +# you have configured defaults. # # Examples: # @@ -122,6 +123,19 @@ # # git config --global bz.default-tracker bgo # +# Per-repository configuration +# ============================ +# Setting the default tracker, product and component in the local +# config for a repository can be useful: +# +# git config bz.default-tracker bugzilla.gnome.org +# git config bz-tracker.bugzilla.gnome.org.default-product gnome-shell +# git config bz-tracker.bugzilla.gnome.org.default-component general +# +# (The default-product and default-component values must always be +# specified within the config for a particular tracker.) Note the +# absence of the --global options. +# # Per Tracker Configuration # ========================= # git-bz needs some configuration specific to the bugzilla instance (tracker), @@ -853,12 +867,34 @@ def do_attach(bug_reference, since_or_revision_range): attach_commits(bug, commits) -def do_file(product_component, since_or_revision_range): - m = re.match("([^/]+)/([^/]+)", product_component) - if not m: - die("'%s' is not a valid / pair" % product_component) - product = m.group(1) - component = m.group(2) +def do_file(*args): + if len(args) == 1: + product_component, since_or_revision_range = None, args[0] + else: + product_component, since_or_revision_range = args[0], args[1] + + config = get_config(get_tracker()) + + if product_component: + m = re.match("(?:([^/]+)/)?([^/]+)", product_component) + if not m: + die("'%s' is not a valid [/]" % product_component) + + product = m.group(1) + component = m.group(2) + + if not product: + if not 'default-product' in config: + die("'%s' does not specify a product and no default product is configured" % product_component) + product = config['default-product'] + else: + if not 'default-product' in config: + die("[/] not specified and no default product is configured") + if not 'default-component' in config: + die("[/] not specified and no default component is configured") + + product = config['default-product'] + component = config['default-component'] commits = get_commits(since_or_revision_range) @@ -941,28 +977,29 @@ def add_add_url_option(): if command == 'add-url': parser.set_usage("git bz add-url [-] [options] []"); add_num_option() - n_args = 2 + min_args = max_args = 2 elif command == 'apply': parser.set_usage("git bz apply [options] "); add_add_url_option() - n_args = 1 + min_args = max_args = 1 elif command == 'attach': parser.set_usage("git bz attach [-] [options] []"); add_add_url_option() add_num_option() - n_args = 2 + min_args = max_args = 2 elif command == 'file': parser.set_usage("git bz file [-] [options] / [ | ]"); add_add_url_option() add_num_option() - n_args = 2 + min_args = 1 + max_args = 2 else: print >>sys.stderr, "Usage: git bz [add-url|apply|attach|file] [options]" sys.exit(1) global_options, args = parser.parse_args() -if len(args) != n_args: +if len(args) < min_args or len(args) > max_args: parser.print_usage() sys.exit(1) -- cgit v1.2.3