git.pm 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/perl
  2. # git support for dpkg-source
  3. package Dpkg::Source::VCS::git;
  4. use strict;
  5. use warnings;
  6. use Dpkg;
  7. use Dpkg::Gettext;
  8. push (@INC, $dpkglibdir);
  9. require 'controllib.pl';
  10. # Called before a tarball is created, must add all files that should be in
  11. # it.
  12. sub prep_tar {
  13. my $srcdir=shift;
  14. my $tardir=shift;
  15. # check for uncommitted files
  16. open(GIT_STATUS, "LANG=C cd $srcdir && git status |") ||
  17. subprocerr("cd $srcdir && git status");
  18. my $clean=0;
  19. my $status="";
  20. while (<GIT_STATUS>) {
  21. if (/^\Qnothing to commit (working directory clean)\E$/) {
  22. $clean=1;
  23. }
  24. $status.=$_;
  25. }
  26. close GIT_STATUS;
  27. # git-status exits 1 if there are uncommitted changes or if
  28. # the repo is clean, and 0 if there are uncommitted changes
  29. # listed in the index.
  30. if ($? && $? >> 8 != 1) {
  31. print $status;
  32. warnerror("working directory is not clean (use -W to override this check)");
  33. }
  34. # garbage collect the repo
  35. system("cd $srcdir && git-gc --prune");
  36. $? && subprocerr("cd $srcdir && git-gc --prune");
  37. # TODO support for creating a shallow clone for those cases where
  38. # uploading the whole repo history is not desired
  39. system("cp -a $srcdir/.git $tardir");
  40. $? && subprocerr("cp -a $srcdir/.git $tardir");
  41. }
  42. # Called after a tarball is unpacked, to check out the working copy.
  43. sub post_unpack_tar {
  44. my $srcdir=shift;
  45. # TODO disable git hooks
  46. # XXX git should be made to run in quiet mode here, but
  47. # lacks a good way to do it. Bug filed.
  48. system("cd $srcdir && git-reset --hard");
  49. $? && subprocerr("cd $srcdir && git-reset --hard");
  50. }
  51. 1