diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java index ec52e25bd6c6..67e4e199d1b3 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java @@ -29,6 +29,7 @@ import org.zmlx.hg4idea.HgVcsMessages; import org.zmlx.hg4idea.execution.HgCommandException; import org.zmlx.hg4idea.execution.HgCommandExecutor; import org.zmlx.hg4idea.util.HgEncodingUtil; +import org.zmlx.hg4idea.util.HgVersionUtil; import java.io.File; import java.io.IOException; @@ -69,7 +70,7 @@ public class HgCommitCommand { //if it's merge commit, so myFiles is Empty. Need to commit all files in changeList. // see HgCheckinEnviroment->commit() method if (myFiles.isEmpty()) { - commitChunkFiles(Collections.emptyList()); + commitChunkFiles(Collections.emptyList(), false); } else { List relativePaths = ContainerUtil.map2List(myFiles, new Function() { @@ -78,8 +79,13 @@ public class HgCommitCommand { return file.getRelativePath(); } }); - for (List chunk : VcsFileUtil.chunkRelativePaths(relativePaths)) { - commitChunkFiles(chunk); + List> chunkedCommits = VcsFileUtil.chunkRelativePaths(relativePaths); + int size = chunkedCommits.size(); + commitChunkFiles(chunkedCommits.get(0), false); + boolean amendCommit = HgVersionUtil.isAmendSupported(); + for (int i = 1; i < size; i++) { + List chunk = chunkedCommits.get(i); + commitChunkFiles(chunk, amendCommit); } } final MessageBus messageBus = myProject.getMessageBus(); @@ -87,11 +93,14 @@ public class HgCommitCommand { messageBus.syncPublisher(HgVcs.BRANCH_TOPIC).update(myProject, null); } - private void commitChunkFiles(List chunk) throws VcsException { + private void commitChunkFiles(List chunk, boolean amendCommit) throws VcsException { List parameters = new LinkedList(); parameters.add("--logfile"); parameters.add(saveCommitMessage().getAbsolutePath()); parameters.addAll(chunk); + if (amendCommit) { + parameters.add("--amend"); + } HgCommandExecutor executor = new HgCommandExecutor(myProject); executor.setCharset(myCharset); ensureSuccess(executor.executeInCurrentThread(myRoot, "commit", parameters));