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
fb92b48d
Commit
fb92b48d
authored
May 28, 2015
by
Edward Thomson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3149 from libgit2/cmn/upstream-matching-push
Fill the pointers for matching refspecs
parents
2b922832
5014fe95
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
3 deletions
+54
-3
src/branch.c
+6
-3
src/refspec.c
+6
-0
tests/network/refspecs.c
+10
-0
tests/refs/branches/upstream.c
+32
-0
No files found.
src/branch.c
View file @
fb92b48d
...
...
@@ -551,7 +551,7 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name)
git_remote
*
remote
=
NULL
;
git_config
*
config
;
const
char
*
name
,
*
shortname
;
int
local
;
int
local
,
error
;
const
git_refspec
*
fetchspec
;
name
=
git_reference_name
(
branch
);
...
...
@@ -586,9 +586,12 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name)
* that.
*/
if
(
local
)
git_buf_puts
(
&
value
,
"."
);
error
=
git_buf_puts
(
&
value
,
"."
);
else
git_branch_remote_name
(
&
value
,
repo
,
git_reference_name
(
upstream
));
error
=
git_branch_remote_name
(
&
value
,
repo
,
git_reference_name
(
upstream
));
if
(
error
<
0
)
goto
on_error
;
if
(
git_buf_printf
(
&
key
,
"branch.%s.remote"
,
shortname
)
<
0
)
goto
on_error
;
...
...
src/refspec.c
View file @
fb92b48d
...
...
@@ -42,6 +42,12 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch)
*/
if
(
!
is_fetch
&&
rhs
==
lhs
&&
rhs
[
1
]
==
'\0'
)
{
refspec
->
matching
=
1
;
refspec
->
string
=
git__strdup
(
input
);
GITERR_CHECK_ALLOC
(
refspec
->
string
);
refspec
->
src
=
git__strdup
(
""
);
GITERR_CHECK_ALLOC
(
refspec
->
src
);
refspec
->
dst
=
git__strdup
(
""
);
GITERR_CHECK_ALLOC
(
refspec
->
dst
);
return
0
;
}
...
...
tests/network/refspecs.c
View file @
fb92b48d
...
...
@@ -146,3 +146,13 @@ void test_network_refspecs__invalid_reverse(void)
assert_invalid_rtransform
(
"refs/heads/*:refs/remotes/origin/*"
,
"master"
);
assert_invalid_rtransform
(
"refs/heads/*:refs/remotes/origin/*"
,
"refs/remotes/o/master"
);
}
void
test_network_refspecs__matching
(
void
)
{
git_refspec
spec
;
cl_git_pass
(
git_refspec__parse
(
&
spec
,
":"
,
false
));
cl_assert_equal_s
(
":"
,
spec
.
string
);
cl_assert_equal_s
(
""
,
spec
.
src
);
cl_assert_equal_s
(
""
,
spec
.
dst
);
}
tests/refs/branches/upstream.c
View file @
fb92b48d
...
...
@@ -159,3 +159,35 @@ void test_refs_branches_upstream__set_unset_upstream(void)
cl_git_sandbox_cleanup
();
}
void
test_refs_branches_upstream__no_fetch_refspec
(
void
)
{
git_reference
*
ref
,
*
branch
;
git_repository
*
repo
;
git_remote
*
remote
;
git_config
*
cfg
;
repo
=
cl_git_sandbox_init
(
"testrepo.git"
);
cl_git_pass
(
git_remote_create_with_fetchspec
(
&
remote
,
repo
,
"matching"
,
"."
,
NULL
));
cl_git_pass
(
git_remote_add_push
(
repo
,
"matching"
,
":"
));
cl_git_pass
(
git_reference_lookup
(
&
branch
,
repo
,
"refs/heads/test"
));
cl_git_pass
(
git_reference_create
(
&
ref
,
repo
,
"refs/remotes/matching/master"
,
git_reference_target
(
branch
),
1
,
"fetch"
));
cl_git_fail
(
git_branch_set_upstream
(
branch
,
"matching/master"
));
cl_assert_equal_s
(
"Could not determine remote for 'refs/remotes/matching/master'"
,
giterr_last
()
->
message
);
/* we can't set it automatically, so let's test the user setting it by hand */
cl_git_pass
(
git_repository_config
(
&
cfg
,
repo
));
cl_git_pass
(
git_config_set_string
(
cfg
,
"branch.test.remote"
,
"matching"
));
cl_git_pass
(
git_config_set_string
(
cfg
,
"branch.test.merge"
,
"refs/heads/master"
));
/* we still can't find it because there is no rule for that reference */
cl_git_fail_with
(
GIT_ENOTFOUND
,
git_branch_upstream
(
&
ref
,
branch
));
git_reference_free
(
ref
);
git_reference_free
(
branch
);
git_remote_free
(
remote
);
cl_git_sandbox_cleanup
();
}
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