X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/2406f7d16cad24d396b3e8ea5605813f4011b5a6..1e0754060c4fbf7a35efc8557e8d798a49103324:/stgit/git.py diff --git a/stgit/git.py b/stgit/git.py index 2399996..025d15d 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -59,7 +59,11 @@ class Commit: return self.__tree def get_parent(self): - return self.get_parents()[0] + parents = self.get_parents() + if parents: + return parents[0] + else: + return None def get_parents(self): return _output_lines('git-rev-list --parents --max-count=1 %s' @@ -436,7 +440,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 +650,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)