import java.util.Collection;
import java.util.List;
+import org.eclipse.jgit.errors.AmbiguousObjectException;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
assertEquals(id.abbreviate(20), reader.abbreviate(id, 2));
- Collection<ObjectId> matches = reader.resolve(id.abbreviate(8));
+ AbbreviatedObjectId abbrev8 = id.abbreviate(8);
+ Collection<ObjectId> matches = reader.resolve(abbrev8);
assertNotNull(matches);
assertEquals(objects.size(), matches.size());
for (PackedObjectInfo info : objects)
assertTrue("contains " + info.name(), matches.contains(info));
- assertNull("cannot resolve", db.resolve(id.abbreviate(8).name()));
+ try {
+ db.resolve(abbrev8.name());
+ fail("did not throw AmbiguousObjectException");
+ } catch (AmbiguousObjectException err) {
+ assertEquals(abbrev8, err.getAbbreviatedObjectId());
+ matches = err.getCandidates();
+ assertNotNull(matches);
+ assertEquals(objects.size(), matches.size());
+ for (PackedObjectInfo info : objects)
+ assertTrue("contains " + info.name(), matches.contains(info));
+ }
+
assertEquals(id, db.resolve(id.abbreviate(20).name()));
}
import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.errors.AmbiguousObjectException;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
* @param revstr
* A git object references expression
* @return an ObjectId or null if revstr can't be resolved to any ObjectId
+ * @throws AmbiguousObjectException
+ * {@code revstr} contains an abbreviated ObjectId and this
+ * repository contains more than one object which match to the
+ * input abbreviation.
* @throws IOException
* on serious errors
*/
- public ObjectId resolve(final String revstr) throws IOException {
+ public ObjectId resolve(final String revstr)
+ throws AmbiguousObjectException, IOException {
RevWalk rw = new RevWalk(this);
try {
return resolve(rw, revstr);
Collection<ObjectId> matches = reader.resolve(id);
if (matches.size() == 1)
return matches.iterator().next();
+ if (1 < matches.size())
+ throw new AmbiguousObjectException(id, matches);
} finally {
reader.release();
}