Mike Bayer avatar Mike Bayer committed a381c8f

The output of the ``alembic history`` command is now
expanded to show information about each change on multiple
lines, including the full top message,
resembling the formatting of git log.

Comments (0)

Files changed (5)

alembic/command.py

                                 head=head or "head"):
             if sc.is_head:
                 config.print_stdout("")
-            config.print_stdout(sc)
+            config.print_stdout(sc.log_entry)
 
     def _display_history_w_current(config, script, base=None, head=None):
         def _display_current_history(rev, context):

alembic/script.py

 import os
 import re
 import shutil
-
 from . import util
 
 _rev_file = re.compile(r'.*\.py$')
     @property
     def doc(self):
         """Return the docstring given in the script."""
-        if self.module.__doc__:
-            return re.split(r"\n\n", self.module.__doc__)[0]
+
+        return re.split("\n\n", self.longdoc)[0]
+
+    @property
+    def longdoc(self):
+        """Return the docstring given in the script."""
+
+        doc = self.module.__doc__
+        if doc:
+            return doc.strip()
+        else:
+            return ""
 
     def add_nextrev(self, rev):
         self.nextrev = self.nextrev.union([rev])
         """
         return len(self.nextrev) > 1
 
+    @property
+    def log_entry(self):
+        return \
+            "Rev: %s%s%s\n" \
+            "Parent: %s\n" \
+            "Path: %s\n" \
+            "\n%s\n" % (
+                self.revision,
+                " (head)" if self.is_head else "",
+                " (branchpoint)" if self.is_branch_point else "",
+                self.down_revision,
+                self.path,
+                "\n".join(
+                    "    %s" % para
+                    for para in self.longdoc.splitlines()
+                )
+            )
+
     def __str__(self):
         return "%s -> %s%s%s, %s" % (
                         self.down_revision,

docs/build/changelog.rst

 
 .. changelog::
     :version: 0.6.0
+    :released:
+
+    .. change::
+      :tags: feature
+
+      The output of the ``alembic history`` command is now
+      expanded to show information about each change on multiple
+      lines, including the full top message,
+      resembling the formatting of git log.
 
     .. change::
       :tags: feature

docs/build/front.rst

 Alembic's install process will ensure that `SQLAlchemy <http://www.sqlalchemy.org>`_
 is installed, in addition to other dependencies.  Alembic will work with
 SQLAlchemy as of version **0.7.3**.   The latest version of SQLAlchemy within
-the **0.7** or **0.8** series is strongly recommended.
+the **0.7**, **0.8**, or more recent series is strongly recommended.
 
 Alembic supports Python versions 2.6 and above.
 

tests/test_command.py

     three_rev_fixture, eq_
 from alembic import command
 from io import StringIO
+from alembic.script import ScriptDirectory
+
+
 
 class StdoutCommandTest(unittest.TestCase):
 
         clear_staging_env()
 
     def _eq_cmd_output(self, buf, expected):
+        script = ScriptDirectory.from_config(self.cfg)
+
         revs = {"reva": self.a, "revb": self.b, "revc": self.c}
         eq_(
-            [s for s in buf.getvalue().split("\n") if s],
-            [exp % revs for exp in expected]
+            buf.getvalue().strip(),
+            "\n".join([script.get_revision(rev).log_entry for rev in expected]).strip()
         )
 
     def test_history_full(self):
         self.cfg.stdout = buf = StringIO()
         command.history(self.cfg)
-        self._eq_cmd_output(buf, [
-                '%(revb)s -> %(revc)s (head), Rev C',
-                '%(reva)s -> %(revb)s, Rev B',
-                'None -> %(reva)s, Rev A'
-            ])
+        self._eq_cmd_output(buf, [self.c, self.b, self.a])
 
     def test_history_num_range(self):
         self.cfg.stdout = buf = StringIO()
         command.history(self.cfg, "%s:%s" % (self.a, self.b))
-        self._eq_cmd_output(buf, [
-                '%(reva)s -> %(revb)s, Rev B',
-            ])
+        self._eq_cmd_output(buf, [self.b])
 
     def test_history_base_to_num(self):
         self.cfg.stdout = buf = StringIO()
         command.history(self.cfg, ":%s" % (self.b))
-        self._eq_cmd_output(buf, [
-                '%(reva)s -> %(revb)s, Rev B',
-                'None -> %(reva)s, Rev A'
-            ])
+        self._eq_cmd_output(buf, [self.b, self.a])
 
     def test_history_num_to_head(self):
         self.cfg.stdout = buf = StringIO()
         command.history(self.cfg, "%s:" % (self.a))
-        self._eq_cmd_output(buf, [
-                '%(revb)s -> %(revc)s (head), Rev C',
-                '%(reva)s -> %(revb)s, Rev B',
-            ])
+        self._eq_cmd_output(buf, [self.c, self.b])
 
     def test_history_num_plus_relative(self):
         self.cfg.stdout = buf = StringIO()
         command.history(self.cfg, "%s:+2" % (self.a))
-        self._eq_cmd_output(buf, [
-                '%(revb)s -> %(revc)s (head), Rev C',
-                '%(reva)s -> %(revb)s, Rev B',
-            ])
+        self._eq_cmd_output(buf, [self.c, self.b])
 
     def test_history_relative_to_num(self):
         self.cfg.stdout = buf = StringIO()
         command.history(self.cfg, "-2:%s" % (self.c))
-        self._eq_cmd_output(buf, [
-                '%(revb)s -> %(revc)s (head), Rev C',
-                '%(reva)s -> %(revb)s, Rev B',
-            ])
+        self._eq_cmd_output(buf, [self.c, self.b])
 
     def test_history_current_to_head_as_b(self):
         command.stamp(self.cfg, self.b)
         self.cfg.stdout = buf = StringIO()
         command.history(self.cfg, "current:")
-        self._eq_cmd_output(buf, [
-                '%(revb)s -> %(revc)s (head), Rev C',
-            ])
+        self._eq_cmd_output(buf, [self.c])
 
     def test_history_current_to_head_as_base(self):
         command.stamp(self.cfg, "base")
         self.cfg.stdout = buf = StringIO()
         command.history(self.cfg, "current:")
-        self._eq_cmd_output(buf, [
-                '%(revb)s -> %(revc)s (head), Rev C',
-                '%(reva)s -> %(revb)s, Rev B',
-                'None -> %(reva)s, Rev A'
-            ])
+        self._eq_cmd_output(buf, [self.c, self.b, self.a])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.