path: root/dgit
diff options
authorIan Jackson <>2018-10-13 13:12:39 +0100
committerIan Jackson <>2018-10-13 16:46:29 +0100
commit79514d6b2708624a62c0e72c2ff0565682b310bf (patch)
tree5a9652cfa317fd533beb8168a55c442ab1cc8183 /dgit
parentd2a8267aca1cc401561e0e7ac7aa9d6f3e315879 (diff)
dgit: --clean=dpkg-source: Check for untracked unignored files
We would like to spot if the user forgot to `git add' a file. This can be done by calling clean_tree_check_git, after rules clean (if applicable). We need to make this configurable. We do so via the clean mode, with a comma-separated checking control suffix (and short aliases) like we did for --clean=git,ignores. The default should be cautious, ie to do this check, but often the user will want to disable it because the source package has a buggy clean target or no or insufficient .gitignore. Existing users should probably get the new check until they choose otherwise (which we have made easier for them with the .clean-mode-newer config option). So we change the meanings of -wd and -wdd to include the new check, and provide new build modes ...,no-check aka -wdn / -wddn to disable it. To implement this we introduce a new clean_tree_check_git_wd function to do the actual work, particularly because both during cleaning and cleanliness checking, we want to print some hints to the user if the check fails. We can't do the new check if we applied patches dirtily to run the rules target, because it will trip over the result of patch application. This way of working is just too poor to support this new check. The test suite generally tests the default versions, not the no-check versions. We must teach the test to expect the new check. This is most easily done with a separate case for the check side of the -wd clean modes. And we need to support the no-check variant too, because: The push-source-with-changes test does in fact work with a built tree and needs to test the no-check variant. The gbp tests sometimes involve patch application. Rather than trying to predict which of them do (in which cases there would be no clean check), we force them all to ,no-check. The oldnewtagalt test can use -wgf. Signed-off-by: Ian Jackson <>
Diffstat (limited to 'dgit')
1 files changed, 21 insertions, 2 deletions
diff --git a/dgit b/dgit
index 57e1e40..654b3d1 100755
--- a/dgit
+++ b/dgit
@@ -101,7 +101,7 @@ our %forceopts = map { $_=>0 }
our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)");
our $suite_re = '[-+.0-9a-z]+';
-our $cleanmode_re = qr{(?: dpkg-source (?: -d )?
+our $cleanmode_re = qr{(?: dpkg-source (?: -d )? (?: ,no-check )?
| git | git-ff
| check (?: ,ignores )?
| none
@@ -6214,6 +6214,19 @@ sub clean_tree_check_git ($$) {
+sub clean_tree_check_git_wd ($) {
+ my ($message) = @_;
+ return if $cleanmode =~ m{no-check};
+ return if $patches_applied_dirtily; # yuk
+ clean_tree_check_git 1,
+ (f_ <<END, $message);
+If this is just missing .gitignore entries, use a different clean
+mode, eg --clean=dpkg-source,no-check (-wdu/-wddu) to ignore them
+or --clean=git (-wg/-wgf) to use \`git clean' instead.
sub clean_tree_check () {
# Not yet fully implemented.
# This function needs to not care about modified but tracked files.
@@ -6222,6 +6235,9 @@ sub clean_tree_check () {
if ($cleanmode =~ m{^check}) {
clean_tree_check_git +($cleanmode =~ m{ignores}), __
"tree contains uncommitted files and --clean=check specified";
+ } elsif ($cleanmode =~ m{^dpkg-source}) {
+ clean_tree_check_git_wd __
+ "tree contains uncommitted files (NB dgit didn't run rules clean)";
@@ -6234,6 +6250,8 @@ sub clean_tree () {
push @cmd, qw(-T clean);
runcmd_ordryrun_local @cmd;
+ clean_tree_check_git_wd __
+ "tree contains uncommitted files (after running rules clean)";
} elsif ($cleanmode eq 'git') {
runcmd_ordryrun_local @git, qw(clean -xdf);
} elsif ($cleanmode eq 'git-ff') {
@@ -7262,10 +7280,11 @@ sub parseopts () {
} elsif (s/^-wgf$//s) {
push @ropts, $&;
$cleanmode = 'git-ff';
- } elsif (s/^-wd(d?)$//s) {
+ } elsif (s/^-wd(d?)([n]?)$//s) {
push @ropts, $&;
$cleanmode = 'dpkg-source';
$cleanmode .= '-d' if $1;
+ $cleanmode .= ',no-check' if $2 eq 'n';
} elsif (s/^-wc$//s) {
push @ropts, $&;
$cleanmode = 'check';