From 07af6c9faf54029db92661461830d5959eda5f22 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Mon, 14 Oct 2013 21:46:28 +0400 Subject: [PATCH] [git] load commit message from .git/COMMIT_EDITMSG as well Previously the commit message was loaded both from MERGE_MSG and SQUASH_MSG. * Load it from COMMIT_EDITMSG as well, but don't concatenate all messages, since in most cases they are the same: use only one of them. * Extract loading message in a separate method. --- .../checkin/GitCheckinEnvironment.java | 39 ++++++++++++------- .../src/git4idea/repo/GitRepositoryFiles.java | 1 + 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java index 7d868af1b545..a4f4b032bdbb 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java +++ b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java @@ -112,20 +112,27 @@ public class GitCheckinEnvironment implements CheckinEnvironment { for (VirtualFile root : GitUtil.gitRoots(Arrays.asList(filesToCheckin))) { VirtualFile mergeMsg = root.findFileByRelativePath(GitRepositoryFiles.GIT_MERGE_MSG); VirtualFile squashMsg = root.findFileByRelativePath(GitRepositoryFiles.GIT_SQUASH_MSG); - if (mergeMsg != null || squashMsg != null) { - try { - String encoding = GitConfigUtil.getCommitEncoding(myProject, root); - if (mergeMsg != null) { - rc.append(FileUtil.loadFileText(new File(mergeMsg.getPath()), encoding)); - } - if (squashMsg != null) { - rc.append(FileUtil.loadFileText(new File(squashMsg.getPath()), encoding)); - } + VirtualFile normalMsg = root.findFileByRelativePath(GitRepositoryFiles.GIT_COMMIT_EDITMSG); + try { + if (mergeMsg == null && squashMsg == null && normalMsg == null) { + continue; } - catch (IOException e) { - if (log.isDebugEnabled()) { - log.debug("Unable to load merge message", e); - } + + String encoding = GitConfigUtil.getCommitEncoding(myProject, root); + + if (mergeMsg != null) { + rc.append(loadMessage(mergeMsg, encoding)); + } + else if (squashMsg != null) { + rc.append(loadMessage(squashMsg, encoding)); + } + else { + rc.append(loadMessage(normalMsg, encoding)); + } + } + catch (IOException e) { + if (log.isDebugEnabled()) { + log.debug("Unable to load merge message", e); } } } @@ -135,6 +142,10 @@ public class GitCheckinEnvironment implements CheckinEnvironment { return null; } + private static char[] loadMessage(@NotNull VirtualFile messageFile, @NotNull String encoding) throws IOException { + return FileUtil.loadFileText(new File(messageFile.getPath()), encoding); + } + public String getHelpId() { return null; } @@ -219,7 +230,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment { } return exceptions; } - + public List commit(List changes, String preparedComment) { return commit(changes, preparedComment, FunctionUtil.nullConstant(), null); } diff --git a/plugins/git4idea/src/git4idea/repo/GitRepositoryFiles.java b/plugins/git4idea/src/git4idea/repo/GitRepositoryFiles.java index f6456ce267a0..d32a0e12f28d 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepositoryFiles.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepositoryFiles.java @@ -53,6 +53,7 @@ public class GitRepositoryFiles { public static final String GIT_MERGE_HEAD = DOT_GIT + slash(MERGE_HEAD); public static final String GIT_MERGE_MSG = DOT_GIT + slash(MERGE_MSG); public static final String GIT_SQUASH_MSG = DOT_GIT + slash(SQUASH_MSG); + public static final String GIT_COMMIT_EDITMSG = DOT_GIT + slash(COMMIT_EDITMSG); private final String myConfigFilePath; private final String myHeadFilePath;