diff src/org/tmatesoft/hg/repo/HgLookup.java @ 148:1a7a9a20e1f9

Exceptions, javadoc. Initial cancel and progress support
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 23 Feb 2011 22:36:28 +0100
parents a3a2e5deb320
children 305ee74c0aa6
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgLookup.java	Tue Feb 22 15:49:26 2011 +0100
+++ b/src/org/tmatesoft/hg/repo/HgLookup.java	Wed Feb 23 22:36:28 2011 +0100
@@ -17,24 +17,28 @@
 package org.tmatesoft.hg.repo;
 
 import java.io.File;
+import java.io.IOException;
+
+import org.tmatesoft.hg.core.HgException;
 
 /**
+ * Utility methods to find Mercurial repository at a given location
  * 
  * @author Artem Tikhomirov
  * @author TMate Software Ltd.
  */
 public class HgLookup {
 
-	public HgRepository detectFromWorkingDir() throws Exception {
+	public HgRepository detectFromWorkingDir() throws HgException {
 		return detect(System.getProperty("user.dir"));
 	}
 
-	public HgRepository detect(String location) throws Exception /*FIXME Exception type, RepoInitException? */ {
+	public HgRepository detect(String location) throws HgException {
 		return detect(new File(location));
 	}
 
 	// look up in specified location and above
-	public HgRepository detect(File location) throws Exception {
+	public HgRepository detect(File location) throws HgException {
 		File dir = location;
 		File repository;
 		do {
@@ -50,6 +54,11 @@
 			// return invalid repository
 			return new HgRepository(location.getPath());
 		}
-		return new HgRepository(repository);
+		try {
+			String repoPath = repository.getParentFile().getCanonicalPath();
+			return new HgRepository(repoPath, repository);
+		} catch (IOException ex) {
+			throw new HgException(location.toString(), ex);
+		}
 	}
 }