#1061450 /usr/bin/dpkg-buildpackage: dpkg-buildpackage does not have tab completion

Package:
dpkg-dev
Source:
dpkg-dev
Submitter:
Aidan Gallagher
Date:
2026-11-03 08:41:02 UTC
Severity:
normal
Tags:
#1061450#5
Date:
2024-01-24 19:18:15 UTC
From:
To:
Hi,

I'm creating a wrapper around dpkg-buildpackage that allows package builds to run in a docker container (https://github.com/aidan-gallagher/debpic).

My package has tab completion for everything however when I added the option to specify dpkg-buildpackage options I realised dpkg-buildpackage doesn't have tab completion.

I assume this is an easy task that is free for picking up?

#1061450#10
Date:
2024-01-25 12:05:16 UTC
From:
To:
Hi!

I've been working on trying to first integrate the current bash
completion support from the bash-completion upstream, but there are
some compatibility issues that need to be fixed first:

https://github.com/scop/bash-completion/issues/694
https://github.com/guillemj/bash-completion/tree/pu/upstream-dpkg

and here's the integration in dpkg itself:

https://git.hadrons.org/cgit/debian/dpkg/dpkg.git/log/?h=pu/merge-bash-completions

But then I don't think that would affect dpkg-buildpackage. So if you
want to tackle that one, that would be great. I can probably split the
build system support and merge that and leave the tricky parts of the
hand over for later.

If you are talking about zsh, that also works though! :)

Thanks,
Guillem

#1061450#15
Date:
2024-02-02 06:41:20 UTC
From:
To:
Greetings.

I'm writing to you because I have a humanitarian request that I believe
could be incredibly impactful. I'm reaching out about the recent
devastating storm that tragically claimed many lives and affected numerous
individuals in Libya, including one of my clients. I would like to discuss
a proposal with you that could enable us to extend a helping hand to these
victims.

Looking forward to discussing this further with you.

Warm regards,
Mrs. Nathalie Herolds

#1061450#20
Date:
2026-05-19 10:21:32 UTC
From:
To:
Hi Guillem,

I'm new to Debian contribution and came across this bug via the
`newcomer` tag. Before I write anything, two quick questions so I
don't duplicate or conflict with the upstream bash-completion
integration you mentioned (pu/merge-bash-completions /
scop/bash-completion#694):

1. Is dpkg-buildpackage completion still open for an outside
   contribution, or has it been absorbed into your upstream work
   since then?

2. If still open, would you prefer the initial patch to add a zsh
   completion only (matching the existing `_dpkg-parsechangelog`
   style under `scripts/completion/zsh/`), or bash + zsh together?

No rush — I'll work on other newcomer-tagged bugs while waiting and
pick this up whenever you have a moment to reply.

#1061450#25
Date:
2026-06-02 03:32:10 UTC
From:
To:
Hi!

I've now submitted an MR to bash-completion upstream to be able to
unblock this and take over the completions in dpkg, which I'd be
planning on doing for 1.23.8, where I'm refreshing the
pu/merge-bash-completions branch, which I'll try to update tomorrow
or so.

Sure thing! For bash sure, for zsh I see that this is already
provided by zsh upstream (but I'm not sure how up-to-date it is).

I've not added anything new relative to bash-completion upstream,
but would consider starting to work on bash-completion improvements
and additions once the transfer has been coordinate. Let me know if
you'd like to start on any program and I'll hold off on those. I'm
unlikely to work on zsh as I don't use it, but I'm happy to merge
zsh completions.

Given what I mention above that zsh already ships completions for it,
I think bash-only would be easiest, as I'm not sure what's zsh stance
on where they prefer to maintain these. But if you or someone else
would like to check how an ownership transfer could be done from zsh
to dpkg, although that might imply rewriting the zsh completion from
scratch (clean room etc) to avoid having to use the Zsh license in
dpkg, then I'd be happy to merge such new completions.

So from my PoV, both would be ideal, but feel free to work on the ones
you are most interested in. In case you work on bash completions,
please make use of the new bash-completion 2.12 APIs (but not later).

Thanks,
Guillem

#1061450#30
Date:
2026-07-19 15:57:28 UTC
From:
To:
Hi Guillem,

Apologies for the slow reply — work has been keeping me busy these past
few weeks.

I see the transfer has landed in the meantime: bash-completion deprecated
its dpkg completions, and the import plus the dpkg-source rework are now
on dpkg main. Nice!

Since scripts/completion/bash/ only has dpkg-source so far, I'd like to
take dpkg-buildpackage as discussed — bash only, following the style and
layout of the dpkg-source file on main. If you've already started on it
locally, sorry for the delay, just tell me and I'll pick another program
instead.

Would you prefer a merge request on Salsa, or a patch to this bug?

Best regards,
Cheng Li

Guillem Jover <guillem@debian.org> 于2026年6月2日周二 11:32写道:

#1061450#35
Date:
2026-07-20 11:01:44 UTC
From:
To:
Hi!

No worries!

Yes, although I'm still working on the --help output improvements, which
in some cases affect the bash-completion parsing of available options
from a program. But I don't think this should affect dpkg-buildpackage
for now, except for the missing = for options with arguments, which I'll
be working on either for this release or next.

Sure, work on dpkg-buildpackage would be much appreciated. I only have a
couple of incomplete local commits to try to handle dselect's --color
options, but otherwise nothing else, no.

MRs are disabled on salsa (for multiple reasons), so a patch series here
for preservation purposes and if you want a branch somewhere would work.

Thanks,
Guillem

#1061450#40
Date:
2026-10-30 11:44:01 UTC
From:
To:
Hi Guillem,

Here is the patch series you asked for back in July; sorry for the long
delay.  It is two patches on top of current main (7492eb3d9).

Patch 1 fixes a bug I ran into while enumerating the options.  The
--help output has documented -ap's long form as --sign-pause since the
long options were added in 1.18.8 (293bd243a), but the parser was
written as --sign-pausa, so the documented spelling has never been
accepted, and the accepted one has never been documented, neither in
--help nor in the man page.  I did not keep the misspelling as a
deprecated alias: it was never part of the documented interface, and
-ap has always worked, so there is nothing to deprecate; --sign-pausa
now gets the usual unknown option error, which names the option.  The
patch also adds the man page entry, which has been missing all along,
annotated as "Support for long option since dpkg 1.23.12", as that is
when the long option starts to actually work; please adjust if this
lands in a different release.  A test asserts that the documented
spelling is accepted.

Patch 2 is the completion itself, following the dpkg-source file on
main and the bash-completion 2.12 API, together with the packaging
bits, in the shape of 9d6fa2c83.  It completes option names and, where
there is something sensible to offer, option values: build types, rules
targets, architectures, build profiles, OpenPGP backends, compression
parameters, command arguments for --root-command, --sign-command,
--check-command and --hook-*, pathname arguments, and the positional
.dsc file or source directory.  The --buildinfo-id, -E and -W options
are deliberately not completed, as they are accepted but have no
effect.

One packaging note: debian/dpkg-dev.install lists the files
individually, and with debhelper compat 13 dh_missing --fail-missing is
the default, so without that line dpkg's own package build fails.

I tested the completion with an offline harness that drives the
function directly (26 cases, covering option names and values) against
bash-completion 2.16; make check passes in a configured tree; and a
full "dpkg-buildpackage -b" of dpkg itself succeeds, with dh_missing
quiet and lintian reporting nothing on dpkg-dev.

Two unrelated things I noticed, both happy to turn into patches if you
want them:

- scripts/.gitignore uses unanchored script names, so the new
  completion file matches the "dpkg-buildpackage" entry and needs
  git add -f; the imported dpkg-source completion has the same
  property.  Anchoring the entries with a leading "/" would avoid it.

- Test::Dpkg::all_shell_files does not pick up
  scripts/completion/bash/, so t/shellcheck.t has never covered the
  completion files, dpkg-source included.  I ran shellcheck by hand
  with the exclude list from t/shellcheck.t, which is how I noticed
  SC1010 on the "done" hook name; patch 2 quotes it.

I can also push the series as a branch to my Salsa fork if that is
easier to look at, and I am happy to rework anything.

Best regards,
Cheng Li

Cheng Li (2):
  dpkg-buildpackage: Fix --sign-pause long option name
  completion: Add bash completion for dpkg-buildpackage

 debian/copyright                          |   1 +
 debian/dpkg-dev.install                   |   1 +
 man/dpkg-buildpackage.pod                 |   7 +
 scripts/Makefile.am                       |   1 +
 scripts/completion/bash/dpkg-buildpackage | 170 ++++++++++++++++++++++
 scripts/dpkg-buildpackage.pl              |   2 +-
 scripts/t/dpkg_buildpackage.t             |  17 ++-
 7 files changed, 197 insertions(+), 2 deletions(-)
 create mode 100644 scripts/completion/bash/dpkg-buildpackage

#1061450#47
Date:
2026-10-30 11:44:02 UTC
From:
To:
The long options were added in dpkg 1.18.8, where the --help output
documented this one as --sign-pause, while the parser was written as
--sign-pausa.  The documented spelling has therefore never been
accepted, and the accepted spelling has never been documented, neither
in --help nor in the man page.

Correct the parser to use the documented and intended spelling.  Do not
keep the misspelling as a deprecated alias, as it was never part of the
documented interface, and the short -ap option has always worked; it now
gets the usual unknown option error, which names the offending option.

Document the option in the man page, which has been missing an entry for
it all along.
---
 man/dpkg-buildpackage.pod     |  7 +++++++
 scripts/dpkg-buildpackage.pl  |  2 +-
 scripts/t/dpkg_buildpackage.t | 17 ++++++++++++++++-
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/man/dpkg-buildpackage.pod b/man/dpkg-buildpackage.pod
index cd49ba2d0..89eb110a8 100644
--- a/man/dpkg-buildpackage.pod
+++ b/man/dpkg-buildpackage.pod
@@ -731,6 +731,13 @@ password.

 Supported since dpkg 1.21.10.

+=item B<-ap>, B<--sign-pause>
+
+Wait for the user to press B<Enter> before starting the signing process.
+This only has an effect if at least one file is going to be signed.
+
+Support for long option since dpkg 1.23.12.
+
 =item B<-us>, B<--unsigned-source>

 Do not sign the source package.
diff --git a/scripts/dpkg-buildpackage.pl b/scripts/dpkg-buildpackage.pl
index f057a64cf..3e41911d9 100755
--- a/scripts/dpkg-buildpackage.pl
+++ b/scripts/dpkg-buildpackage.pl
@@ -545,7 +545,7 @@ while (@ARGV) {
     } elsif (/^-uc$/ or /^--unsigned-changes$/) {
         $signbuildinfo = 0;
         $signchanges = 0;
-    } elsif (/^-ap$/ or /^--sign-pausa$/) {
+    } elsif (/^-ap$/ or /^--sign-pause$/) {
         $signpause = 1;
     } elsif (/^-a$/ or /^--host-arch$/) {
         $host_arch = shift;
diff --git a/scripts/t/dpkg_buildpackage.t b/scripts/t/dpkg_buildpackage.t
index cbfe03b78..405388831 100644
--- a/scripts/t/dpkg_buildpackage.t
+++ b/scripts/t/dpkg_buildpackage.t
@@ -29,7 +29,7 @@ use Dpkg::BuildTypes;
 use Dpkg::Substvars;

 test_needs_command('fakeroot');
-plan tests => 17;
+plan tests => 18;

 my $srcdir = rel2abs($ENV{srcdir} || '.');
 my $datadir = "$srcdir/t/dpkg_buildpackage";
@@ -52,6 +52,21 @@ $ENV{PATH} = "$srcdir/t/mock-bin:$ENV{PATH}";

 chdir $tmpdir;

+my $stderr;
+
+spawn(
+    exec => [
+        $ENV{PERL}, "$srcdir/dpkg-buildpackage.pl",
+        '--sign-pause', '--help',
+    ],
+    to_file => '/dev/null',
+    error_to_string => \$stderr,
+    wait_child => 1,
+    no_check => 1,
+);
+ok($? == 0 && $stderr eq '', '--sign-pause is accepted');
+diag($stderr) unless $? == 0;
+
 my $tmpl_format = <<'TMPL_FORMAT';
 3.0 (native)
 TMPL_FORMAT

#1061450#52
Date:
2026-10-30 11:44:03 UTC
From:
To:
Follow the layout and idioms of the dpkg-source completion, using the
bash-completion 2.12 API.  Complete option names, and values for the
options that take one: build types, rules targets, architectures via
dpkg-architecture --list-known, build profiles, OpenPGP backends,
compression parameters, hook and other command arguments, pathname
arguments, and the positional .dsc filename or source directory.
Unlike dpkg-source, split the words on "=" and complete the long options
in that spelling, as many of them only accept a value in that form.

The options taking a comma-separated list (--build, --rules-target and
--build-profiles) are completed element per element, and the ones taking
an optional value only in the "=" form (--jobs and friends,
--diff-ignore and --tar-ignore) offer both spellings.

The --buildinfo-id, -E and -W options, which are accepted but without
effect, are intentionally not completed.

Closes: #1061450
---
 debian/copyright                          |   1 +
 debian/dpkg-dev.install                   |   1 +
 scripts/Makefile.am                       |   1 +
 scripts/completion/bash/dpkg-buildpackage | 170 ++++++++++++++++++++++
 4 files changed, 173 insertions(+)
 create mode 100644 scripts/completion/bash/dpkg-buildpackage

diff --git a/debian/copyright b/debian/copyright
index d8a445fd1..7ddcf9e6c 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -87,6 +87,7 @@ Copyright:
  Copyright © 2018 Uwe Storbeck <uwe@ibr.ch>
  Copyright © 2021-2024 Koichi Murase <myoga.murase@gmail.com>
  Copyright © 2024 Arnaud Rebillout <arnaudr@kali.org>
+ Copyright © 2026 Cheng Li <shiptux@gmail.com>
  Copyright © 2026 Guillem Jover <guillem@debian.org>
 License: GPL-2+

diff --git a/debian/dpkg-dev.install b/debian/dpkg-dev.install
index 3d87080cc..4a509496a 100644
--- a/debian/dpkg-dev.install
+++ b/debian/dpkg-dev.install
@@ -21,6 +21,7 @@ usr/bin/dpkg-scansources
 usr/bin/dpkg-shlibdeps
 usr/bin/dpkg-source
 usr/bin/dpkg-vendor
+usr/share/bash-completion/completions/dpkg-buildpackage
 usr/share/bash-completion/completions/dpkg-source
 usr/share/dpkg/*.mk
 usr/share/zsh/vendor-completions/_dpkg-parsechangelog
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 0fa3165bf..4d91e602c 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -155,6 +155,7 @@ CLEANFILES += \
 	# EOL

 dist_bashcompletions_DATA = \
+	completion/bash/dpkg-buildpackage \
 	completion/bash/dpkg-source \
 	# EOL

diff --git a/scripts/completion/bash/dpkg-buildpackage b/scripts/completion/bash/dpkg-buildpackage
new file mode 100644
index 000000000..3497e309a
--- /dev/null
+++ b/scripts/completion/bash/dpkg-buildpackage
@@ -0,0 +1,170 @@
+#!/bin/bash
+# dpkg-buildpackage(1) bash completion
+#
+# Copyright © 2026 Cheng Li <shiptux@gmail.com>
+#
+# 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, see <https://www.gnu.org/licenses/>.
+
+_comp_cmd_dpkg_buildpackage()
+{
+  # shellcheck disable=SC2034
+  local cur prev words cword was_split comp_args
+  _comp_initialize -s -- "$@" || return
+
+  local -a options buildtypes rulestargets hookopts sourceopts
+  local hook
+
+  buildtypes=(
+    source
+    any
+    all
+    binary
+    full
+  )
+  rulestargets=(
+    clean
+    build
+    build-arch
+    build-indep
+    binary
+    binary-arch
+    binary-indep
+  )
+  hookopts=()
+  for hook in preinit init preclean source build binary buildinfo \
+              changes postclean check sign 'done'; do
+    hookopts+=("--hook-$hook=")
+  done
+  sourceopts=(
+    -si -sa -sd
+    -sn -ss -sA -sk -su -sr -sK -sU -sR
+    -i --diff-ignore --diff-ignore=
+    -I --tar-ignore --tar-ignore=
+    -z --compression-level=
+    -Z --compression=
+    --source-option=
+  )
+  options=(
+    --help --version
+    --admindir=
+    --build=
+    -b -B -A -S -G -g -F
+    -T --target= --rules-target=
+    --as-root
+    --rules-requires-root
+    -R --rules-file=
+    --pre-clean -nc --no-pre-clean
+    -tc --post-clean --no-post-clean
+    --sanitize-env
+    -d -D --check-builddeps --no-check-builddeps
+    --ignore-builtin-builddeps
+    -j -J --jobs --jobs= --jobs-try --jobs-try= --jobs-force --jobs-force=
+    -a --host-arch=
+    -t --host-type=
+    --target-arch= --target-type=
+    -P --build-profiles=
+    -v -C
+    -m --source-by= --build-by=
+    -e --changed-by= --release-by=
+    --changes-option= --changes-file=
+    --buildinfo-option= --buildinfo-file=
+    --check-command= --check-option=
+    -r --root-command=
+    --sign-backend=
+    -p --sign-command=
+    --sign-keyfile=
+    -k --sign-keyid=
+    --sign-key=
+    --force-sign --no-sign
+    -us --unsigned-source
+    -ui --unsigned-buildinfo
+    -uc --unsigned-changes
+    -ap --sign-pause
+    "${hookopts[@]}"
+    "${sourceopts[@]}"
+  )
+
+  case $prev in
+  --admindir)
+    _comp_compgen_filedir -d
+    return
+    ;;
+  --build)
+    _comp_delimited , -W "${buildtypes[*]}"
+    return
+    ;;
+  -T | --target | --rules-target)
+    _comp_delimited , -W "${rulestargets[*]}"
+    return
+    ;;
+  -a | --host-arch | --target-arch)
+    _comp_compgen_split -- "$(command dpkg-architecture --list-known 2>/dev/null)"
+    return
+    ;;
+  --build-profiles)
+    # Complete the registered common profiles.
+    _comp_delimited , -W 'cross nocheck nodoc noinsttest nopython noudeb
+      stage1 stage2'
+    return
+    ;;
+  --rules-file | --sign-keyfile | --buildinfo-file | --changes-file)
+    _comp_compgen_filedir
+    return
+    ;;
+  --root-command | --sign-command | --check-command | --hook-*)
+    _comp_compgen_commands
+    return
+    ;;
+  --sign-backend)
+    _comp_compgen -- -W 'auto gpg sq sop'
+    return
+    ;;
+  --compression)
+    _comp_compgen -- -W 'gzip xz bzip2 lzma'
+    return
+    ;;
+  --compression-level)
+    _comp_compgen -- -W '{0..9}'
+    return
+    ;;
+  --jobs | --jobs-try | --jobs-force)
+    # These options accept an optional value only in the = form.
+    [[ $was_split ]] || return
+    _comp_compgen -- -W 'auto'
+    return
+    ;;
+  -t | --host-type | --target-type)
+    # GNU system types, no sensible completion.
+    return
+    ;;
+  --source-by | --build-by | --changed-by | --release-by | \
+  --sign-key | --sign-keyid | --source-option | --changes-option | \
+  --buildinfo-option | --check-option)
+    # Free-form values, no sensible completion.
+    return
+    ;;
+  esac
+
+  # A value glued to a long option with "=" was already handled above.
+  [[ $was_split ]] && return
+
+  if [[ $cur == -* ]]; then
+    _comp_compgen -- -W "${options[*]}"
+    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
+    return
+  fi
+
+  # The optional positional argument is a .dsc file or a source directory.
+  _comp_compgen_filedir 'dsc'
+} && complete -F _comp_cmd_dpkg_buildpackage dpkg-buildpackage

#1061450#57
Date:
2026-10-31 19:41:39 UTC
From:
To:
Hi!

Thanks!

Nice catch, perfect! I've merged this locally and will include in my
next push.

Ah, thanks! I had also started adding the missing completions for all
commands last month, and ended up partially doing dpkg-buildpackage,
in the following WIP pu/bash-completions branch from this repo, which
I just rebased and pushed to:

  <https://git.hadrons.org/cgit/debian/dpkg/dpkg.git>

But it seems some of my changes complement some of yours. So it would
make sense if you adopted some of those into your patch?

Sure, it is expected that we add explicit lines for each new script,
instead of using globs, so that we control when something appears or
disappears (on purpose or by accident).

Ah great!

Right, it looks I was also bothered by this, and ended up adding negated
entries (in a commit in that branch). But I think I do prefer your
proposed fix better. So feel free to provide a patch for that.

Nice catch as well. I was curious whether the current completion files
were fine, so added this locally now (with attribution), and fixed a
couple of issues with the dpkg-deb completion.

No worries, this is good.

Thanks,
Guillem

#1061450#62
Date:
2026-11-03 08:38:37 UTC
From:
To:
Hi Guillem,

Here is v2 of the series. It no longer contains the --sign-pause fix,
since you have merged that locally already. Patch 1/2 is new (the
.gitignore change), and patch 2/2 is the updated completion file.

I fetched your pu/bash-completions branch (4198c5e9b) and compared it
with mine. I adopted your approach of completing --sign-command with a
curated list: mine used _comp_compgen_commands, which expands to 7024
entries here, so it was not usable interactively.

My values differ from yours in two ways. First, neither auto nor none is
offered, as dpkg-buildpackage validates the value with find_command()
before it reaches the backend (scripts/dpkg-buildpackage.pl:674), so
both error out with "sign-command 'auto' not found". Second, the *v
commands (sqopv, rsopv, sqv, gpgv-sq and gpgv) are the verification
commands (DEFAULT_CMDV), rather than the signing ones. The final list is
the DEFAULT_CMD of each supported backend, in the backend preference
order from dpkg-buildpackage(1).

I did not adopt -x dpkg_architecture, because the xfunc is defined in
the dpkg-architecture completion file, which is not in main yet; adding
it now makes --host-arch complete nothing. I will switch to it once that
file lands.

Patch 1/2 does this. It anchors every entry in scripts/, src/, dselect/
and utils/, which are the four directories containing a completion/bash/
subdirectory. Once it is applied, the negated entries you added in
3c498a0c3 will no longer be needed.

Thank you, both for adding the test and for the attribution.

Best regards,
Cheng Li

#1061450#67
Date:
2026-11-03 08:38:38 UTC
From:
To:
All the entries in these four directories name files generated at the
top level of the directory, but none of them is anchored, so they also
match any file with the same name in a subdirectory.

The bash completion files are named after the programs they complete and
live in <dir>/completion/bash/, so each of them is currently matched by
the entry for its own generated program.  Adding a new completion file
needs git add -f, and git add -A skips it silently.

Anchor every entry with a leading "/" so that it only matches the
generated file it is meant to match.

Ref: #1061450
---
 dselect/.gitignore |  6 +++---
 scripts/.gitignore | 48 +++++++++++++++++++++++-----------------------
 src/.gitignore     | 24 +++++++++++------------
 utils/.gitignore   |  8 ++++----
 4 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/dselect/.gitignore b/dselect/.gitignore
index bba6d3455..20629e6cf 100644
--- a/dselect/.gitignore
+++ b/dselect/.gitignore
@@ -1,3 +1,3 @@
-curkeys.h
-curkeys.hpp
-dselect
+/curkeys.h
+/curkeys.hpp
+/dselect
diff --git a/scripts/.gitignore b/scripts/.gitignore
index 8bbf4e05b..17c8d7d89 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -1,24 +1,24 @@
-Build.PL
-README.cpan
-dpkg-architecture
-dpkg-buildapi
-dpkg-buildflags
-dpkg-buildpackage
-dpkg-buildtree
-dpkg-checkbuilddeps
-dpkg-distaddfile
-dpkg-genbuildinfo
-dpkg-genchanges
-dpkg-gencontrol
-dpkg-gensymbols
-dpkg-mergechangelogs
-dpkg-name
-dpkg-parsechangelog
-dpkg-scanpackages
-dpkg-scansources
-dpkg-shlibdeps
-dpkg-source
-dpkg-statoverride
-dpkg-vendor
-t.tmp
-cover_db
+/Build.PL
+/README.cpan
+/dpkg-architecture
+/dpkg-buildapi
+/dpkg-buildflags
+/dpkg-buildpackage
+/dpkg-buildtree
+/dpkg-checkbuilddeps
+/dpkg-distaddfile
+/dpkg-genbuildinfo
+/dpkg-genchanges
+/dpkg-gencontrol
+/dpkg-gensymbols
+/dpkg-mergechangelogs
+/dpkg-name
+/dpkg-parsechangelog
+/dpkg-scanpackages
+/dpkg-scansources
+/dpkg-shlibdeps
+/dpkg-source
+/dpkg-statoverride
+/dpkg-vendor
+/t.tmp
+/cover_db
diff --git a/src/.gitignore b/src/.gitignore
index 3a122bf11..13279a60d 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,12 +1,12 @@
-dpkg
-dpkg-db-backup
-dpkg-db-keeper
-dpkg-deb
-dpkg-divert
-dpkg-maintscript-helper
-dpkg-query
-dpkg-realpath
-dpkg-split
-dpkg-statoverride
-dpkg-trigger
-t.tmp
+/dpkg
+/dpkg-db-backup
+/dpkg-db-keeper
+/dpkg-deb
+/dpkg-divert
+/dpkg-maintscript-helper
+/dpkg-query
+/dpkg-realpath
+/dpkg-split
+/dpkg-statoverride
+/dpkg-trigger
+/t.tmp
diff --git a/utils/.gitignore b/utils/.gitignore
index edc11e367..005b37350 100644
--- a/utils/.gitignore
+++ b/utils/.gitignore
@@ -1,4 +1,4 @@
-org.dpkg.pkexec.update-alternatives.policy
-start-stop-daemon
-update-alternatives
-t.tmp
+/org.dpkg.pkexec.update-alternatives.policy
+/start-stop-daemon
+/update-alternatives
+/t.tmp

#1061450#72
Date:
2026-11-03 08:38:39 UTC
From:
To:
Follow the layout and idioms of the dpkg-source completion, using the
bash-completion 2.12 API.  Complete option names, and values for the
options that take one: build types, rules targets, architectures via
dpkg-architecture --list-known, build profiles, OpenPGP backends and
signing commands, compression parameters, hook and other command
arguments, pathname arguments, and the positional .dsc filename or
source directory.
Unlike dpkg-source, split the words on "=" and complete the long options
in that spelling, as many of them only accept a value in that form.

The options taking a comma-separated list (--build, --rules-target and
--build-profiles) are completed element per element, and the ones taking
an optional value only in the "=" form (--jobs and friends,
--diff-ignore and --tar-ignore) offer both spellings.

For --sign-command, complete the signing commands of the supported
OpenPGP backends rather than any command name, as those are the expected
values.  Unlike for --sign-backend, "auto" and "none" are not offered,
as the value is looked up in PATH and both would error out.

The --buildinfo-id, -E and -W options, which are accepted but without
effect, are intentionally not completed.

Improved-by: Guillem Jover <guillem@debian.org>
Closes: #1061450
---
 debian/copyright                          |   1 +
 debian/dpkg-dev.install                   |   1 +
 scripts/Makefile.am                       |   1 +
 scripts/completion/bash/dpkg-buildpackage | 177 ++++++++++++++++++++++
 4 files changed, 180 insertions(+)
 create mode 100644 scripts/completion/bash/dpkg-buildpackage

diff --git a/debian/copyright b/debian/copyright
index d8a445fd1..7ddcf9e6c 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -87,6 +87,7 @@ Copyright:
  Copyright © 2018 Uwe Storbeck <uwe@ibr.ch>
  Copyright © 2021-2024 Koichi Murase <myoga.murase@gmail.com>
  Copyright © 2024 Arnaud Rebillout <arnaudr@kali.org>
+ Copyright © 2026 Cheng Li <shiptux@gmail.com>
  Copyright © 2026 Guillem Jover <guillem@debian.org>
 License: GPL-2+

diff --git a/debian/dpkg-dev.install b/debian/dpkg-dev.install
index 3d87080cc..4a509496a 100644
--- a/debian/dpkg-dev.install
+++ b/debian/dpkg-dev.install
@@ -21,6 +21,7 @@ usr/bin/dpkg-scansources
 usr/bin/dpkg-shlibdeps
 usr/bin/dpkg-source
 usr/bin/dpkg-vendor
+usr/share/bash-completion/completions/dpkg-buildpackage
 usr/share/bash-completion/completions/dpkg-source
 usr/share/dpkg/*.mk
 usr/share/zsh/vendor-completions/_dpkg-parsechangelog
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 0fa3165bf..4d91e602c 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -155,6 +155,7 @@ CLEANFILES += \
 	# EOL

 dist_bashcompletions_DATA = \
+	completion/bash/dpkg-buildpackage \
 	completion/bash/dpkg-source \
 	# EOL

diff --git a/scripts/completion/bash/dpkg-buildpackage b/scripts/completion/bash/dpkg-buildpackage
new file mode 100644
index 000000000..315f7f26a
--- /dev/null
+++ b/scripts/completion/bash/dpkg-buildpackage
@@ -0,0 +1,177 @@
+#!/bin/bash
+# dpkg-buildpackage(1) bash completion
+#
+# Copyright © 2026 Cheng Li <shiptux@gmail.com>
+#
+# 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, see <https://www.gnu.org/licenses/>.
+
+_comp_cmd_dpkg_buildpackage()
+{
+  # shellcheck disable=SC2034
+  local cur prev words cword was_split comp_args
+  _comp_initialize -s -- "$@" || return
+
+  local -a options buildtypes rulestargets hookopts sourceopts
+  local hook
+
+  buildtypes=(
+    source
+    any
+    all
+    binary
+    full
+  )
+  rulestargets=(
+    clean
+    build
+    build-arch
+    build-indep
+    binary
+    binary-arch
+    binary-indep
+  )
+  hookopts=()
+  for hook in preinit init preclean source build binary buildinfo \
+              changes postclean check sign 'done'; do
+    hookopts+=("--hook-$hook=")
+  done
+  sourceopts=(
+    -si -sa -sd
+    -sn -ss -sA -sk -su -sr -sK -sU -sR
+    -i --diff-ignore --diff-ignore=
+    -I --tar-ignore --tar-ignore=
+    -z --compression-level=
+    -Z --compression=
+    --source-option=
+  )
+  options=(
+    --help --version
+    --admindir=
+    --build=
+    -b -B -A -S -G -g -F
+    -T --target= --rules-target=
+    --as-root
+    --rules-requires-root
+    -R --rules-file=
+    --pre-clean -nc --no-pre-clean
+    -tc --post-clean --no-post-clean
+    --sanitize-env
+    -d -D --check-builddeps --no-check-builddeps
+    --ignore-builtin-builddeps
+    -j -J --jobs --jobs= --jobs-try --jobs-try= --jobs-force --jobs-force=
+    -a --host-arch=
+    -t --host-type=
+    --target-arch= --target-type=
+    -P --build-profiles=
+    -v -C
+    -m --source-by= --build-by=
+    -e --changed-by= --release-by=
+    --changes-option= --changes-file=
+    --buildinfo-option= --buildinfo-file=
+    --check-command= --check-option=
+    -r --root-command=
+    --sign-backend=
+    -p --sign-command=
+    --sign-keyfile=
+    -k --sign-keyid=
+    --sign-key=
+    --force-sign --no-sign
+    -us --unsigned-source
+    -ui --unsigned-buildinfo
+    -uc --unsigned-changes
+    -ap --sign-pause
+    "${hookopts[@]}"
+    "${sourceopts[@]}"
+  )
+
+  case $prev in
+  --admindir)
+    _comp_compgen_filedir -d
+    return
+    ;;
+  --build)
+    _comp_delimited , -W "${buildtypes[*]}"
+    return
+    ;;
+  -T | --target | --rules-target)
+    _comp_delimited , -W "${rulestargets[*]}"
+    return
+    ;;
+  -a | --host-arch | --target-arch)
+    _comp_compgen_split -- "$(command dpkg-architecture --list-known 2>/dev/null)"
+    return
+    ;;
+  --build-profiles)
+    # Complete the registered common profiles.
+    _comp_delimited , -W 'cross nocheck nodoc noinsttest nopython noudeb
+      stage1 stage2'
+    return
+    ;;
+  --rules-file | --sign-keyfile | --buildinfo-file | --changes-file)
+    _comp_compgen_filedir
+    return
+    ;;
+  --root-command | --check-command | --hook-*)
+    _comp_compgen_commands
+    return
+    ;;
+  --sign-backend)
+    _comp_compgen -- -W 'auto gpg sq sop'
+    return
+    ;;
+  --sign-command)
+    # The signing commands of the supported OpenPGP backends, in backend
+    # preference order.  The value is looked up in PATH, so unlike for
+    # --sign-backend, "auto" and "none" are not accepted here.
+    _comp_compgen -- -W 'sqop rsop gosop hop pgpainless-cli sq gpg-sq gpg'
+    return
+    ;;
+  --compression)
+    _comp_compgen -- -W 'gzip xz bzip2 lzma'
+    return
+    ;;
+  --compression-level)
+    _comp_compgen -- -W '{0..9}'
+    return
+    ;;
+  --jobs | --jobs-try | --jobs-force)
+    # These options accept an optional value only in the = form.
+    [[ $was_split ]] || return
+    _comp_compgen -- -W 'auto'
+    return
+    ;;
+  -t | --host-type | --target-type)
+    # GNU system types, no sensible completion.
+    return
+    ;;
+  --source-by | --build-by | --changed-by | --release-by | \
+  --sign-key | --sign-keyid | --source-option | --changes-option | \
+  --buildinfo-option | --check-option)
+    # Free-form values, no sensible completion.
+    return
+    ;;
+  esac
+
+  # A value glued to a long option with "=" was already handled above.
+  [[ $was_split ]] && return
+
+  if [[ $cur == -* ]]; then
+    _comp_compgen -- -W "${options[*]}"
+    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
+    return
+  fi
+
+  # The optional positional argument is a .dsc file or a source directory.
+  _comp_compgen_filedir 'dsc'
+} && complete -F _comp_cmd_dpkg_buildpackage dpkg-buildpackage