]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/command/prepare_pristine.py
prepare-pristine: stage deleted files too, and update upgrade docs.
[wizard.git] / wizard / command / prepare_pristine.py
index 80517d1b1c1cc3a6e641231bd9645f0ed1156693..d4c92331868688ef2700f168fc2a2d98902c10fb 100644 (file)
@@ -1,6 +1,7 @@
 import urllib
 import shutil
 import os
+import os.path
 
 from wizard import app, command, shell
 
@@ -9,7 +10,7 @@ def main(argv, baton):
     check_directory(options)
     if not os.path.exists(args[0]):
         appname, _, version = args[0].partition("-")
-        application = app.applications()[appname]
+        application = app.getApplication(appname)
         url = application.download(version)
         base = os.path.basename(url)
         with open(base, "w") as outfile:
@@ -32,7 +33,11 @@ def main(argv, baton):
             if "/.git" in dirpath: continue
             if not filenames and not dirnames:
                 open(os.path.join(dirpath, ".preserve-dir"), "w").write("")
+        # stage all changes
         shell.call("git", "add", ".")
+        for f in shell.call("git", "ls-files", "-d", "-z")[0].split("\0"):
+            if f != "":
+                shell.call("git", "rm", "--", f)
 
 def parse_args(argv, baton):
     usage = """usage: %prog prepare-pristine APP-VERSION
@@ -56,6 +61,8 @@ local diffs: you can override this safety mechanism with --force.
     return options, args
 
 def check_directory(options):
+    if not os.path.exists(".git"):
+        raise Exception("Not in root directory of Git repository")
     files = shell.eval("git", "ls-files", "-o")
     if files:
         raise Exception("Unversioned files exist, refusing to remove (override with --force)")
@@ -65,11 +72,8 @@ def check_directory(options):
         if not options.force:
             if ref != "refs/heads/pristine" and os.path.exists(os.path.join(".git", ref)):
                 raise Exception("Not on pristine branch (override with --force)")
-            try:
-                shell.call("git", "status")
+            if shell.eval("git", "ls-files", "-m").strip() != "":
                 raise Exception("Working copy is dirty (override with --force)")
-            except shell.CallError:
-                pass
         for f in os.listdir(os.getcwd()):
             if f == ".git": continue
             try: