Skip to content

Commit

Permalink
Remote.xs: Added is_url_valid() and is_url_supported()
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesg committed Apr 25, 2014
1 parent d8ddb18 commit fa6af85
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Git/Raw/Remote.pm
Expand Up @@ -190,6 +190,15 @@ Update the tips to the new status.
Check if the remote is connected.
=head2 is_url_valid( $url )
Check whether C<$url> is a valid remote URL.
=head2 is_url_supported( $url )
Check whether C<$url> the passed URL is supported by this version of the
library.
=head1 AUTHOR
Alessandro Ghedini <alexbio@cpan.org>
Expand Down
24 changes: 24 additions & 0 deletions t/07-remote.t
Expand Up @@ -6,6 +6,30 @@ use Git::Raw;
use Cwd qw(abs_path);
use File::Path qw(make_path rmtree);

is (Git::Raw::Remote -> is_url_valid('/somewhere/on/filesystem'), 0);
is (Git::Raw::Remote -> is_url_valid('somewhere/on/filesystem'), 0);
is (Git::Raw::Remote -> is_url_valid('file:///somewhere/on/filesystem'), 1);
is (Git::Raw::Remote -> is_url_valid('git://somewhere.com/somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_valid('https://somewhere.com/somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_valid('http://somewhere.com/somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_valid('ssh://me@somewhere.com:somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_valid('ssh://me@somewhere.com:/somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_valid('ssh://somewhere.com:somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_valid('ssh://somewhere.com:/somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_valid('me@somewhere.com:somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_valid('me@somewhere.com:/somerepo.git'), 1);

is (Git::Raw::Remote -> is_url_supported('file:///somewhere/on/filesystem'), 1);
is (Git::Raw::Remote -> is_url_supported('git://somewhere.com/somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_supported('https://somewhere.com/somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_supported('http://somewhere.com/somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_supported('ssh://me@somewhere.com:somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_supported('ssh://me@somewhere.com:/somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_supported('ssh://somewhere.com:somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_supported('ssh://somewhere.com:/somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_supported('me@somewhere.com:somerepo.git'), 1);
is (Git::Raw::Remote -> is_url_supported('me@somewhere.com:/somerepo.git'), 1);

my $path = abs_path('t/test_repo');
my $repo = Git::Raw::Repository -> open($path);

Expand Down
26 changes: 26 additions & 0 deletions xs/Remote.xs
Expand Up @@ -449,6 +449,32 @@ is_connected(self)

OUTPUT: RETVAL

SV *
is_url_valid(class, url)
SV *class
SV *url

CODE:
if (!SvPOK(url))
Perl_croak(aTHX_ "Expected a string for 'url'");

RETVAL = newSViv(git_remote_valid_url(SvPVbyte_nolen(url)));

OUTPUT: RETVAL

SV *
is_url_supported(class, url)
SV *class
SV *url

CODE:
if (!SvPOK(url))
Perl_croak(aTHX_ "Expected a string for 'url'");

RETVAL = newSViv(git_remote_supported_url(SvPVbyte_nolen(url)));

OUTPUT: RETVAL

void
DESTROY(self)
SV *self
Expand Down

0 comments on commit fa6af85

Please sign in to comment.