From 8bd74c48600178d980afb70f687e3c8c2a6c83ec Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Sun, 10 Jun 2018 23:27:29 +0300 Subject: [PATCH] git: trim leading newline in the squash message editor Fixes IDEA-193688 When squashing two commits, Git proposes the following message: ``` # This is a combination of 2 commits. # This is the 1st commit message: first # This is the commit message #2: second ``` Since we remove commented lines, we show the following message: ``` first second ``` The first newline looks like a bug and never makes sense. We could be even more intelligent and remove the newline before the second commit message as well, but this would require parsing of commented messages, whose texts are not specified. --- .../src/git4idea/rebase/GitInteractiveRebaseEditorHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseEditorHandler.java b/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseEditorHandler.java index 0bae12f3bd6c..e028626dffb2 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseEditorHandler.java +++ b/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseEditorHandler.java @@ -39,6 +39,7 @@ import static com.intellij.CommonBundle.getCancelButtonText; import static com.intellij.CommonBundle.getOkButtonText; import static com.intellij.openapi.ui.Messages.getQuestionIcon; import static com.intellij.openapi.util.text.StringUtil.splitByLinesKeepSeparators; +import static com.intellij.openapi.util.text.StringUtil.trimLeading; import static git4idea.DialogManager.showOkCancelDialog; import static git4idea.rebase.GitRebaseEditorMain.ERROR_EXIT_CODE; @@ -98,7 +99,7 @@ public class GitInteractiveRebaseEditorHandler implements Closeable, GitRebaseEd protected boolean handleUnstructuredEditor(@NotNull String path) throws IOException { String encoding = GitConfigUtil.getCommitEncoding(myProject, myRoot); File file = new File(path); - String initialText = ignoreComments(FileUtil.loadFile(file, encoding)); + String initialText = trimLeading(ignoreComments(FileUtil.loadFile(file, encoding))); String newText = showUnstructuredEditor(initialText); if (newText == null) {