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
86e5003d
Commit
86e5003d
authored
Dec 23, 2021
by
Edward Thomson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'pr/6062'
parents
a50bbba1
942cfac1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
6 deletions
+34
-6
include/git2/worktree.h
+6
-1
src/worktree.c
+6
-5
tests/worktree/worktree.c
+22
-0
No files found.
include/git2/worktree.h
View file @
86e5003d
...
@@ -86,10 +86,15 @@ typedef struct git_worktree_add_options {
...
@@ -86,10 +86,15 @@ typedef struct git_worktree_add_options {
int
lock
;
/**< lock newly created worktree */
int
lock
;
/**< lock newly created worktree */
git_reference
*
ref
;
/**< reference to use for the new worktree HEAD */
git_reference
*
ref
;
/**< reference to use for the new worktree HEAD */
/**
* Options for the checkout.
*/
git_checkout_options
checkout_options
;
}
git_worktree_add_options
;
}
git_worktree_add_options
;
#define GIT_WORKTREE_ADD_OPTIONS_VERSION 1
#define GIT_WORKTREE_ADD_OPTIONS_VERSION 1
#define GIT_WORKTREE_ADD_OPTIONS_INIT {GIT_WORKTREE_ADD_OPTIONS_VERSION,0,NULL}
#define GIT_WORKTREE_ADD_OPTIONS_INIT {GIT_WORKTREE_ADD_OPTIONS_VERSION,0,NULL
,GIT_CHECKOUT_OPTIONS_INIT
}
/**
/**
* Initialize git_worktree_add_options structure
* Initialize git_worktree_add_options structure
...
...
src/worktree.c
View file @
86e5003d
...
@@ -304,16 +304,13 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
...
@@ -304,16 +304,13 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
git_reference
*
ref
=
NULL
,
*
head
=
NULL
;
git_reference
*
ref
=
NULL
,
*
head
=
NULL
;
git_commit
*
commit
=
NULL
;
git_commit
*
commit
=
NULL
;
git_repository
*
wt
=
NULL
;
git_repository
*
wt
=
NULL
;
git_checkout_options
coopts
=
GIT_CHECKOUT_OPTIONS_INIT
;
git_checkout_options
coopts
;
git_worktree_add_options
wtopts
=
GIT_WORKTREE_ADD_OPTIONS_INIT
;
git_worktree_add_options
wtopts
=
GIT_WORKTREE_ADD_OPTIONS_INIT
;
int
err
;
int
err
;
GIT_ERROR_CHECK_VERSION
(
GIT_ERROR_CHECK_VERSION
(
opts
,
GIT_WORKTREE_ADD_OPTIONS_VERSION
,
"git_worktree_add_options"
);
opts
,
GIT_WORKTREE_ADD_OPTIONS_VERSION
,
"git_worktree_add_options"
);
if
(
opts
)
memcpy
(
&
wtopts
,
opts
,
sizeof
(
wtopts
));
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
repo
);
GIT_ASSERT_ARG
(
repo
);
GIT_ASSERT_ARG
(
name
);
GIT_ASSERT_ARG
(
name
);
...
@@ -321,6 +318,11 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
...
@@ -321,6 +318,11 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
*
out
=
NULL
;
*
out
=
NULL
;
if
(
opts
)
memcpy
(
&
wtopts
,
opts
,
sizeof
(
wtopts
));
memcpy
(
&
coopts
,
&
wtopts
.
checkout_options
,
sizeof
(
coopts
));
if
(
wtopts
.
ref
)
{
if
(
wtopts
.
ref
)
{
if
(
!
git_reference_is_branch
(
wtopts
.
ref
))
{
if
(
!
git_reference_is_branch
(
wtopts
.
ref
))
{
git_error_set
(
GIT_ERROR_WORKTREE
,
"reference is not a branch"
);
git_error_set
(
GIT_ERROR_WORKTREE
,
"reference is not a branch"
);
...
@@ -405,7 +407,6 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
...
@@ -405,7 +407,6 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
goto
out
;
goto
out
;
/* Checkout worktree's HEAD */
/* Checkout worktree's HEAD */
coopts
.
checkout_strategy
=
GIT_CHECKOUT_FORCE
;
if
((
err
=
git_checkout_head
(
wt
,
&
coopts
))
<
0
)
if
((
err
=
git_checkout_head
(
wt
,
&
coopts
))
<
0
)
goto
out
;
goto
out
;
...
...
tests/worktree/worktree.c
View file @
86e5003d
...
@@ -292,6 +292,28 @@ void test_worktree_worktree__add_with_explicit_branch(void)
...
@@ -292,6 +292,28 @@ void test_worktree_worktree__add_with_explicit_branch(void)
git_worktree_free
(
wt
);
git_worktree_free
(
wt
);
}
}
void
test_worktree_worktree__add_no_checkout
(
void
)
{
git_worktree
*
wt
;
git_repository
*
wtrepo
;
git_index
*
index
;
git_str
path
=
GIT_STR_INIT
;
git_worktree_add_options
opts
=
GIT_WORKTREE_ADD_OPTIONS_INIT
;
opts
.
checkout_options
.
checkout_strategy
=
GIT_CHECKOUT_NONE
;
cl_git_pass
(
git_str_joinpath
(
&
path
,
fixture
.
repo
->
workdir
,
"../worktree-no-checkout"
));
cl_git_pass
(
git_worktree_add
(
&
wt
,
fixture
.
repo
,
"worktree-no-checkout"
,
path
.
ptr
,
&
opts
));
cl_git_pass
(
git_repository_open
(
&
wtrepo
,
path
.
ptr
));
cl_git_pass
(
git_repository_index
(
&
index
,
wtrepo
));
cl_assert_equal_i
(
git_index_entrycount
(
index
),
0
);
git_str_dispose
(
&
path
);
git_worktree_free
(
wt
);
git_index_free
(
index
);
git_repository_free
(
wtrepo
);
}
void
test_worktree_worktree__init_existing_worktree
(
void
)
void
test_worktree_worktree__init_existing_worktree
(
void
)
{
{
...
...
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