diff options
author | Mathias Kinzler <mathias.kinzler@sap.com> | 2010-12-01 15:10:13 +0100 |
---|---|---|
committer | Mathias Kinzler <mathias.kinzler@sap.com> | 2010-12-01 15:10:13 +0100 |
commit | 59e62ba7e10188c6170bd97ffbd9c8768d9745ea (patch) | |
tree | d422855d75599ed6fe146f0c93949dd8c16928bd /org.eclipse.jgit | |
parent | 7aa1b85821e007c0243772273960069497284290 (diff) | |
download | jgit-59e62ba7e10188c6170bd97ffbd9c8768d9745ea.tar.gz jgit-59e62ba7e10188c6170bd97ffbd9c8768d9745ea.zip |
Rebase Interoperability second part: fix "pop steps"
If the CLI stops a rebase upon conflict, the current
step is already popped from the git-rebase-todo and appended to the
"done" file. The current implementation wrongly pops the step only
after successful cherry-pick.
Change-Id: I8640dda0cbb2a5271ecf75fcbad69410122eeab6
Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java | 46 |
1 files changed, 31 insertions, 15 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 45c66e57b8..fbe7debc45 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -185,6 +185,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> { for (Step step : steps) { if (step.action != Action.PICK) continue; + popSteps(1); Collection<ObjectId> ids = or.resolve(step.commit); if (ids.size() != 1) throw new JGitInternalException( @@ -203,7 +204,6 @@ public class RebaseCommand extends GitCommand<RebaseResult> { .call(); monitor.endTask(); if (newHead == null) { - popSteps(stepsToPop); return new RebaseResult(commitToPick); } stepsToPop++; @@ -238,14 +238,15 @@ public class RebaseCommand extends GitCommand<RebaseResult> { private void popSteps(int numSteps) throws IOException { if (numSteps == 0) return; - List<String> lines = new ArrayList<String>(); - File file = new File(rebaseDir, "git-rebase-todo"); + List<String> todoLines = new ArrayList<String>(); + List<String> poppedLines = new ArrayList<String>(); + File todoFile = new File(rebaseDir, "git-rebase-todo"); + File doneFile = new File(rebaseDir, "done"); BufferedReader br = new BufferedReader(new InputStreamReader( - new FileInputStream(file), "UTF-8")); - int popped = 0; + new FileInputStream(todoFile), "UTF-8")); try { // check if the line starts with a action tag (pick, skip...) - while (popped < numSteps) { + while (poppedLines.size() < numSteps) { String popCandidate = br.readLine(); if (popCandidate == null) break; @@ -256,28 +257,43 @@ public class RebaseCommand extends GitCommand<RebaseResult> { pop = Action.parse(actionToken) != null; } if (pop) - popped++; + poppedLines.add(popCandidate); else - lines.add(popCandidate); + todoLines.add(popCandidate); } String readLine = br.readLine(); while (readLine != null) { - lines.add(readLine); + todoLines.add(readLine); readLine = br.readLine(); } } finally { br.close(); } - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(file), "UTF-8")); + BufferedWriter todoWriter = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(todoFile), "UTF-8")); try { - for (String writeLine : lines) { - bw.write(writeLine); - bw.newLine(); + for (String writeLine : todoLines) { + todoWriter.write(writeLine); + todoWriter.newLine(); } } finally { - bw.close(); + todoWriter.close(); + } + + if (poppedLines.size() > 0) { + // append here + BufferedWriter doneWriter = new BufferedWriter( + new OutputStreamWriter( + new FileOutputStream(doneFile, true), "UTF-8")); + try { + for (String writeLine : poppedLines) { + doneWriter.write(writeLine); + doneWriter.newLine(); + } + } finally { + doneWriter.close(); + } } } |