Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2352 - add the functionality of removing with git address #2368

Merged
merged 2 commits into from Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/core/Project.js
Expand Up @@ -213,6 +213,20 @@ Project.prototype.update = function (names, options) {
});
};

function resolveUrlNames(names, flattened)
{
for (var i = 0; i < names.length; i++)
if (! flattened[names[i]])
{
var url = names[i].trim().replace(/\/$/, '');
var packName;
for (packName in flattened)
if (! ( !flattened[packName].source))
if (url == flattened[packName].source.trim().replace(/\/$/, ''))
names[i] = packName;
}
}

Project.prototype.uninstall = function (names, options) {
var that = this;
var packages = {};
Expand All @@ -230,6 +244,7 @@ Project.prototype.uninstall = function (names, options) {
// Fill in the packages to be uninstalled
.spread(function (json, tree, flattened) {
var promise = Q.resolve();
resolveUrlNames(names, flattened);

names.forEach(function (name) {
var decEndpoint = flattened[name];
Expand Down
17 changes: 17 additions & 0 deletions test/commands/uninstall.js
Expand Up @@ -99,4 +99,21 @@ describe('bower uninstall', function () {
});
});

it('removes a project with url from absolute path', function () {
var targetPath = path.resolve(tempDir.path, 'other_directory/underscore');
mkdirp.sync(targetPath);
fs.writeFileSync(path.join(targetPath, '.bower.json'), '{ "name": "underscore", "_source": "git://github.com/user/repo.git" }');

return helpers.run(uninstall, [['git://github.com/user/repo.git'], undefined, {
cwd: tempDir.path,
directory: path.resolve(tempDir.path, 'other_directory'),
interactive: true
}])
.then(function () {
expect(function () {
fs.statSync(targetPath);
}).to.throwException(/no such file or directory/);
});
});

});