From a64fa0bd7f0f958ccd87b0cd5e7c1bd39500c636 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Wed, 19 Dec 2018 11:03:29 +0100 Subject: [PATCH] RebaseCommand: fix ONTO_NAME, and --preserve-merges is interactive ONTO_NAME must be "onto_name", not "onto-name". For native git, --preserve-merges is an interactive mode. Create the INTERACTIVE marker file, otherwise a native git rebase --continue will fall back into rebase --merge mode before git 2.19.0 since it started looking for the REWRITTEN directory to make the distinction only then.[1] This allows a JGit interactive rebase to be continued via native git rebase --continue. [1] https://github.com/git/git/commit/6d98d0c0 Bug: 511487 Change-Id: I13850e0fd96ac77d03fbb581c8790d76648dbbc6 Signed-off-by: Thomas Wolf --- .../org/eclipse/jgit/api/RebaseCommand.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index 9653c365b2..416a6c2dfc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -158,7 +158,7 @@ public class RebaseCommand extends GitCommand { private static final String ONTO = "onto"; //$NON-NLS-1$ - private static final String ONTO_NAME = "onto-name"; //$NON-NLS-1$ + private static final String ONTO_NAME = "onto_name"; //$NON-NLS-1$ private static final String PATCH = "patch"; //$NON-NLS-1$ @@ -1123,7 +1123,10 @@ public class RebaseCommand extends GitCommand { rebaseState.createFile(HEAD_NAME, headName); rebaseState.createFile(ONTO, upstreamCommit.name()); rebaseState.createFile(ONTO_NAME, upstreamCommitName); - if (isInteractive()) { + if (isInteractive() || preserveMerges) { + // --preserve-merges is an interactive mode for native git. Without + // this, native git rebase --continue after a conflict would fall + // into merge mode. rebaseState.createFile(INTERACTIVE, ""); //$NON-NLS-1$ } rebaseState.createFile(QUIET, ""); //$NON-NLS-1$ @@ -1706,7 +1709,20 @@ public class RebaseCommand extends GitCommand { } public String readFile(String name) throws IOException { - return readFile(getDir(), name); + try { + return readFile(getDir(), name); + } catch (FileNotFoundException e) { + if (ONTO_NAME.equals(name)) { + // Older JGit mistakenly wrote a file "onto-name" instead of + // "onto_name". Try that wrong name just in case somebody + // upgraded while a rebase started by JGit was in progress. + File oldFile = getFile(ONTO_NAME.replace('_', '-')); + if (oldFile.exists()) { + return readFile(oldFile); + } + } + throw e; + } } public void createFile(String name, String content) throws IOException { @@ -1721,14 +1737,18 @@ public class RebaseCommand extends GitCommand { return (getDir().getName() + "/" + name); //$NON-NLS-1$ } - private static String readFile(File directory, String fileName) - throws IOException { - byte[] content = IO.readFully(new File(directory, fileName)); + private static String readFile(File file) throws IOException { + byte[] content = IO.readFully(file); // strip off the last LF int end = RawParseUtils.prevLF(content, content.length); return RawParseUtils.decode(content, 0, end + 1); } + private static String readFile(File directory, String fileName) + throws IOException { + return readFile(new File(directory, fileName)); + } + private static void createFile(File parentDir, String name, String content) throws IOException { -- 2.39.5