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
58582cd0
Commit
58582cd0
authored
Jan 26, 2014
by
Edward Thomson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2057 from GrahamDennis/local-file-url-push-fix
Fix local push to file:// URL.
parents
ca55fc63
8bf476ac
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
9 deletions
+75
-9
src/transports/local.c
+35
-9
tests/network/remote/local.c
+40
-0
No files found.
src/transports/local.c
View file @
58582cd0
...
@@ -156,6 +156,24 @@ on_error:
...
@@ -156,6 +156,24 @@ on_error:
return
-
1
;
return
-
1
;
}
}
static
int
path_from_url_or_path
(
git_buf
*
local_path_out
,
const
char
*
url_or_path
)
{
int
error
;
/* If url_or_path begins with file:// treat it as a URL */
if
(
!
git__prefixcmp
(
url_or_path
,
"file://"
))
{
if
((
error
=
git_path_fromurl
(
local_path_out
,
url_or_path
))
<
0
)
{
return
error
;
}
}
else
{
/* We assume url_or_path is already a path */
if
((
error
=
git_buf_sets
(
local_path_out
,
url_or_path
))
<
0
)
{
return
error
;
}
}
return
0
;
}
/*
/*
* Try to open the url as a git directory. The direction doesn't
* Try to open the url as a git directory. The direction doesn't
* matter in this case because we're calulating the heads ourselves.
* matter in this case because we're calulating the heads ourselves.
...
@@ -181,18 +199,13 @@ static int local_connect(
...
@@ -181,18 +199,13 @@ static int local_connect(
t
->
direction
=
direction
;
t
->
direction
=
direction
;
t
->
flags
=
flags
;
t
->
flags
=
flags
;
/* The repo layer doesn't want the prefix */
/* 'url' may be a url or path; convert to a path */
if
(
!
git__prefixcmp
(
t
->
url
,
"file://"
))
{
if
((
error
=
path_from_url_or_path
(
&
buf
,
url
))
<
0
)
{
if
(
git_path_fromurl
(
&
buf
,
t
->
url
)
<
0
)
{
git_buf_free
(
&
buf
);
git_buf_free
(
&
buf
);
return
-
1
;
return
error
;
}
}
path
=
git_buf_cstr
(
&
buf
);
path
=
git_buf_cstr
(
&
buf
);
}
else
{
/* We assume transport->url is already a path */
path
=
t
->
url
;
}
error
=
git_repository_open
(
&
repo
,
path
);
error
=
git_repository_open
(
&
repo
,
path
);
git_buf_free
(
&
buf
);
git_buf_free
(
&
buf
);
...
@@ -344,11 +357,24 @@ static int local_push(
...
@@ -344,11 +357,24 @@ static int local_push(
git_repository
*
remote_repo
=
NULL
;
git_repository
*
remote_repo
=
NULL
;
push_spec
*
spec
;
push_spec
*
spec
;
char
*
url
=
NULL
;
char
*
url
=
NULL
;
const
char
*
path
;
git_buf
buf
=
GIT_BUF_INIT
;
int
error
;
int
error
;
unsigned
int
i
;
unsigned
int
i
;
size_t
j
;
size_t
j
;
if
((
error
=
git_repository_open
(
&
remote_repo
,
push
->
remote
->
url
))
<
0
)
/* 'push->remote->url' may be a url or path; convert to a path */
if
((
error
=
path_from_url_or_path
(
&
buf
,
push
->
remote
->
url
))
<
0
)
{
git_buf_free
(
&
buf
);
return
error
;
}
path
=
git_buf_cstr
(
&
buf
);
error
=
git_repository_open
(
&
remote_repo
,
path
);
git_buf_free
(
&
buf
);
if
(
error
<
0
)
return
error
;
return
error
;
/* We don't currently support pushing locally to non-bare repos. Proper
/* We don't currently support pushing locally to non-bare repos. Proper
...
...
tests/network/remote/local.c
View file @
58582cd0
...
@@ -197,6 +197,46 @@ void test_network_remote_local__push_to_bare_remote(void)
...
@@ -197,6 +197,46 @@ void test_network_remote_local__push_to_bare_remote(void)
cl_fixture_cleanup
(
"localbare.git"
);
cl_fixture_cleanup
(
"localbare.git"
);
}
}
void
test_network_remote_local__push_to_bare_remote_with_file_url
(
void
)
{
/* Should be able to push to a bare remote */
git_remote
*
localremote
;
git_push
*
push
;
/* Get some commits */
connect_to_local_repository
(
cl_fixture
(
"testrepo.git"
));
cl_git_pass
(
git_remote_add_fetch
(
remote
,
"master:master"
));
cl_git_pass
(
git_remote_download
(
remote
));
cl_git_pass
(
git_remote_update_tips
(
remote
));
git_remote_disconnect
(
remote
);
/* Set up an empty bare repo to push into */
{
git_repository
*
localbarerepo
;
cl_git_pass
(
git_repository_init
(
&
localbarerepo
,
"./localbare.git"
,
1
));
git_repository_free
(
localbarerepo
);
}
/* Create a file URL */
const
char
*
url
=
cl_git_path_url
(
"./localbare.git"
);
/* Connect to the bare repo */
cl_git_pass
(
git_remote_create_inmemory
(
&
localremote
,
repo
,
NULL
,
url
));
cl_git_pass
(
git_remote_connect
(
localremote
,
GIT_DIRECTION_PUSH
));
/* Try to push */
cl_git_pass
(
git_push_new
(
&
push
,
localremote
));
cl_git_pass
(
git_push_add_refspec
(
push
,
"refs/heads/master:"
));
cl_git_pass
(
git_push_finish
(
push
));
cl_assert
(
git_push_unpack_ok
(
push
));
/* Clean up */
git_push_free
(
push
);
git_remote_free
(
localremote
);
cl_fixture_cleanup
(
"localbare.git"
);
}
void
test_network_remote_local__push_to_non_bare_remote
(
void
)
void
test_network_remote_local__push_to_non_bare_remote
(
void
)
{
{
/* Shouldn't be able to push to a non-bare remote */
/* Shouldn't be able to push to a non-bare remote */
...
...
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