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.
This commit is contained in:
Kirill Likhodedov
2018-06-11 10:29:24 +03:00
parent fa5fd3e2b6
commit 8bd74c4860
@@ -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) {