Переглянути джерело

support dpkg-source -i for overriding git WC cleanliness check

Joey Hess 19 роки тому
батько
коміт
02a9822835
3 змінених файлів з 37 додано та 10 видалено
  1. 3 1
      man/dpkg-source.1
  2. 33 8
      scripts/Dpkg/Source/VCS/git.pm
  3. 1 1
      scripts/dpkg-source.pl

+ 3 - 1
man/dpkg-source.1

@@ -113,7 +113,9 @@ This option negates a previously set
 .BR \-i [\fIregexp\fP]
 You may specify a perl regular expression to match files you want
 filtered out of the list of files for the diff. (This list is
-generated by a find command.) \fB\-i\fR by itself enables the option,
+generated by a find command.) (If the source package is being built as a
+version 3 source package using a VCS, this is instead used to
+ignore uncommitted files.) \fB\-i\fR by itself enables the option,
 with a default that will filter out control files and directories of the
 most common revision control systems, backup and swap files and Libtool
 build output directories. There can only be one active regexp, of multiple

+ 33 - 8
scripts/Dpkg/Source/VCS/git.pm

@@ -63,8 +63,8 @@ sub prep_tar {
 	}
 
 	# Check for uncommitted files.
-	open(GIT_STATUS, "LANG=C cd $srcdir && git status |") ||
-		main::subprocerr("cd $srcdir && git status");
+	open(GIT_STATUS, "LANG=C cd $srcdir && git-status |") ||
+		main::subprocerr("cd $srcdir && git-status");
 	my $clean=0;
 	my $status="";
 	while (<GIT_STATUS>) {
@@ -83,11 +83,36 @@ sub prep_tar {
 		main::subprocerr("cd $srcdir && git status");
 	}
 	if (! $clean) {
-		# TODO support dpkg-buildpackage -i and allow building with
-		# modified ignored files. This requires a way to get a list
-		# of files, and git-status's output is too evil to parse.
-		print $status;
-		main::error(_g("uncommitted changes in working directory"));
+		# To support dpkg-buildpackage -i, get a list of files
+		# eqivilant to the ones git-status finds, and remove any
+		# ignored files from it.
+		my $core_excludesfile=`cd $srcdir && git-config --get core.excludesfile`;
+		chomp $core_excludesfile;
+		my @ignores="--exclude-per-directory=.gitignore";
+		if (-e "$srcdir/$core_excludesfile") {
+			push @ignores, "--exclude-from='$core_excludesfile'";
+		}
+		if (-e "$srcdir/.git/info/exclude") {
+			push @ignores, "--exclude-from=.git/info/exclude";
+		}
+		open(GIT_LS_FILES, "cd $srcdir && git-ls-files -m -d -o @ignores |") ||
+			main::subprocerr("cd $srcdir && git-ls-files");
+		my @files;
+		while (<GIT_LS_FILES>) {
+			chomp;
+			if (! defined $main::diff_ignore_regexp ||
+			    ! length $main::diff_ignore_regexp ||
+			    ! m/$main::diff_ignore_regexp/o) {
+				push @files, $_;
+			}
+		}
+		close(GIT_LS_FILES) || main::syserr("git-ls-files exited nonzero");
+
+		if (@files) {
+			print $status;
+			main::error(_g("uncommitted, not-ignored changes in working directory: %s"),
+				join(" ", @files));
+		}
 	}
 
 	# garbage collect the repo
@@ -123,7 +148,7 @@ sub post_unpack_tar {
 	}
 	
 	# This is a paranoia measure, since the index is not normally
-	# provided by possible-untrusted third parties, remove it if
+	# provided by possibly-untrusted third parties, remove it if
 	# present (git-rebase will recreate it).
 	unlink("$srcdir/.git/index") ||
 		main::syserr(sprintf(_g("unable to remove `%s'"), "$srcdir/.git/index"));

+ 1 - 1
scripts/dpkg-source.pl

@@ -17,7 +17,7 @@ my $controlfile;
 my $changelogfile;
 my $changelogformat;
 
-my $diff_ignore_regexp = '';
+our $diff_ignore_regexp = '';
 my $diff_ignore_default_regexp = '
 # Ignore general backup files
 (?:^|/).*~$|