CheckoutResult: return paths instead of Files
As discussed in http://egit.eclipse.org/r/#change,2127 we should use paths relative the working directory instead of Files to notify the caller about conflicts and nondeleted files. Change-Id: I034c7bd846f0df78d97bc246f38d411f29713dde Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
This commit is contained in:
parent
8f419dc5e6
commit
e272ca0f14
|
@ -128,9 +128,8 @@ public void testCheckoutToNonExistingBranch() throws JGitInternalException,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCheckoutWithConflict() throws IOException {
|
public void testCheckoutWithConflict() {
|
||||||
CheckoutCommand co = git.checkout();
|
CheckoutCommand co = git.checkout();
|
||||||
File trashFile = writeTrashFile("Test.txt", "Another change");
|
|
||||||
try {
|
try {
|
||||||
writeTrashFile("Test.txt", "Another change");
|
writeTrashFile("Test.txt", "Another change");
|
||||||
assertEquals(Status.NOT_TRIED, co.getResult().getStatus());
|
assertEquals(Status.NOT_TRIED, co.getResult().getStatus());
|
||||||
|
@ -138,7 +137,7 @@ public void testCheckoutWithConflict() throws IOException {
|
||||||
fail("Should have failed");
|
fail("Should have failed");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assertEquals(Status.CONFLICTS, co.getResult().getStatus());
|
assertEquals(Status.CONFLICTS, co.getResult().getStatus());
|
||||||
assertTrue(co.getResult().getConflictList().contains(trashFile));
|
assertTrue(co.getResult().getConflictList().contains("Test.txt"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +170,7 @@ public void testCheckoutWithNonDeletedFiles() throws Exception {
|
||||||
co.setName("test").call();
|
co.setName("test").call();
|
||||||
assertTrue(testFile.exists());
|
assertTrue(testFile.exists());
|
||||||
assertEquals(Status.NONDELETED, co.getResult().getStatus());
|
assertEquals(Status.NONDELETED, co.getResult().getStatus());
|
||||||
assertTrue(co.getResult().getUndeletedList().contains(testFile));
|
assertTrue(co.getResult().getUndeletedList().contains("Test.txt"));
|
||||||
} finally {
|
} finally {
|
||||||
fis.close();
|
fis.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,8 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.jgit.api;
|
package org.eclipse.jgit.api;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.eclipse.jgit.JGitText;
|
import org.eclipse.jgit.JGitText;
|
||||||
import org.eclipse.jgit.api.CheckoutResult.Status;
|
import org.eclipse.jgit.api.CheckoutResult.Status;
|
||||||
|
@ -141,11 +138,8 @@ public Ref call() throws JGitInternalException, RefAlreadyExistsException,
|
||||||
try {
|
try {
|
||||||
dco.checkout();
|
dco.checkout();
|
||||||
} catch (CheckoutConflictException e) {
|
} catch (CheckoutConflictException e) {
|
||||||
List<File> fileList = new ArrayList<File>();
|
status = new CheckoutResult(Status.CONFLICTS, dco
|
||||||
for (String filePath : dco.getConflicts()) {
|
.getConflicts());
|
||||||
fileList.add(new File(repo.getWorkTree(), filePath));
|
|
||||||
}
|
|
||||||
status = new CheckoutResult(Status.CONFLICTS, fileList);
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
Ref ref = repo.getRef(name);
|
Ref ref = repo.getRef(name);
|
||||||
|
@ -183,12 +177,9 @@ public Ref call() throws JGitInternalException, RefAlreadyExistsException,
|
||||||
throw new JGitInternalException(MessageFormat.format(JGitText
|
throw new JGitInternalException(MessageFormat.format(JGitText
|
||||||
.get().checkoutUnexpectedResult, updateResult.name()));
|
.get().checkoutUnexpectedResult, updateResult.name()));
|
||||||
|
|
||||||
if (!repo.isBare() && !dco.getToBeDeleted().isEmpty()) {
|
if (!dco.getToBeDeleted().isEmpty()) {
|
||||||
List<File> fileList = new ArrayList<File>();
|
status = new CheckoutResult(Status.NONDELETED, dco
|
||||||
for (String filePath : dco.getToBeDeleted()) {
|
.getToBeDeleted());
|
||||||
fileList.add(new File(repo.getWorkTree(), filePath));
|
|
||||||
}
|
|
||||||
status = new CheckoutResult(Status.NONDELETED, fileList);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status = CheckoutResult.OK_RESULT;
|
status = CheckoutResult.OK_RESULT;
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.jgit.api;
|
package org.eclipse.jgit.api;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -97,20 +96,20 @@ public enum Status {
|
||||||
|
|
||||||
private final Status myStatus;
|
private final Status myStatus;
|
||||||
|
|
||||||
private final List<File> conflictList;
|
private final List<String> conflictList;
|
||||||
|
|
||||||
private final List<File> undeletedList;
|
private final List<String> undeletedList;
|
||||||
|
|
||||||
CheckoutResult(Status status, List<File> fileList) {
|
CheckoutResult(Status status, List<String> fileList) {
|
||||||
myStatus = status;
|
myStatus = status;
|
||||||
if (status == Status.CONFLICTS)
|
if (status == Status.CONFLICTS)
|
||||||
this.conflictList = fileList;
|
this.conflictList = fileList;
|
||||||
else
|
else
|
||||||
this.conflictList = new ArrayList<File>(0);
|
this.conflictList = new ArrayList<String>(0);
|
||||||
if (status == Status.NONDELETED)
|
if (status == Status.NONDELETED)
|
||||||
this.undeletedList = fileList;
|
this.undeletedList = fileList;
|
||||||
else
|
else
|
||||||
this.undeletedList = new ArrayList<File>(0);
|
this.undeletedList = new ArrayList<String>(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +124,7 @@ public Status getStatus() {
|
||||||
* @return the list of files that created a checkout conflict, or an empty
|
* @return the list of files that created a checkout conflict, or an empty
|
||||||
* list if {@link #getStatus()} is not {@link Status#CONFLICTS};
|
* list if {@link #getStatus()} is not {@link Status#CONFLICTS};
|
||||||
*/
|
*/
|
||||||
public List<File> getConflictList() {
|
public List<String> getConflictList() {
|
||||||
return conflictList;
|
return conflictList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +133,7 @@ public List<File> getConflictList() {
|
||||||
* an empty list if {@link #getStatus()} is not
|
* an empty list if {@link #getStatus()} is not
|
||||||
* {@link Status#NONDELETED};
|
* {@link Status#NONDELETED};
|
||||||
*/
|
*/
|
||||||
public List<File> getUndeletedList() {
|
public List<String> getUndeletedList() {
|
||||||
return undeletedList;
|
return undeletedList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue