summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--alembic/command.py2
-rw-r--r--alembic/script.py33
-rw-r--r--docs/build/changelog.rst9
-rw-r--r--docs/build/front.rst2
-rw-r--r--tests/test_command.py49
5 files changed, 56 insertions, 39 deletions
diff --git a/alembic/command.py b/alembic/command.py
index 898f4c9..095d041 100644
--- a/alembic/command.py
+++ b/alembic/command.py
@@ -168,7 +168,7 @@ def history(config, rev_range=None):
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):
diff --git a/alembic/script.py b/alembic/script.py
index 637a749..f090326 100644
--- a/alembic/script.py
+++ b/alembic/script.py
@@ -2,7 +2,6 @@ import datetime
import os
import re
import shutil
-
from . import util
_rev_file = re.compile(r'.*\.py$')
@@ -377,8 +376,18 @@ class Script(object):
@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])
@@ -406,6 +415,24 @@ class Script(object):
"""
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,
diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst
index ec5beba..bc39aea 100644
--- a/docs/build/changelog.rst
+++ b/docs/build/changelog.rst
@@ -5,6 +5,15 @@ Changelog
.. 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
diff --git a/docs/build/front.rst b/docs/build/front.rst
index 26be21b..3270f5c 100644
--- a/docs/build/front.rst
+++ b/docs/build/front.rst
@@ -52,7 +52,7 @@ Dependencies
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.
diff --git a/tests/test_command.py b/tests/test_command.py
index 36bcc66..34f5785 100644
--- a/tests/test_command.py
+++ b/tests/test_command.py
@@ -4,6 +4,9 @@ from . import clear_staging_env, staging_env, \
three_rev_fixture, eq_
from alembic import command
from io import StringIO
+from alembic.script import ScriptDirectory
+
+
class StdoutCommandTest(unittest.TestCase):
@@ -18,74 +21,52 @@ 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])