This looks good as far as I can eyeball.  @Eric: what do you think?

On Mon, Apr 20, 2009 at 2:18 PM, Ian Petersen <[email protected]> wrote:

>
> On Mon, Apr 20, 2009 at 10:59 AM, Scott Blum <[email protected]> wrote:
> > That would be a nice enhancement.  Patches welcome. :)
>
> How about this?
>
> static boolean looksLikeGit(File dir) {
>  if (looksLikeSvn(dir)) {
>    // Prefer svn to git.
>    return false;
>  }
>
>   File gitDir = findGitDir(dir);
>
>  return gitDir != null && new File(gitDir, "index").isFile();
> }
>
> static File findGitDir(File dir) {
>  File ret;
>
>  // try $GIT_DIR
>  // is there any point in worrying about SecurityExceptions here?
>  // if this code lacks the ability to access $GIT_DIR, it would
>  // maybe make sense to fall back on the default below.
>  String gitDir = System.getenv("GIT_DIR");
>
>  if (gitDir != null) {
>    ret = new File(gitDir).getAbsoluteFile();
>
>    if (ret.isDirectory()) {
>      return ret;
>    }
>  }
>
>  // try searching for a .git at or above dir
>   dir = dir.getAbsoluteFile();
>  while (dir != null) {
>     ret = new File(ret, ".git");
>    if (ret.isDirectory()) {
>      return ret;
>    }
>    dir = dir.getParentFile();
>  }
>
>  return null;
> }
>
> That was typed directly into email and I haven't written any Java in
> half a year, so at least compile it before doing anything serious.
> Also, it could probably do with a refactoring but that's a real pain
> in a text area.
>
> Ian
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to