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
01dbe273
Commit
01dbe273
authored
Jun 04, 2012
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #737 from nulltoken/topic/git_remote_add_refspec
Remotes and refspecs
parents
8856849c
d27bf665
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
1 deletions
+31
-1
include/git2/refspec.h
+8
-0
src/refspec.c
+7
-0
src/remote.c
+5
-1
tests-clar/network/remotes.c
+11
-0
No files found.
include/git2/refspec.h
View file @
01dbe273
...
@@ -36,6 +36,14 @@ GIT_EXTERN(const char *) git_refspec_src(const git_refspec *refspec);
...
@@ -36,6 +36,14 @@ GIT_EXTERN(const char *) git_refspec_src(const git_refspec *refspec);
GIT_EXTERN
(
const
char
*
)
git_refspec_dst
(
const
git_refspec
*
refspec
);
GIT_EXTERN
(
const
char
*
)
git_refspec_dst
(
const
git_refspec
*
refspec
);
/**
/**
* Get the force update setting
*
* @param refspec the refspec
* @return 1 if force update has been set, 0 otherwise
*/
GIT_EXTERN
(
int
)
git_refspec_force
(
const
git_refspec
*
refspec
);
/**
* Check if a refspec's source descriptor matches a reference
* Check if a refspec's source descriptor matches a reference
*
*
* @param refspec the refspec
* @param refspec the refspec
...
...
src/refspec.c
View file @
01dbe273
...
@@ -53,6 +53,13 @@ const char *git_refspec_dst(const git_refspec *refspec)
...
@@ -53,6 +53,13 @@ const char *git_refspec_dst(const git_refspec *refspec)
return
refspec
==
NULL
?
NULL
:
refspec
->
dst
;
return
refspec
==
NULL
?
NULL
:
refspec
->
dst
;
}
}
int
git_refspec_force
(
const
git_refspec
*
refspec
)
{
assert
(
refspec
);
return
refspec
->
force
;
}
int
git_refspec_src_matches
(
const
git_refspec
*
refspec
,
const
char
*
refname
)
int
git_refspec_src_matches
(
const
git_refspec
*
refspec
,
const
char
*
refname
)
{
{
if
(
refspec
==
NULL
||
refspec
->
src
==
NULL
)
if
(
refspec
==
NULL
||
refspec
->
src
==
NULL
)
...
...
src/remote.c
View file @
01dbe273
...
@@ -189,6 +189,8 @@ int git_remote_save(const git_remote *remote)
...
@@ -189,6 +189,8 @@ int git_remote_save(const git_remote *remote)
git_buf_clear
(
&
buf
);
git_buf_clear
(
&
buf
);
git_buf_clear
(
&
value
);
git_buf_clear
(
&
value
);
git_buf_printf
(
&
buf
,
"remote.%s.fetch"
,
remote
->
name
);
git_buf_printf
(
&
buf
,
"remote.%s.fetch"
,
remote
->
name
);
if
(
remote
->
fetch
.
force
)
git_buf_putc
(
&
value
,
'+'
);
git_buf_printf
(
&
value
,
"%s:%s"
,
remote
->
fetch
.
src
,
remote
->
fetch
.
dst
);
git_buf_printf
(
&
value
,
"%s:%s"
,
remote
->
fetch
.
src
,
remote
->
fetch
.
dst
);
if
(
git_buf_oom
(
&
buf
)
||
git_buf_oom
(
&
value
))
if
(
git_buf_oom
(
&
buf
)
||
git_buf_oom
(
&
value
))
return
-
1
;
return
-
1
;
...
@@ -201,6 +203,8 @@ int git_remote_save(const git_remote *remote)
...
@@ -201,6 +203,8 @@ int git_remote_save(const git_remote *remote)
git_buf_clear
(
&
buf
);
git_buf_clear
(
&
buf
);
git_buf_clear
(
&
value
);
git_buf_clear
(
&
value
);
git_buf_printf
(
&
buf
,
"remote.%s.push"
,
remote
->
name
);
git_buf_printf
(
&
buf
,
"remote.%s.push"
,
remote
->
name
);
if
(
remote
->
push
.
force
)
git_buf_putc
(
&
value
,
'+'
);
git_buf_printf
(
&
value
,
"%s:%s"
,
remote
->
push
.
src
,
remote
->
push
.
dst
);
git_buf_printf
(
&
value
,
"%s:%s"
,
remote
->
push
.
src
,
remote
->
push
.
dst
);
if
(
git_buf_oom
(
&
buf
)
||
git_buf_oom
(
&
value
))
if
(
git_buf_oom
(
&
buf
)
||
git_buf_oom
(
&
value
))
return
-
1
;
return
-
1
;
...
@@ -490,7 +494,7 @@ int git_remote_add(git_remote **out, git_repository *repo, const char *name, con
...
@@ -490,7 +494,7 @@ int git_remote_add(git_remote **out, git_repository *repo, const char *name, con
{
{
git_buf
buf
=
GIT_BUF_INIT
;
git_buf
buf
=
GIT_BUF_INIT
;
if
(
git_buf_printf
(
&
buf
,
"refs/heads/*:refs/remotes/%s/*"
,
name
)
<
0
)
if
(
git_buf_printf
(
&
buf
,
"
+
refs/heads/*:refs/remotes/%s/*"
,
name
)
<
0
)
return
-
1
;
return
-
1
;
if
(
git_remote_new
(
out
,
repo
,
name
,
url
,
git_buf_cstr
(
&
buf
))
<
0
)
if
(
git_remote_new
(
out
,
repo
,
name
,
url
,
git_buf_cstr
(
&
buf
))
<
0
)
...
...
tests-clar/network/remotes.c
View file @
01dbe273
...
@@ -92,6 +92,7 @@ void test_network_remotes__save(void)
...
@@ -92,6 +92,7 @@ void test_network_remotes__save(void)
cl_assert
(
_refspec
!=
NULL
);
cl_assert
(
_refspec
!=
NULL
);
cl_assert_equal_s
(
git_refspec_src
(
_refspec
),
"refs/heads/*"
);
cl_assert_equal_s
(
git_refspec_src
(
_refspec
),
"refs/heads/*"
);
cl_assert_equal_s
(
git_refspec_dst
(
_refspec
),
"refs/remotes/upstream/*"
);
cl_assert_equal_s
(
git_refspec_dst
(
_refspec
),
"refs/remotes/upstream/*"
);
cl_assert
(
git_refspec_force
(
_refspec
)
==
0
);
_refspec
=
git_remote_pushspec
(
_remote
);
_refspec
=
git_remote_pushspec
(
_remote
);
cl_assert
(
_refspec
!=
NULL
);
cl_assert
(
_refspec
!=
NULL
);
...
@@ -159,6 +160,15 @@ void test_network_remotes__loading_a_missing_remote_returns_ENOTFOUND(void)
...
@@ -159,6 +160,15 @@ void test_network_remotes__loading_a_missing_remote_returns_ENOTFOUND(void)
cl_assert_equal_i
(
GIT_ENOTFOUND
,
git_remote_load
(
&
_remote
,
_repo
,
"just-left-few-minutes-ago"
));
cl_assert_equal_i
(
GIT_ENOTFOUND
,
git_remote_load
(
&
_remote
,
_repo
,
"just-left-few-minutes-ago"
));
}
}
/*
* $ git remote add addtest http://github.com/libgit2/libgit2
*
* $ cat .git/config
* [...]
* [remote "addtest"]
* url = http://github.com/libgit2/libgit2
* fetch = +refs/heads/*:refs/remotes/addtest/*
*/
void
test_network_remotes__add
(
void
)
void
test_network_remotes__add
(
void
)
{
{
git_remote_free
(
_remote
);
git_remote_free
(
_remote
);
...
@@ -168,5 +178,6 @@ void test_network_remotes__add(void)
...
@@ -168,5 +178,6 @@ void test_network_remotes__add(void)
cl_git_pass
(
git_remote_load
(
&
_remote
,
_repo
,
"addtest"
));
cl_git_pass
(
git_remote_load
(
&
_remote
,
_repo
,
"addtest"
));
_refspec
=
git_remote_fetchspec
(
_remote
);
_refspec
=
git_remote_fetchspec
(
_remote
);
cl_assert
(
!
strcmp
(
git_refspec_src
(
_refspec
),
"refs/heads/*"
));
cl_assert
(
!
strcmp
(
git_refspec_src
(
_refspec
),
"refs/heads/*"
));
cl_assert
(
git_refspec_force
(
_refspec
)
==
1
);
cl_assert
(
!
strcmp
(
git_refspec_dst
(
_refspec
),
"refs/remotes/addtest/*"
));
cl_assert
(
!
strcmp
(
git_refspec_dst
(
_refspec
),
"refs/remotes/addtest/*"
));
}
}
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