chiark / gitweb /
tg2quilt.mk: don't call git-status with git-commit options
[topgit.git] / debian / tg2quilt.mk
index 2ff9bc9a754f7cc051143ef3952cecdc8caf7534..744b853a4e41a156748e41e6135851c38641eabc 100644 (file)
@@ -31,7 +31,9 @@
 #                  target, and invokes tg-rmdir
 #
 #        tg-rmdir: tries to remove debian/patches, but only if there are no
-#                  non-TopGit files under the directory.
+#                  non-TopGit files under the directory, the repository has
+#                  no uncommitted changes, and there are not quilt patches
+#                  applied.
 #                    The heuristic is to find files that do not contain a line
 #                  matchines /^tg:/, minus the series file. If any such files
 #                  are found, an error occurs. Otherwise, the directory is
@@ -68,11 +70,16 @@ else
 
 # We are in a TopGit branch, so let the fun begin.
 
-ifdef (PATCHES_DIR)
-       @echo 'W: The $PATCHES_DIR variable is deprecated, please use $QUILT_PATCH_DIR instead' >&2
+ifdef PATCHES_DIR
+       DUMMY := $(warning W: The $$PATCHES_DIR variable is deprecated, please use $$QUILT_PATCH_DIR instead.)
+       DUMMY := $(warning W: Sleeping for 10 seconds so you can read this!)
+       DUMMY := $(shell sleep 10)
        QUILT_PATCH_DIR := $(PATCHES_DIR)
 endif
 
+QUILT_PATCH_DIR ?= debian/patches
+QUILT_STAMPFN ?= patch
+
 # Hook tg-export into quilt's make(1) snippet such that it gets executed
 # before quilt patches or unpatches.
 $(QUILT_STAMPFN): tg-export
@@ -115,12 +122,26 @@ else
   tg-rmdir: __TG_FILES := $(shell find $(QUILT_PATCH_DIR) -type f -a -not -path \*/series \
                                     | xargs grep -l '^tg:')
   tg-rmdir:
+       QUILT_PATCHES=$(QUILT_PATCH_DIR) quilt pop -a 2>/dev/null || :
+       @if quilt applied >/dev/null 2>&1; then \
+         echo "E: there are applied quilt patches." >&2; \
+         echo "E: please unapply (pop) all patches and try again." >&2; \
+         false; \
+       fi
+       @git update-index -q --ignore-submodules --refresh
+       @if git diff-index --quiet --cached HEAD --ignore-submodules -- > /dev/null || git diff-files --quiet --ignore-submodules > /dev/null; then \
+         echo "E: there are uncommitted changes in the working directory." >&2; \
+         echo "E: please commit or revert all changes." >&2; \
+         false; \
+       fi
        # remove all files whose contents matches /^tg:/
-       test -n "$(__TG_FILES)" && rm $(__TG_FILES) || :
-        # remove the series file
-       test -f $(QUILT_PATCH_DIR)/series && rm $(QUILT_PATCH_DIR)/series || :
+       rm -f $(__TG_FILES)
+       # remove the series file
+       rm -f $(QUILT_PATCH_DIR)/series
+       # remove dpkg v3 file
+       rm -f $(QUILT_PATCH_DIR)/.dpkg-source-applied
        # try to remove directories
-       find $(QUILT_PATCH_DIR) -type d | tac | xargs rmdir 2>/dev/null || :
+       find $(QUILT_PATCH_DIR) -depth -type d -empty -execdir rmdir {} +
        # fail if the directory could not be removed and still exists
        @test ! -d $(QUILT_PATCH_DIR) || { \
          echo "E: $(QUILT_PATCH_DIR) contains non-TopGit-generated files:" >&2; \
@@ -141,7 +162,7 @@ tg-cleanexport: tg-rmdir
 
 endif
 
-.PHONY: tg-clean tg-export tg-forceclean tg-rmdir
+.PHONY: tg-clean tg-export tg-forceclean tg-rmdir tg-cleanexport
 
 # vim:ft=make:ts=8:noet
 # -*- Makefile -*-, you silly Emacs! (shamelessly stolen from quilt)