blob: c504e072b0773c1ce34aa1033e1e8455fd6ddc82 [file] [log] [blame]
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:path/path.dart' as p;
import 'package:test/test.dart';
import 'package:pub/src/io.dart';
import '../../descriptor.dart' as d;
import '../../test_pub.dart';
main() {
// Regression test for issue 20947.
test(
'checks out an unfetched and locked revision of a cached '
'repository', () async {
ensureGit();
// In order to get a lockfile that refers to a newer revision than is in the
// cache, we'll switch between two caches. First we ensure that the repo is
// in the first cache.
await d.git(
'foo.git', [d.libDir('foo'), d.libPubspec('foo', '1.0.0')]).create();
await d.appDir({
"foo": {"git": "../foo.git"}
}).create();
await pubGet();
// Switch to a new cache.
renameInSandbox(cachePath, "$cachePath.old");
// Make the lockfile point to a new revision of the git repository.
await d.git('foo.git',
[d.libDir('foo', 'foo 2'), d.libPubspec('foo', '1.0.0')]).commit();
await pubUpgrade(output: contains("Changed 1 dependency!"));
// Switch back to the old cache.
var cacheDir = p.join(d.sandbox, cachePath);
deleteEntry(cacheDir);
renameInSandbox("$cachePath.old", cacheDir);
// Get the updated version of the git dependency based on the lockfile.
// TODO(rnystrom): Remove "--packages-dir" and validate using the
// ".packages" file instead of looking in the "packages" directory.
await pubGet(args: ["--packages-dir"]);
await d.dir(cachePath, [
d.dir('git', [
d.dir('cache', [d.gitPackageRepoCacheDir('foo')]),
d.gitPackageRevisionCacheDir('foo'),
d.gitPackageRevisionCacheDir('foo', 2)
])
]).validate();
await d.dir(packagesPath, [
d.dir('foo', [d.file('foo.dart', 'main() => "foo 2";')])
]).validate();
});
}