From a3fe2903e215f5da8b3b3d00e7d8c16a8580ee68 Mon Sep 17 00:00:00 2001 From: "gab@chromium.org" Date: Wed, 20 Apr 2016 18:31:37 +0000 Subject: [PATCH] Ensure files passed to the editor by RunEditor end in a new line BUG=605201 Review URL: https://codereview.chromium.org/1905693002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@300049 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient_utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gclient_utils.py b/gclient_utils.py index 21c44c36a..9d1b9dfdd 100644 --- a/gclient_utils.py +++ b/gclient_utils.py @@ -1084,7 +1084,11 @@ def RunEditor(content, git, git_editor=None): '!! Please remove \\r from your change description !!') fileobj = os.fdopen(file_handle, 'w') # Still remove \r if present. - fileobj.write(re.sub('\r?\n', '\n', content)) + content = re.sub('\r?\n', '\n', content) + # Some editors complain when the file doesn't end in \n. + if not content.endswith('\n'): + content += '\n' + fileobj.write(content) fileobj.close() try: