Permalink
Browse files

Merge commit '2shot/master'

  • Loading branch information...
miyagawa committed Sep 5, 2009
2 parents ce8df95 + 39ecf3e commit 43193585711b2d46df0cf67cd73fff89a3393dbe
Showing with 36 additions and 12 deletions.
  1. +1 −0 .gitignore
  2. +11 −7 lib/Module/Install/Repository.pm
  3. +24 −5 t/01_find_repo.t
View
@@ -2,4 +2,5 @@ META.yml
Makefile
inc/
pm_to_blib
+blib
*~
@@ -29,13 +29,17 @@ sub _find_repo {
my ($execute) = @_;
if (-e ".git") {
- # TODO support remote besides 'origin'?
- if ($execute->('git remote show -n origin') =~ /URL: (.*)$/m) {
- # XXX Make it public clone URL, but this only works with github
- my $git_url = $1;
- $git_url =~ s![\w\-]+\@([^:]+):!git://$1/!;
- return $git_url;
- } elsif ($execute->('git svn info') =~ /URL: (.*)$/m) {
+ foreach my $name (qw(origin github)) {
+ my $git_output = $execute->("git remote show -n $name");
+ if ($git_output =~ /Tracked remote branch/ && $git_output =~ /URL: (.*)$/m) {
+ # XXX Make it public clone URL, but this only works with github
+ my $git_url = $1;
+ $git_url =~ s![\w\-]+\@([^:]+):!git://$1/!;
+ return $git_url;
+ }
+ }
+
+ if ($execute->('git svn info') =~ /URL: (.*)$/m) {
return $1;
}
} elsif (-e ".svn") {
View
@@ -1,6 +1,6 @@
use strict;
use warnings;
-use Test::More tests => 2;
+use Test::More tests => 3;
use Module::Install::Repository;
@@ -22,15 +22,34 @@ END
}->{ $s };
}
+sub fake_execute2 {
+ my ($s) = @_;
+ return {
+ 'git remote show -n origin' => <<'END',
+* remote origin
+ URL: origin
+END
+ 'git remote show -n github' => <<'END',
+* remote github
+ URL: git@github.com:2shortplanks/test-enhancedis.git
+ master
+ Tracked remote branch
+ master
+END
+ }->{ $s };
+
+}
+
sub test {
- my ($basename) = @_;
+ my ($basename, $func) = @_;
my $dir = tempdir(CLEANUP => 1);
dir("$dir/$basename")->mkpath;
chdir($dir);
- return Module::Install::Repository::_find_repo(\&fake_execute);
+ return Module::Install::Repository::_find_repo($func);
}
-is(test('.git'), 'git://github.com/miyagawa/module-install-repository.git', 'Git');
-is(test('.hg'), 'http://example.com/foo/bar/', 'Mercurial');
+is(test('.git',\&fake_execute), 'git://github.com/miyagawa/module-install-repository.git', 'Git origin');
+is(test('.git',\&fake_execute2), 'git://github.com/2shortplanks/test-enhancedis.git', 'Git github');
+is(test('.hg',\&fake_execute), 'http://example.com/foo/bar/', 'Mercurial');

0 comments on commit 4319358

Please sign in to comment.