Skip to content

Commit

Permalink
Merge commit '2shot/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Sep 5, 2009
2 parents ce8df95 + 39ecf3e commit 4319358
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,4 +2,5 @@ META.yml
Makefile Makefile
inc/ inc/
pm_to_blib pm_to_blib
blib
*~ *~
18 changes: 11 additions & 7 deletions lib/Module/Install/Repository.pm
Expand Up @@ -29,13 +29,17 @@ sub _find_repo {
my ($execute) = @_; my ($execute) = @_;


if (-e ".git") { if (-e ".git") {
# TODO support remote besides 'origin'? foreach my $name (qw(origin github)) {
if ($execute->('git remote show -n origin') =~ /URL: (.*)$/m) { my $git_output = $execute->("git remote show -n $name");
# XXX Make it public clone URL, but this only works with github if ($git_output =~ /Tracked remote branch/ && $git_output =~ /URL: (.*)$/m) {
my $git_url = $1; # XXX Make it public clone URL, but this only works with github
$git_url =~ s![\w\-]+\@([^:]+):!git://$1/!; my $git_url = $1;
return $git_url; $git_url =~ s![\w\-]+\@([^:]+):!git://$1/!;
} elsif ($execute->('git svn info') =~ /URL: (.*)$/m) { return $git_url;
}
}

if ($execute->('git svn info') =~ /URL: (.*)$/m) {
return $1; return $1;
} }
} elsif (-e ".svn") { } elsif (-e ".svn") {
Expand Down
29 changes: 24 additions & 5 deletions t/01_find_repo.t
@@ -1,6 +1,6 @@
use strict; use strict;
use warnings; use warnings;
use Test::More tests => 2; use Test::More tests => 3;


use Module::Install::Repository; use Module::Install::Repository;


Expand All @@ -22,15 +22,34 @@ END
}->{ $s }; }->{ $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 { sub test {
my ($basename) = @_; my ($basename, $func) = @_;


my $dir = tempdir(CLEANUP => 1); my $dir = tempdir(CLEANUP => 1);
dir("$dir/$basename")->mkpath; dir("$dir/$basename")->mkpath;
chdir($dir); 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('.git',\&fake_execute), 'git://github.com/miyagawa/module-install-repository.git', 'Git origin');
is(test('.hg'), 'http://example.com/foo/bar/', 'Mercurial'); 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.