Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
864ac49e
Commit
864ac49e
authored
Mar 05, 2012
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ssh-urls' into development
parents
c4c4bc1f
4f8efc97
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
7 deletions
+51
-7
include/git2/remote.h
+8
-0
src/transport.c
+17
-7
src/transport.h
+5
-0
tests-clar/network/remotes.c
+21
-0
No files found.
include/git2/remote.h
View file @
864ac49e
...
...
@@ -198,6 +198,14 @@ GIT_EXTERN(int) git_remote_update_tips(git_remote *remote);
GIT_EXTERN
(
int
)
git_remote_valid_url
(
const
char
*
url
);
/**
* Return whether the passed URL is supported by this version of the library.
*
* @param url the url to check
* @return 1 if the url is supported, 0 otherwise
*/
GIT_EXTERN
(
int
)
git_remote_supported_url
(
const
char
*
url
);
/**
* Get a list of the configured remotes for a repo
*
* The string array must be freed by the user.
...
...
src/transport.c
View file @
864ac49e
...
...
@@ -9,6 +9,7 @@
#include "git2/remote.h"
#include "git2/net.h"
#include "transport.h"
#include "path.h"
static
struct
{
char
*
prefix
;
...
...
@@ -29,13 +30,20 @@ static git_transport_cb transport_find_fn(const char *url)
{
size_t
i
=
0
;
/* TODO: Parse "example.com:project.git" as an SSH URL */
// First, check to see if it's an obvious URL, which a URL scheme
for
(
i
=
0
;
i
<
GIT_TRANSPORT_COUNT
;
++
i
)
{
if
(
!
strncasecmp
(
url
,
transports
[
i
].
prefix
,
strlen
(
transports
[
i
].
prefix
)))
return
transports
[
i
].
fn
;
}
/* still here? Check to see if the path points to a file on the local file system */
if
((
git_path_exists
(
url
)
==
GIT_SUCCESS
)
&&
git_path_isdir
(
url
))
return
&
git_transport_local
;
/* It could be a SSH remote path. Check to see if there's a : */
if
(
strrchr
(
url
,
':'
))
return
&
git_transport_dummy
;
/* SSH is an unsupported transport mechanism in this version of libgit2 */
return
NULL
;
}
...
...
@@ -57,12 +65,8 @@ int git_transport_new(git_transport **out, const char *url)
fn
=
transport_find_fn
(
url
);
/*
* If we haven't found the transport, we assume we mean a
* local file.
*/
if
(
fn
==
NULL
)
fn
=
&
git_transport_local
;
return
git__throw
(
GIT_EINVALIDARGS
,
"Unsupported URL or non-existent path"
)
;
error
=
fn
(
&
transport
);
if
(
error
<
GIT_SUCCESS
)
...
...
@@ -83,3 +87,9 @@ int git_remote_valid_url(const char *url)
return
transport_find_fn
(
url
)
!=
NULL
;
}
int
git_remote_supported_url
(
const
char
*
url
)
{
git_transport_cb
transport_fn
=
transport_find_fn
(
url
);
return
((
transport_fn
!=
NULL
)
&&
(
transport_fn
!=
&
git_transport_dummy
));
}
src/transport.h
View file @
864ac49e
...
...
@@ -102,6 +102,11 @@ int git_transport_local(struct git_transport **transport);
int
git_transport_git
(
struct
git_transport
**
transport
);
int
git_transport_http
(
struct
git_transport
**
transport
);
int
git_transport_dummy
(
struct
git_transport
**
transport
);
/**
Returns true if the passed URL is valid (a URL with a Git supported scheme,
or pointing to an existing path)
*/
int
git_transport_valid_url
(
const
char
*
url
);
typedef
struct
git_transport
git_transport
;
...
...
tests-clar/network/remotes.c
View file @
864ac49e
#include "clar_libgit2.h"
#include "buffer.h"
#include "refspec.h"
#include "transport.h"
static
git_remote
*
_remote
;
static
git_repository
*
_repo
;
...
...
@@ -30,6 +31,26 @@ void test_network_remotes__parsing(void)
cl_assert
(
!
strcmp
(
git_remote_url
(
_remote
),
"git://github.com/libgit2/libgit2"
));
}
void
test_network_remotes__parsing_ssh_remote
(
void
)
{
cl_assert
(
git_remote_valid_url
(
"git@github.com:libgit2/libgit2.git"
)
);
}
void
test_network_remotes__parsing_local_path_fails_if_path_not_found
(
void
)
{
cl_assert
(
!
git_remote_valid_url
(
"/home/git/repos/libgit2.git"
)
);
}
void
test_network_remotes__supported_transport_methods_are_supported
(
void
)
{
cl_assert
(
git_remote_supported_url
(
"git://github.com/libgit2/libgit2"
)
);
}
void
test_network_remotes__unsupported_transport_methods_are_unsupported
(
void
)
{
cl_assert
(
!
git_remote_supported_url
(
"git@github.com:libgit2/libgit2.git"
)
);
}
void
test_network_remotes__refspec_parsing
(
void
)
{
cl_assert
(
!
strcmp
(
git_refspec_src
(
_refspec
),
"refs/heads/*"
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment