2727
2727
class cmd_commit(Command):
2728
2728
"""Commit changes into a new revision.
2730
If no arguments are given, the entire tree is committed.
2732
If selected files are specified, only changes to those files are
2733
committed. If a directory is specified then the directory and everything
2734
within it is committed.
2736
When excludes are given, they take precedence over selected files.
2737
For example, too commit only changes within foo, but not changes within
2740
bzr commit foo -x foo/bar
2742
If author of the change is not the same person as the committer, you can
2743
specify the author's name using the --author option. The name should be
2744
in the same format as a committer-id, e.g. "John Doe <jdoe@example.com>".
2745
If there is more than one author of the change you can specify the option
2746
multiple times, once for each author.
2748
A selected-file commit may fail in some cases where the committed
2749
tree would be invalid. Consider::
2754
bzr commit foo -m "committing foo"
2755
bzr mv foo/bar foo/baz
2758
bzr commit foo/bar -m "committing bar but not baz"
2760
In the example above, the last commit will fail by design. This gives
2761
the user the opportunity to decide whether they want to commit the
2762
rename at the same time, separately first, or not at all. (As a general
2763
rule, when in doubt, Bazaar has a policy of Doing the Safe Thing.)
2765
Note: A selected-file commit after a merge is not yet supported.
2730
An explanatory message needs to be given for each commit. This is
2731
often done by using the --message option (getting the message from the
2732
command line) or by using the --file option (getting the message from
2733
a file). If neither of these options is given, an editor is opened for
2734
the user to enter the message. To see the changed files in the
2735
boilerplate text loaded into the editor, use the --show-diff option.
2737
By default, the entire tree is committed and the person doing the
2738
commit is assumed to be the author. These defaults can be overridden
2743
If selected files are specified, only changes to those files are
2744
committed. If a directory is specified then the directory and
2745
everything within it is committed.
2747
When excludes are given, they take precedence over selected files.
2748
For example, to commit only changes within foo, but not changes
2751
bzr commit foo -x foo/bar
2753
A selective commit after a merge is not yet supported.
2757
If the author of the change is not the same person as the committer,
2758
you can specify the author's name using the --author option. The
2759
name should be in the same format as a committer-id, e.g.
2760
"John Doe <jdoe@example.com>". If there is more than one author of
2761
the change you can specify the option multiple times, once for each
2766
A common mistake is to forget to add a new file or directory before
2767
running the commit command. The --strict option checks for unknown
2768
files and aborts the commit if any are found. More advanced pre-commit
2769
checks can be implemented by defining hooks. See ``bzr help hooks``
2774
If you accidentially commit the wrong changes or make a spelling
2775
mistake in the commit message say, you can use the uncommit command
2776
to undo it. See ``bzr help uncommit`` for details.
2778
Hooks can also be configured to run after a commit. This allows you
2779
to trigger updates to external systems like bug trackers. The --fixes
2780
option can be used to record the association between a revision and
2781
one or more bugs. See ``bzr help bugs`` for details.
2783
A selective commit may fail in some cases where the committed
2784
tree would be invalid. Consider::
2789
bzr commit foo -m "committing foo"
2790
bzr mv foo/bar foo/baz
2793
bzr commit foo/bar -m "committing bar but not baz"
2795
In the example above, the last commit will fail by design. This gives
2796
the user the opportunity to decide whether they want to commit the
2797
rename at the same time, separately first, or not at all. (As a general
2798
rule, when in doubt, Bazaar has a policy of Doing the Safe Thing.)
2767
2800
# TODO: Run hooks on tree to-be-committed, and after commit.
5271
5304
from bzrlib import switch
5272
5305
tree_location = '.'
5273
5306
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5274
branch = control_dir.open_branch()
5308
branch = control_dir.open_branch()
5309
had_explicit_nick = branch.get_config().has_explicit_nickname()
5310
except errors.NotBranchError:
5311
had_explicit_nick = False
5276
5313
to_branch = Branch.open(to_location)
5277
5314
except errors.NotBranchError:
5278
this_branch = control_dir.open_branch()
5279
# This may be a heavy checkout, where we want the master branch
5280
this_url = this_branch.get_bound_location()
5281
# If not, use a local sibling
5282
if this_url is None:
5283
this_url = this_branch.base
5315
this_url = self._get_branch_location(control_dir)
5284
5316
to_branch = Branch.open(
5285
5317
urlutils.join(this_url, '..', to_location))
5286
5318
switch.switch(control_dir, to_branch, force)
5287
if branch.get_config().has_explicit_nickname():
5319
if had_explicit_nick:
5288
5320
branch = control_dir.open_branch() #get the new branch!
5289
5321
branch.nick = to_branch.nick
5290
5322
note('Switched to branch: %s',
5291
5323
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5325
def _get_branch_location(self, control_dir):
5326
"""Return location of branch for this control dir."""
5328
this_branch = control_dir.open_branch()
5329
# This may be a heavy checkout, where we want the master branch
5330
master_location = this_branch.get_bound_location()
5331
if master_location is not None:
5332
return master_location
5333
# If not, use a local sibling
5334
return this_branch.base
5335
except errors.NotBranchError:
5336
format = control_dir.find_branch_format()
5337
if getattr(format, 'get_reference', None) is not None:
5338
return format.get_reference(control_dir)
5340
return control_dir.root_transport.base
5294
5343
class cmd_view(Command):
5295
5344
"""Manage filtered views.