Here is a new patch that incorporates the test for $GIT_DIR. I don't know
if 'index' is the right directory to test for. It is present both in git
repositories that support SVN and those that don't.
On Mon, Apr 20, 2009 at 2:28 PM, Scott Blum <[email protected]> wrote:
> 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
>>
>>
>>
>
> >
>
--
Eric Z. Ayers - GWT Team - Atlanta, GA USA
http://code.google.com/webtoolkit/
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---
Index: build-tools/ant-gwt/src/com/google/gwt/ant/taskdefs/SvnInfo.java
===================================================================
--- build-tools/ant-gwt/src/com/google/gwt/ant/taskdefs/SvnInfo.java (revision 5262)
+++ build-tools/ant-gwt/src/com/google/gwt/ant/taskdefs/SvnInfo.java (working copy)
@@ -164,14 +164,23 @@
return output;
}
+ /**
+ * Determine if this directory is a part of a .git repository.
+ *
+ * @param dir working directory to start looking for the repository.
+ * @return <code>true</code> if a .git repo is found. Returns
+ * <code>false</false> if a .git repo cannot be found, or if
+ * this directory is part of a subversion repository.
+ */
static boolean looksLikeGit(File dir) {
- dir = dir.getAbsoluteFile();
- while (dir != null) {
- if (new File(dir, ".git").isDirectory()) {
- return true;
- }
- dir = dir.getParentFile();
+ if (looksLikeSvn(dir)) {
+ return false;
}
+ File gitDir = findGitDir(dir);
+
+ if (gitDir != null && gitDir.isDirectory()) {
+ return new File(gitDir, "svn").isDirectory();
+ }
return false;
}
@@ -238,6 +247,35 @@
return url;
}
+ /**
+ * Find the GIT working directory.
+ *
+ * First checks for the presence of the env variable GIT_DIR, then, looks up
+ * the the tree for a directory named '.git'.
+ *
+ * @param dir Current working directory
+ * @return An object representing the .git directory. Returns
+ * <code>null</code> if none can be found.
+ */
+ private static File findGitDir(File dir) {
+ String gitDirPath = System.getenv("GIT_DIR");
+ if (gitDirPath != null) {
+ File gitDir = new File(gitDirPath).getAbsoluteFile();
+ if (gitDir.isDirectory()) {
+ return gitDir;
+ }
+ }
+
+ dir = dir.getAbsoluteFile();
+ while (dir != null) {
+ if (new File(dir, ".git").isDirectory()) {
+ return dir;
+ }
+ dir = dir.getParentFile();
+ }
+ return null;
+ }
+
private String fileprop;
private String outprop;