diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2018-12-19 11:03:29 +0100 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2019-02-26 16:18:27 +0900 |
commit | a64fa0bd7f0f958ccd87b0cd5e7c1bd39500c636 (patch) | |
tree | 09dc37884bca8de9c611a88819dc7fcb29e9c6cd | |
parent | 60cf85a4a39c34a426e52c4f1fa3f5ef5ba659c5 (diff) | |
download | jgit-a64fa0bd7f0f958ccd87b0cd5e7c1bd39500c636.tar.gz jgit-a64fa0bd7f0f958ccd87b0cd5e7c1bd39500c636.zip |
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 <thomas.wolf@paranor.ch>
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java | 32 |
1 files 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<RebaseResult> { 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<RebaseResult> { 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<RebaseResult> { } 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<RebaseResult> { 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 { |