chiark / gitweb /
Break out remove_stray_gits
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 9e2e66e4841b4adb690225fab1def69b6229df6d..31b08d3ea46a6e1ed90ab2b586ae63234d7c4cb4 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -1139,6 +1139,22 @@ sub git_write_tree () {
     return $tree;
 }
 
+sub remove_stray_gits () {
+    my @gitscmd = qw(find -name .git -prune -print0);
+    debugcmd "|",@gitscmd;
+    open GITS, "-|", @gitscmd or failedcmd @gitscmd;
+    {
+       local $/="\0";
+       while (<GITS>) {
+           chomp or die;
+           print STDERR "$us: warning: removing from source package: ",
+               (messagequote $_), "\n";
+           rmtree $_;
+       }
+    }
+    $!=0; $?=0; close GITS or failedcmd @gitscmd;
+}
+
 sub mktree_in_ud_from_only_subdir () {
     # changes into the subdir
     my (@dirs) = <*/.>;
@@ -1146,7 +1162,8 @@ sub mktree_in_ud_from_only_subdir () {
     $dirs[0] =~ m#^([^/]+)/\.$# or die;
     my $dir = $1;
     changedir $dir;
-    fail "source package contains .git directory" if stat_exists '.git';
+
+    remove_stray_gits();
     mktree_in_ud_here();
     my $format=get_source_format();
     if (madformat($format)) {