Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Unified Diff: sdk/lib/_internal/pub/lib/src/source/git.dart

Issue 448933002: Support Git in pub global activate. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise! Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/pub/lib/src/source/git.dart
diff --git a/sdk/lib/_internal/pub/lib/src/source/git.dart b/sdk/lib/_internal/pub/lib/src/source/git.dart
index 9f4c38c32c9ffb9be0ebeb9c62528107feb7e0fc..9851677b3635f6f1e5fd945e4c9c4ad19c0dcfc6 100644
--- a/sdk/lib/_internal/pub/lib/src/source/git.dart
+++ b/sdk/lib/_internal/pub/lib/src/source/git.dart
@@ -18,12 +18,28 @@ import 'cached.dart';
/// A package source that gets packages from Git repos.
class GitSource extends CachedSource {
+ /// Given a valid git package description, returns the URL of the repository
+ /// it pulls from.
+ static String urlFromDescription(description) => description["url"];
+
final name = "git";
/// The paths to the canonical clones of repositories for which "git fetch"
/// has already been run during this run of pub.
final _updatedRepos = new Set<String>();
+ /// Given a Git repo that contains a pub package, gets the name of the pub
+ /// package.
+ Future<String> getPackageNameFromRepo(String repo) {
+ // Clone the repo to a temp directory.
+ return withTempDir((tempDir) {
+ return _clone(repo, tempDir, shallow: true).then((_) {
+ var pubspec = new Pubspec.load(tempDir, systemCache.sources);
+ return pubspec.name;
+ });
+ });
+ }
+
/// Since we don't have an easy way to read from a remote Git repo, this
/// just installs [id] into the system cache, then describes it from there.
Future<Pubspec> describeUncached(PackageId id) {
@@ -134,10 +150,10 @@ class GitSource extends CachedSource {
var failures = 0;
var packages = listDir(systemCacheRoot)
- .where((entry) => dirExists(path.join(entry, ".git")))
- .map((packageDir) => new Package.load(null, packageDir,
- systemCache.sources))
- .toList();
+ .where((entry) => dirExists(path.join(entry, ".git")))
+ .map((packageDir) => new Package.load(null, packageDir,
+ systemCache.sources))
+ .toList();
// Note that there may be multiple packages with the same name and version
// (pinned to different commits). The sort order of those is unspecified.
@@ -222,13 +238,17 @@ class GitSource extends CachedSource {
/// If [mirror] is true, create a bare, mirrored clone. This doesn't check out
/// the working tree, but instead makes the repository a local mirror of the
/// remote repository. See the manpage for `git clone` for more information.
nweiz 2014/08/14 00:40:54 Document [shallow].
Bob Nystrom 2014/08/15 00:06:41 Done.
- Future _clone(String from, String to, {bool mirror: false}) {
+ Future _clone(String from, String to, {bool mirror: false,
+ bool shallow: false}) {
return syncFuture(() {
// Git on Windows does not seem to automatically create the destination
// directory.
ensureDir(to);
var args = ["clone", from, to];
+
if (mirror) args.insert(1, "--mirror");
+ if (shallow) args.insertAll(1, ["--depth", "1"]);
+
return git.run(args);
}).then((result) => null);
}

Powered by Google App Engine
This is Rietveld 408576698