1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic)
2
# Some parts of the code are:
3
# Copyright (C) 2005, 2006 by Canonical Ltd
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
import bzrlib.errors as errors
24
from errors import (EmptyMessageError, NoMessageNoFileError,
25
NoChangesToCommitError, ConflictsInTreeError,
26
StrictCommitError, BoundBranchOutOfDate,
27
LocalRequiresBoundBranch, NotBranchError)
29
def commit(selected_list, message=None, file=None, unchanged=False,
30
strict=False, local=False):
31
""" Command to commit changes into the branch.
33
:param selected_list: list of files you want to commit (at least the top working directory has to specified)
35
:param message: commit message
37
:param file: the file which contains the commit message
39
:param unchanged: force commit if nothing has changed since the last commit
41
:param strict: refuse to commit if there are unknown files in the working tree
43
:param local: perform a local only commit in a bound branch
45
from bzrlib.builtins import tree_files
46
from bzrlib.commit import NullCommitReporter
49
tree, selected_list = tree_files(selected_list)
50
except errors.NotBranchError:
53
if local and not tree.branch.get_bound_location():
54
raise LocalRequiresBoundBranch()
55
if message is None and not file:
57
raise NoMessageNoFileError
58
elif message and file:
59
raise NoMessageNoFileError
62
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
65
raise EmptyMessageError
67
reporter = NullCommitReporter()
70
tree.commit(message, specific_files=selected_list,
71
allow_pointless=unchanged, strict=strict, local=local,
73
except errors.PointlessCommit:
74
raise NoChangesToCommitError
75
except errors.ConflictsInTree:
76
raise ConflictsInTreeError
77
except errors.StrictCommitFailed:
78
raise StrictCommitError
79
except errors.BoundBranchOutOfDate, e:
80
raise BoundBranchOutOfDate(str(e))