From e272ca0f1429440af3fde06387b8815a7f9d4547 Mon Sep 17 00:00:00 2001 From: Mathias Kinzler Date: Tue, 21 Dec 2010 10:06:19 +0100 Subject: [PATCH] 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 --- .../eclipse/jgit/api/CheckoutCommandTest.java | 7 +++---- .../org/eclipse/jgit/api/CheckoutCommand.java | 19 +++++-------------- .../org/eclipse/jgit/api/CheckoutResult.java | 15 +++++++-------- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java index 2abd9d84e..1166464d5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java @@ -128,9 +128,8 @@ public void testCheckoutToNonExistingBranch() throws JGitInternalException, } } - public void testCheckoutWithConflict() throws IOException { + public void testCheckoutWithConflict() { CheckoutCommand co = git.checkout(); - File trashFile = writeTrashFile("Test.txt", "Another change"); try { writeTrashFile("Test.txt", "Another change"); assertEquals(Status.NOT_TRIED, co.getResult().getStatus()); @@ -138,7 +137,7 @@ public void testCheckoutWithConflict() throws IOException { fail("Should have failed"); } catch (Exception e) { 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(); assertTrue(testFile.exists()); assertEquals(Status.NONDELETED, co.getResult().getStatus()); - assertTrue(co.getResult().getUndeletedList().contains(testFile)); + assertTrue(co.getResult().getUndeletedList().contains("Test.txt")); } finally { fis.close(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java index cb261a0ac..dcd8fc3fc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java @@ -42,11 +42,8 @@ */ package org.eclipse.jgit.api; -import java.io.File; import java.io.IOException; import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; import org.eclipse.jgit.JGitText; import org.eclipse.jgit.api.CheckoutResult.Status; @@ -141,11 +138,8 @@ public Ref call() throws JGitInternalException, RefAlreadyExistsException, try { dco.checkout(); } catch (CheckoutConflictException e) { - List fileList = new ArrayList(); - for (String filePath : dco.getConflicts()) { - fileList.add(new File(repo.getWorkTree(), filePath)); - } - status = new CheckoutResult(Status.CONFLICTS, fileList); + status = new CheckoutResult(Status.CONFLICTS, dco + .getConflicts()); throw e; } Ref ref = repo.getRef(name); @@ -183,12 +177,9 @@ public Ref call() throws JGitInternalException, RefAlreadyExistsException, throw new JGitInternalException(MessageFormat.format(JGitText .get().checkoutUnexpectedResult, updateResult.name())); - if (!repo.isBare() && !dco.getToBeDeleted().isEmpty()) { - List fileList = new ArrayList(); - for (String filePath : dco.getToBeDeleted()) { - fileList.add(new File(repo.getWorkTree(), filePath)); - } - status = new CheckoutResult(Status.NONDELETED, fileList); + if (!dco.getToBeDeleted().isEmpty()) { + status = new CheckoutResult(Status.NONDELETED, dco + .getToBeDeleted()); } else status = CheckoutResult.OK_RESULT; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutResult.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutResult.java index bddfe2be5..19b64229d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutResult.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutResult.java @@ -42,7 +42,6 @@ */ package org.eclipse.jgit.api; -import java.io.File; import java.util.ArrayList; import java.util.List; @@ -97,20 +96,20 @@ public enum Status { private final Status myStatus; - private final List conflictList; + private final List conflictList; - private final List undeletedList; + private final List undeletedList; - CheckoutResult(Status status, List fileList) { + CheckoutResult(Status status, List fileList) { myStatus = status; if (status == Status.CONFLICTS) this.conflictList = fileList; else - this.conflictList = new ArrayList(0); + this.conflictList = new ArrayList(0); if (status == Status.NONDELETED) this.undeletedList = fileList; else - this.undeletedList = new ArrayList(0); + this.undeletedList = new ArrayList(0); } @@ -125,7 +124,7 @@ public Status getStatus() { * @return the list of files that created a checkout conflict, or an empty * list if {@link #getStatus()} is not {@link Status#CONFLICTS}; */ - public List getConflictList() { + public List getConflictList() { return conflictList; } @@ -134,7 +133,7 @@ public List getConflictList() { * an empty list if {@link #getStatus()} is not * {@link Status#NONDELETED}; */ - public List getUndeletedList() { + public List getUndeletedList() { return undeletedList; }