OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * This file contains functionality for getting dart version numbers using | 6 * This file contains functionality for getting dart version numbers using |
7 * our standard version construction method. Systems that does not include this | 7 * our standard version construction method. Systems that does not include this |
8 * file should emulate the structure for revision numbers that we have here. | 8 * file should emulate the structure for revision numbers that we have here. |
9 * | 9 * |
10 * The version number of a dart build is constructed as follows: | 10 * The version number of a dart build is constructed as follows: |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 key = "USERNAME"; | 171 key = "USERNAME"; |
172 } | 172 } |
173 if (!Platform.environment.containsKey(key)) return ""; | 173 if (!Platform.environment.containsKey(key)) return ""; |
174 var username = Platform.environment[key]; | 174 var username = Platform.environment[key]; |
175 // If this is a production build, i.e., this is something we are shipping, | 175 // If this is a production build, i.e., this is something we are shipping, |
176 // don't suffix the version with the username. | 176 // don't suffix the version with the username. |
177 if (isProductionBuild(username)) return ""; | 177 if (isProductionBuild(username)) return ""; |
178 return username; | 178 return username; |
179 } | 179 } |
180 | 180 |
| 181 bool isGitRepository() { |
| 182 var currentPath = new Path.fromNative(new Directory.current().path); |
| 183 while (!new Directory.fromPath(currentPath.append(".git")).existsSync()) { |
| 184 currentPath = currentPath.directoryPath; |
| 185 if (currentPath.toString() == "/") { |
| 186 break; |
| 187 } |
| 188 } |
| 189 return new Directory.fromPath(currentPath.append(".git")).existsSync(); |
| 190 } |
| 191 |
181 RepositoryType get repositoryType { | 192 RepositoryType get repositoryType { |
182 if (new Directory(".svn").existsSync()) return RepositoryType.SVN; | 193 if (new Directory(".svn").existsSync()) return RepositoryType.SVN; |
183 if (new Directory(".git").existsSync()) return RepositoryType.GIT; | 194 if (isGitRepository()) return RepositoryType.GIT; |
184 return RepositoryType.UNKNOWN; | 195 return RepositoryType.UNKNOWN; |
185 } | 196 } |
186 } | 197 } |
187 | 198 |
188 class RepositoryType { | 199 class RepositoryType { |
189 static final RepositoryType SVN = const RepositoryType("SVN"); | 200 static final RepositoryType SVN = const RepositoryType("SVN"); |
190 static final RepositoryType GIT = const RepositoryType("GIT"); | 201 static final RepositoryType GIT = const RepositoryType("GIT"); |
191 static final RepositoryType UNKNOWN = const RepositoryType("UNKNOWN"); | 202 static final RepositoryType UNKNOWN = const RepositoryType("UNKNOWN"); |
192 | 203 |
193 const RepositoryType(String this.name); | 204 const RepositoryType(String this.name); |
194 | 205 |
195 static RepositoryType guessType() { | 206 static RepositoryType guessType() { |
196 if (new Directory(".svn").existsSync()) return RepositoryType.SVN; | 207 if (new Directory(".svn").existsSync()) return RepositoryType.SVN; |
197 if (new Directory(".git").existsSync()) return RepositoryType.GIT; | 208 if (new Directory(".git").existsSync()) return RepositoryType.GIT; |
198 return RepositoryType.UNKNOWN; | 209 return RepositoryType.UNKNOWN; |
199 } | 210 } |
200 | 211 |
201 String toString() => name; | 212 String toString() => name; |
202 | 213 |
203 final String name; | 214 final String name; |
204 } | 215 } |
OLD | NEW |