]> scripts.mit.edu Git - wizard.git/commitdiff
Fix non-zero shell exit code and --continue in wrong directory.
authorEdward Z. Yang <ezyang@mit.edu>
Sun, 27 Dec 2009 22:54:06 +0000 (17:54 -0500)
committerEdward Z. Yang <ezyang@mit.edu>
Sun, 27 Dec 2009 22:54:06 +0000 (17:54 -0500)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
TODO
tests/mediawiki-alt-continue-upgrade-test.sh [new file with mode: 0755]
wizard/command/upgrade.py

diff --git a/TODO b/TODO
index 5762dee498fab20f7f24a78d8cec90e0cdba2109..08ace5d976bbd38a7044c0a958cd3cb1f77e6ca4 100644 (file)
--- a/TODO
+++ b/TODO
@@ -6,9 +6,9 @@ TODO NOW:
 
 - Remerges aren't reflected in the parent files, so `git diff` output is
   spurious.  Not sure how to fix this w/o tree hackery.
-- Missing ancestor means that certain files cannot be merged, for the curious files;
-  this is indicated by 1,3 but missing 2.  There might be some cleverness to be
-  done here by finding a "fake" ancestor to use.
+- Sometimes users remove files. Well, if those files change, they automatically
+  get marked as conflicted.  Maybe we should say for certain files "if they're
+  gone, they're gone forever"?  What is the proper resolution?
 
 - wizard install wordpress should ask for password.  One problem with this is that
   Wordpress will still send mail with the wrong username and password, so Wordpress
diff --git a/tests/mediawiki-alt-continue-upgrade-test.sh b/tests/mediawiki-alt-continue-upgrade-test.sh
new file mode 100755 (executable)
index 0000000..3052555
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash -e
+cd `dirname $0`
+
+TESTNAME="mediawiki_alt_continue_upgrade"
+source ./setup
+
+source ./mediawiki-install
+
+# nuke the install
+FROB="RELEASE-NOTES"
+mv "$TESTDIR/$FROB" "$TESTDIR/$FROB.bak"
+echo "this is a bad file" > "$TESTDIR/$FROB"
+
+# attempt an upgrade, this will fail
+RESULT=`! wizard upgrade "$TESTDIR" --non-interactive`
+TMPTESTDIR=`echo "$RESULT" | awk '{print $2}'`
+
+# resolve the upgrade
+mv -f "$TESTDIR/$FROB.bak" "$TMPTESTDIR/$FROB"
+OLDDIR=`pwd`
+cd "$TMPTESTDIR"
+git add $FROB
+git commit -m "resolution commit"
+
+# perform continue from the wrong directory
+cd "$OLDDIR/$TESTDIR"
+wizard upgrade --continue
index e35daa8efe329ace3f831c6166de6ee98dcb4879..a8cbde76e67b778d3637d9370099fb1b4ec3439d 100644 (file)
@@ -6,6 +6,7 @@ import logging.handlers
 import tempfile
 import itertools
 import time
+import errno
 
 from wizard import app, command, deploy, scripts, shell, util
 
@@ -101,15 +102,31 @@ class Upgrade(object):
         In the event of a ``--continue`` flag, we have to restore state and
         perform some sanity checks.
         """
+        self.resumeChdir()
         self.resumeState()
         self.resumeLogging()
         util.chdir(shell.eval("git", "config", "remote.origin.url"))
         self.resumeProd()
+    def resumeChdir(self):
+        """
+        If we called ``--continue`` inside a production copy,  check if
+        :file:`.scripts/pending` exists and change to that directory if so.
+        """
+        if os.path.exists(".scripts/pending"):
+            newdir = open(".scripts/pending").read().strip()
+            logging.warning("Detected production copy; changing directory to %s", newdir)
+            os.chdir(newdir)
     def resumeState(self):
         self.temp_wc_dir = os.getcwd()
         self.wc = deploy.WorkingCopy(".")
-        self.user_commit, self.next_commit = open(".git/WIZARD_PARENTS", "r").read().split()
-        self.version = open(".git/WIZARD_UPGRADE_VERSION", "r").read()
+        try:
+            self.user_commit, self.next_commit = open(".git/WIZARD_PARENTS", "r").read().split()
+            self.version = open(".git/WIZARD_UPGRADE_VERSION", "r").read()
+        except IOError as e:
+            if e.errno == errno.ENOENT:
+                raise CannotResumeError()
+            else:
+                raise
     def resumeLogging(self):
         options = self.options
         if not options.log_file and os.path.exists(".git/WIZARD_LOG_FILE"):
@@ -292,7 +309,10 @@ class Upgrade(object):
                     print "Please resolve these conflicts (edit and then `git add`), and"
                     print "then type 'exit'.  You will now be dropped into a shell whose working"
                     print "directory is %s" % self.temp_wc_dir
-                    shell.call(user_shell, "-i", interactive=True)
+                    try:
+                        shell.call(user_shell, "-i", interactive=True)
+                    except shell.CallError as e:
+                        logging.warning("Shell returned non-zero exit code %d" % e.code)
                     if shell.eval("git", "ls-files", "--unmerged").strip():
                         print
                         print "WARNING: There are still unmerged files."
@@ -480,3 +500,12 @@ if the user has not been notified of this, please send them
 mail.
 
 The reason was: %s""" % self.reason
+
+class CannotResumeError(Error):
+    def __str__(self):
+        return """
+
+ERROR: We cannot resume the upgrade process; either this working
+copy is missing essential metadata, or you've attempt to continue
+from a production copy that does not have any pending upgrades.
+"""