aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--becommands/commit.py68
-rw-r--r--libbe/cmdutil.py2
-rw-r--r--libbe/editor.py2
-rw-r--r--libbe/rcs.py5
4 files changed, 73 insertions, 4 deletions
diff --git a/becommands/commit.py b/becommands/commit.py
new file mode 100644
index 0000000..bda51c4
--- /dev/null
+++ b/becommands/commit.py
@@ -0,0 +1,68 @@
+# Copyright (C) 2009 W. Trevor King <wking@drexel.edu>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+"""Commit the currently pending changes to the repository"""
+from libbe import cmdutil, bugdir, editor
+import sys
+__desc__ = __doc__
+
+def execute(args, manipulate_encodings=True):
+ """
+ >>> import os, time
+ >>> from libbe import bug
+ >>> bd = bugdir.simple_bug_dir()
+ >>> os.chdir(bd.root)
+ >>> full_path = "testfile"
+ >>> test_contents = "A test file"
+ >>> bd.rcs.set_file_contents(full_path, test_contents)
+ >>> execute(["Added %s." % (full_path)], manipulate_encodings=False) # doctest: +ELLIPSIS
+ Committed ...
+ """
+ parser = get_parser()
+ options, args = parser.parse_args(args)
+ cmdutil.default_complete(options, args, parser)
+ if len(args) != 1:
+ raise cmdutil.UsageError("Please supply a commit message")
+ bd = bugdir.BugDir(from_disk=True,
+ manipulate_encodings=manipulate_encodings)
+ if args[0] == '-': # read summary from stdin
+ assert options.body != "EDITOR", \
+ "Cannot spawn and editor when the summary is using stdin."
+ summary = sys.stdin.readline()
+ else:
+ summary = args[0]
+ if options.body == None:
+ body = None
+ elif options.body == "EDITOR":
+ body = editor.editor_string("Please enter your commit message above")
+ else:
+ body = bd.rcs.get_file_contents(options.body, allow_no_rcs=True)
+ revision = bd.rcs.commit(summary, body=body)
+ print "Committed %s" % revision
+
+def get_parser():
+ parser = cmdutil.CmdOptionParser("be commit COMMENT")
+ parser.add_option("-b", "--body", metavar="FILE", dest="body",
+ help='Provide a detailed body for the commit message. In the special case that FILE == "EDITOR", spawn an editor to enter the body text (in which case you cannot use stdin for the summary)', default=None)
+ return parser
+
+longhelp="""
+Commit the current repository status. The summary specified on the
+commandline is a string (only one line) that describes the commit
+briefly or "-", in which case the string will be read from stdin.
+"""
+
+def help():
+ return get_parser().help_str() + longhelp
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py
index 36d5d96..bba3e0e 100644
--- a/libbe/cmdutil.py
+++ b/libbe/cmdutil.py
@@ -163,7 +163,7 @@ def default_complete(options, args, parser, bugid_args={}):
"""
for option,value in option_value_pairs(options, parser):
if value == "--complete":
- raise cmdutil.GetCompletions()
+ raise GetCompletions()
if len(bugid_args.keys()) > 0:
max_pos_arg = max(bugid_args.keys())
else:
diff --git a/libbe/editor.py b/libbe/editor.py
index 5e3f9a6..93144b8 100644
--- a/libbe/editor.py
+++ b/libbe/editor.py
@@ -31,7 +31,7 @@ class CantFindEditor(Exception):
Exception.__init__(self, "Can't find editor to get string from")
def editor_string(comment=None, encoding=None):
- """Invokes the editor, and returns the user_produced text as a string
+ """Invokes the editor, and returns the user-produced text as a string
>>> if "EDITOR" in os.environ:
... del os.environ["EDITOR"]
diff --git a/libbe/rcs.py b/libbe/rcs.py
index 1024249..7138d01 100644
--- a/libbe/rcs.py
+++ b/libbe/rcs.py
@@ -201,7 +201,7 @@ class RCS(object):
"""
Commit the current working directory, using the contents of
commitfile as the comment. Return the name of the old
- revision.
+ revision (or None if commits are not supported).
"""
return None
def installed(self):
@@ -370,8 +370,9 @@ class RCS(object):
string summary and body. Return the name of the old revision
(or None if versioning is not supported).
"""
+ summary = summary.strip()
if body is not None:
- summary += '\n' + body
+ summary += '\n\n' + body.strip() + '\n'
descriptor, filename = tempfile.mkstemp()
revision = None
try: