comparison src/com/tmate/hgkit/fs/RepositoryFinder.java @ 1:a3576694a4d1

Repository detection from local/specified directory
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sat, 18 Dec 2010 05:47:35 +0100
parents
children
comparison
equal deleted inserted replaced
0:dbd663faec1f 1:a3576694a4d1
1 /**
2 * Copyright (c) 2010 Artem Tikhomirov
3 */
4 package com.tmate.hgkit.fs;
5
6 import java.io.File;
7
8 import com.tmate.hgkit.ll.HgRepository;
9 import com.tmate.hgkit.ll.LocalHgRepo;
10
11 /**
12 * @author artem
13 */
14 public class RepositoryFinder {
15
16 public HgRepository detect(String[] commandLineArgs) throws Exception {
17 if (commandLineArgs.length == 0) {
18 return detectFromWorkingDir();
19 }
20 return detect(commandLineArgs[0]);
21 }
22
23 public HgRepository detectFromWorkingDir() throws Exception {
24 return detect(System.getProperty("user.dir"));
25 }
26
27 public HgRepository detect(String location) throws Exception /*FIXME Exception type, RepoInitException? */ {
28 File dir = new File(location);
29 File repository;
30 do {
31 repository = new File(dir, ".hg");
32 if (repository.exists() && repository.isDirectory()) {
33 break;
34 }
35 repository = null;
36 dir = dir.getParentFile();
37
38 } while(dir != null);
39 if (repository == null) {
40 return new LocalHgRepo(location);
41 }
42 return new LocalHgRepo(repository);
43 }
44 }