Allow empty commit messages
[stgit] / stgit / git.py
index 2399996..2c73bb8 100644 (file)
@@ -436,7 +436,9 @@ def commit(message, files = None, parents = None, allowempty = False,
             raise GitException, 'No changes to commit'
 
     # get the commit message
-    if message[-1:] != '\n':
+    if not message:
+        message = '\n'
+    elif message[-1:] != '\n':
         message += '\n'
 
     must_switch = True
@@ -644,12 +646,13 @@ def checkout(files = None, tree_id = None, force = False):
     if __run(checkout_cmd, files) != 0:
         raise GitException, 'Failed git-checkout-index'
 
-def switch(tree_id):
+def switch(tree_id, keep = False):
     """Switch the tree to the given id
     """
-    refresh_index()
-    if __run('git-read-tree -u -m', [get_head(), tree_id]) != 0:
-        raise GitException, 'git-read-tree failed (local changes maybe?)'
+    if not keep:
+        refresh_index()
+        if __run('git-read-tree -u -m', [get_head(), tree_id]) != 0:
+            raise GitException, 'git-read-tree failed (local changes maybe?)'
 
     __set_head(tree_id)