Browse Source

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>
tags/v5.3.0.201903061415-rc1
Thomas Wolf 5 years ago
parent
commit
a64fa0bd7f
1 changed files with 26 additions and 6 deletions
  1. 26
    6
      org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java

+ 26
- 6
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java View File

@@ -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 {

Loading…
Cancel
Save