1802
1803
StrictCommitFailed)
1803
1804
from bzrlib.msgeditor import edit_commit_message, \
1804
1805
make_commit_message_template
1805
from tempfile import TemporaryFile
1807
1807
# TODO: Need a blackbox test for invoking the external editor; may be
1808
1808
# slightly problematic to run this cross-platform.
1810
1810
# TODO: do more checks that the commit will succeed before
1811
1811
# spending the user's valuable time typing a commit message.
1813
# TODO: if the commit *does* happen to fail, then save the commit
1814
# message to a temporary file where it can be recovered
1815
1812
tree, selected_list = tree_files(selected_list)
1816
1813
if selected_list == ['']:
1817
1814
# workaround - commit of root of tree should be exactly the same
1840
1837
reporter = ReportCommitToLog()
1842
1839
reporter = NullCommitReporter()
1841
msgfilename = self._save_commit_message(message, tree.basedir)
1845
1843
tree.commit(message, specific_files=selected_list,
1846
1844
allow_pointless=unchanged, strict=strict, local=local,
1847
1845
reporter=reporter)
1846
if msgfilename is not None:
1848
os.unlink(msgfilename)
1850
warning("failed to unlink %s: %s; ignored", msgfilename, e)
1848
1851
except PointlessCommit:
1849
1852
# FIXME: This should really happen before the file is read in;
1850
1853
# perhaps prepare the commit; get the message; then actually commit
1851
raise errors.BzrCommandError("no changes to commit."
1852
" use --unchanged to commit anyhow")
1854
if msgfilename is not None:
1855
raise errors.BzrCommandError("no changes to commit."
1856
" use --unchanged to commit anyhow\n"
1857
"Commit message saved. To reuse the message,"
1858
" do\nbzr commit --file " + msgfilename)
1860
raise errors.BzrCommandError("no changes to commit."
1861
" use --unchanged to commit anyhow")
1853
1862
except ConflictsInTree:
1854
raise errors.BzrCommandError("Conflicts detected in working tree. "
1855
'Use "bzr conflicts" to list, "bzr resolve FILE" to resolve.')
1863
if msgfilename is not None:
1864
raise errors.BzrCommandError('Conflicts detected in working '
1865
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
1867
'Commit message saved. To reuse the message,'
1868
' do\nbzr commit --file ' + msgfilename)
1870
raise errors.BzrCommandError('Conflicts detected in working '
1871
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
1856
1873
except StrictCommitFailed:
1857
raise errors.BzrCommandError("Commit refused because there are unknown "
1858
"files in the working tree.")
1874
if msgfilename is not None:
1875
raise errors.BzrCommandError("Commit refused because there are"
1876
" unknown files in the working tree.\n"
1877
"Commit message saved. To reuse the message,"
1878
" do\nbzr commit --file " + msgfilename)
1880
raise errors.BzrCommandError("Commit refused because there are"
1881
" unknown files in the working tree.")
1859
1882
except errors.BoundBranchOutOfDate, e:
1860
raise errors.BzrCommandError(str(e) + "\n"
1883
if msgfilename is not None:
1884
raise errors.BzrCommandError(str(e) + "\n"
1885
'To commit to master branch, run update and then commit.\n'
1886
'You can also pass --local to commit to continue working '
1888
'Commit message saved. To reuse the message,'
1889
' do\nbzr commit --file ' + msgfilename)
1891
raise errors.BzrCommandError(str(e) + "\n"
1861
1892
'To commit to master branch, run update and then commit.\n'
1862
1893
'You can also pass --local to commit to continue working '
1863
1894
'disconnected.')
1896
def _save_commit_message(self, message, basedir):
1897
# save the commit message and only unlink it if the commit was
1901
tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr-commit-',
1905
# No access to working dir, try $TMP
1906
tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr-commit-')
1908
# We can't create a temp file, try to work without it
1911
os.write(tmp_fileno, message.encode(bzrlib.user_encoding, 'replace'))
1913
os.close(tmp_fileno)
1865
1917
class cmd_check(Command):
1866
1918
"""Validate consistency of branch history.