[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.
This commit is contained in:
Kirill Likhodedov
2013-10-14 22:24:58 +04:00
parent ac0c562aed
commit 07af6c9faf
2 changed files with 26 additions and 14 deletions
@@ -112,20 +112,27 @@ public class GitCheckinEnvironment implements CheckinEnvironment {
for (VirtualFile root : GitUtil.gitRoots(Arrays.asList(filesToCheckin))) { for (VirtualFile root : GitUtil.gitRoots(Arrays.asList(filesToCheckin))) {
VirtualFile mergeMsg = root.findFileByRelativePath(GitRepositoryFiles.GIT_MERGE_MSG); VirtualFile mergeMsg = root.findFileByRelativePath(GitRepositoryFiles.GIT_MERGE_MSG);
VirtualFile squashMsg = root.findFileByRelativePath(GitRepositoryFiles.GIT_SQUASH_MSG); VirtualFile squashMsg = root.findFileByRelativePath(GitRepositoryFiles.GIT_SQUASH_MSG);
if (mergeMsg != null || squashMsg != null) { VirtualFile normalMsg = root.findFileByRelativePath(GitRepositoryFiles.GIT_COMMIT_EDITMSG);
try { try {
String encoding = GitConfigUtil.getCommitEncoding(myProject, root); if (mergeMsg == null && squashMsg == null && normalMsg == null) {
if (mergeMsg != null) { continue;
rc.append(FileUtil.loadFileText(new File(mergeMsg.getPath()), encoding));
}
if (squashMsg != null) {
rc.append(FileUtil.loadFileText(new File(squashMsg.getPath()), encoding));
}
} }
catch (IOException e) {
if (log.isDebugEnabled()) { String encoding = GitConfigUtil.getCommitEncoding(myProject, root);
log.debug("Unable to load merge message", e);
} 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; 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() { public String getHelpId() {
return null; return null;
} }
@@ -219,7 +230,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment {
} }
return exceptions; return exceptions;
} }
public List<VcsException> commit(List<Change> changes, String preparedComment) { public List<VcsException> commit(List<Change> changes, String preparedComment) {
return commit(changes, preparedComment, FunctionUtil.<Object, Object>nullConstant(), null); return commit(changes, preparedComment, FunctionUtil.<Object, Object>nullConstant(), null);
} }
@@ -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_HEAD = DOT_GIT + slash(MERGE_HEAD);
public static final String GIT_MERGE_MSG = DOT_GIT + slash(MERGE_MSG); 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_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 myConfigFilePath;
private final String myHeadFilePath; private final String myHeadFilePath;