Merge "Rebase Interoperability second part: fix "pop steps""
This commit is contained in:
commit
a51f44edb0
|
@ -327,7 +327,7 @@ public void testAbortOnConflict() throws Exception {
|
|||
assertTrue(new File(db.getDirectory(), "rebase-merge").exists());
|
||||
// the first one should be included, so we should have left two picks in
|
||||
// the file
|
||||
assertEquals(2, countPicks());
|
||||
assertEquals(1, countPicks());
|
||||
|
||||
// rebase should not succeed in this state
|
||||
try {
|
||||
|
@ -416,7 +416,7 @@ public void testAbortOnConflictFileCreationAndDeletion() throws Exception {
|
|||
assertTrue(new File(db.getDirectory(), "rebase-merge").exists());
|
||||
// the first one should be included, so we should have left two picks in
|
||||
// the file
|
||||
assertEquals(1, countPicks());
|
||||
assertEquals(0, countPicks());
|
||||
|
||||
assertFalse(file2.exists());
|
||||
assertFalse(file3.exists());
|
||||
|
|
|
@ -185,6 +185,7 @@ public RebaseResult call() throws NoHeadException, RefNotFoundException,
|
|||
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 RebaseResult call() throws NoHeadException, RefNotFoundException,
|
|||
.call();
|
||||
monitor.endTask();
|
||||
if (newHead == null) {
|
||||
popSteps(stepsToPop);
|
||||
return new RebaseResult(commitToPick);
|
||||
}
|
||||
stepsToPop++;
|
||||
|
@ -238,14 +238,15 @@ public RebaseResult call() throws NoHeadException, RefNotFoundException,
|
|||
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 @@ private void popSteps(int numSteps) throws IOException {
|
|||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue