~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: wang
  • Date: 2006-10-19 03:25:55 UTC
  • mto: (2111.1.1 32054)
  • mto: This revision was merged to the branch mainline in revision 2113.
  • Revision ID: wang@ubuntu-20061019032555-79c04af4940e8e94
If a commit fails, the commit message is stored in a file at the root of
the tree for later commit. Fixes #32054

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import codecs
24
24
import errno
25
25
import sys
 
26
import tempfile
26
27
 
27
28
import bzrlib
28
29
from bzrlib import (
1801
1802
            reporter = ReportCommitToLog()
1802
1803
        else:
1803
1804
            reporter = NullCommitReporter()
1804
 
        
 
1805
 
 
1806
        # save the commit message and only unlink it if the commit was
 
1807
        # successful
 
1808
        try:
 
1809
            tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr-commit-',
 
1810
                                                       dir=tree.basedir)
 
1811
            os.close(tmp_fileno)
 
1812
        except OSError:
 
1813
            try:
 
1814
                # No access to working dir, try $TMP
 
1815
                tmp_fileno, msgfilename= tempfile.mkstemp(prefix='bzr-commit-')
 
1816
                os.close(tmp_fileno)
 
1817
            except:
 
1818
                # We can't create a temp file, try to work without it
 
1819
                msgfilename = None
 
1820
        if msgfilename is not None:
 
1821
            msgfile = open(msgfilename, "wt")
 
1822
            try:
 
1823
                msgfile.write(message.encode(bzrlib.user_encoding, 'replace'))
 
1824
            finally:
 
1825
                msgfile.close()
 
1826
 
1805
1827
        try:
1806
1828
            tree.commit(message, specific_files=selected_list,
1807
1829
                        allow_pointless=unchanged, strict=strict, local=local,
1808
1830
                        reporter=reporter)
 
1831
            if msgfilename is not None:
 
1832
                try:
 
1833
                    os.unlink(msgfilename)
 
1834
                except IOError, e:
 
1835
                    warning("failed to unlink %s: %s; ignored", msgfilename, e)
1809
1836
        except PointlessCommit:
1810
1837
            # FIXME: This should really happen before the file is read in;
1811
1838
            # perhaps prepare the commit; get the message; then actually commit
1812
 
            raise errors.BzrCommandError("no changes to commit."
1813
 
                                         " use --unchanged to commit anyhow")
 
1839
            if msgfilename is not None:
 
1840
                raise errors.BzrCommandError("no changes to commit."
 
1841
                                  " use --unchanged to commit anyhow\n"
 
1842
                                  "Commit message saved. To reuse the message,"
 
1843
                                  " do\nbzr commit --file " + msgfilename)
 
1844
            else:
 
1845
                raise errors.BzrCommandError("no changes to commit."
 
1846
                                  " use --unchanged to commit anyhow")
1814
1847
        except ConflictsInTree:
1815
 
            raise errors.BzrCommandError("Conflicts detected in working tree.  "
1816
 
                'Use "bzr conflicts" to list, "bzr resolve FILE" to resolve.')
 
1848
            if msgfilename is not None:
 
1849
                raise errors.BzrCommandError('Conflicts detected in working '
 
1850
                    'tree.  Use "bzr conflicts" to list, "bzr resolve FILE" to'
 
1851
                    ' resolve.\n'
 
1852
                    'Commit message saved. To reuse the message,'
 
1853
                    ' do\nbzr commit --file ' + msgfilename)
 
1854
            else:
 
1855
                raise errors.BzrCommandError('Conflicts detected in working '
 
1856
                    'tree.  Use "bzr conflicts" to list, "bzr resolve FILE" to'
 
1857
                    ' resolve.')
1817
1858
        except StrictCommitFailed:
1818
 
            raise errors.BzrCommandError("Commit refused because there are unknown "
1819
 
                                         "files in the working tree.")
 
1859
            if msgfilename is not None:
 
1860
                raise errors.BzrCommandError("Commit refused because there are"
 
1861
                                  " unknown files in the working tree.\n"
 
1862
                                  "Commit message saved. To reuse the message,"
 
1863
                                  " do\nbzr commit --file " + msgfilename)
 
1864
            else:
 
1865
                raise errors.BzrCommandError("Commit refused because there are"
 
1866
                                  " unknown files in the working tree.")
1820
1867
        except errors.BoundBranchOutOfDate, e:
1821
 
            raise errors.BzrCommandError(str(e) + "\n"
 
1868
            if msgfilename is not None:
 
1869
                raise errors.BzrCommandError(str(e) + "\n"
 
1870
                'To commit to master branch, run update and then commit.\n'
 
1871
                'You can also pass --local to commit to continue working '
 
1872
                'disconnected.\n'
 
1873
                'Commit message saved. To reuse the message,'
 
1874
                ' do\nbzr commit --file ' + msgfilename)
 
1875
            else:
 
1876
                raise errors.BzrCommandError(str(e) + "\n"
1822
1877
                'To commit to master branch, run update and then commit.\n'
1823
1878
                'You can also pass --local to commit to continue working '
1824
1879
                'disconnected.')